local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local login = imgui.ImBool(false)
local window = imgui.ImBool(false)
local loggedIn = false
local login_input_password = imgui.ImBuffer(256)
local users = {
{'chapo', '12341'},
{'Nick_Name', '1234567890'},
{'Script_User1', 'password1'},
{'Script_User2', 'password2'},
}
function main()
while not isSampAvailable() do wait(200) end
while not sampIsLocalPlayerSpawned() do wait(0) end
sampRegisterChatCommand('login', function()
if loggedIn then window.v = not window.v else login.v = not login.v end
end)
imgui.Process = false
login.v = true --show window
window.v = false
while true do
wait(0)
if login.v or window.v then imgui.Process = true else imgui.Process = false end
end
end
function imgui.OnDrawFrame()
if login.v then
resX, resY = getScreenResolution()
sizeX, sizeY = 250, 75
imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
imgui.Begin('Log In', login)
imgui.PushItemWidth(240)
imgui.SetCursorPosX(5)
imgui.InputText(u8'Пароль', login_input_password, imgui.InputTextFlags.Password)
imgui.PopItemWidth()
imgui.SetCursorPosX(5)
if imgui.Button(u8'Ok', imgui.ImVec2(240, 20)) then
for i = 1, #users do
myName = sampGetPlayerNickname(select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)))
if users[i][1] == myName and users[i][2] == login_input_password.v then
loggedIn = true
login.v = false
window.v = true
sampAddChatMessage('Пароль принят!', -1)
end
end
end
imgui.End()
end
if window.v then
resX, resY = getScreenResolution()
sizeX, sizeY = 500, 500
imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
imgui.Begin('Window Title', window)
imgui.Text('text')
if imgui.Button('Log Out', imgui.ImVec2(75, 20)) then
loggedIn = false
login.v = true
window.v = false
login_input_password.v = ''
end
imgui.End()
end
end