Witam, tworz? system logowania na MYSQL.
Stworzy?em baz? danych i skrypt na ??czenie si? z ni?.
Skrypt przy starcie daje pozytywny wynik ?e po??czono z baz? danych.
Zrobi?em funkcj? tworz?ce konta i logowanie si? na nie.
Lecz przy starcie skryptu GUI logowania nie chce si? pokazac.
1. Zmieniaj pozycje na relatywn? w guieditorze , bo wszystko si? posypie na innej rodzielczo?ci.
2. U?ywaj db3 , ?eby zobaczy? , czy s? b??dy.
3. U?ywaj tag?w [lua].
4. O jeden end za ma?o w ostatniej funkcji.
5. Operator ~= w if nie znaczy je?li tak , tylko je?li nie.
6. W elseif te? trzeba doda? then
Tw?j kod ostatniej funkcji:
function btn.rejestracja()
local login = guiGetText(GUIEditor.edit[1])
local haslo = guiGetText(GUIEditor.edit[2])
triggerServerEvent("zarejestruj",getLocalPlayer(),getLocalPlayer(),login,haslo)
end
function btn.logowanie()
local login = guiGetText(GUIEditor.edit[1])
local haslo = guiGetText(GUIEditor.edit[2])
triggerServerEvent("zaloguj",getLocalPlayer(),getLocalPlayer(),login,haslo)
end
addEventHandler ( "onClientGUIClick", getRootElement(), function()
addEventHandler ( "onClientGUIClick", getRootElement(), function()
if source == GUIEditor.button[1] then
btn.logowanie()
elseif source == GUIEditor.button[2] then
btn.rejestracja()
end
end)
Jak mog?em przegapi? t? linijk?...
Gui si? wyswietla lecz gracz w bazie danych nie chce si? stworzy?.
local connect = dbConnect( "mysql", "dbname=mtalogowanie;host=127.0.0.1", "root", "")
if connect then
outputDebugString ("Polaczenie z baza danych przebieglo pomyslnie!")
else
outputDebugString ("Polaczenie z baza danych nie udane!")
end
addEvent("zarejestruj",true)
function zarejestruj(player,login,haslo)
local acount = getAccount(login)
if acount == false then
local serial = getPlayerSerial(player)
local pieniadze = getPlayerMoney(player)
exports.mysql:_Exec("insert into gracze(serial,login,haslo,pieniadze) values (?,?,?,?)",serial,login,haslo,pieniadze)
local addAccount = addAccount(tostring(login),tostring(haslo))
if addAccount then
outputDebugString("User register with login ".. login)
else
outputDebugString("ERROR Occur while register.")
end
end
end
addEventHandler("zarejestruj",getRootElement(),zarejestruj)
addEvent("zaloguj",true)
function zaloguj(player,login,haslo)
local check = exports.mysql:_QuerySingle("select * from gracze where login = ? ",login)
if check then
local checkPass = check.haslo
if (checkPass == haslo) then
logIn(player,getAccount(login),tostring(haslo))
outputDebugString("User Logged In")
end
end
end
addEventHandler("zaloguj",getRootElement(),zaloguj)
local acount = getAccount(login)
if acount == false then
local serial = getPlayerSerial(player)
local pieniadze = getPlayerMoney(player)
exports.mysql:_Exec("insert into gracze(serial,login,haslo,pieniadze) values (?,?,?,?)",serial,login,haslo,pieniadze)
local addAccount = addAccount(tostring(login),tostring(haslo))
if addAccount then
outputDebugString("User register with login ".. login)
else
outputDebugString("ERROR Occur while register.")
end
else
outputChatBox ( "Konto juz jest", getRootElement())
end
Ale jak klikam na przycisk "Zarejestruj" nic si? nie dzieje.
Wydaje mi si? ?e skrypt client.lua nie mo?e odtworzy? eventow z server.lua.
Tak to przynajmniej wygl?da.
function btn.rejestracja()
local login = guiGetText(GUIEditor.edit[1])
local haslo = guiGetText(GUIEditor.edit[2])
triggerServerEvent("zarejestruj",getLocalPlayer(),getLocalPlayer(),login,haslo)
end
function btn.logowanie()
local login = guiGetText(GUIEditor.edit[1])
local haslo = guiGetText(GUIEditor.edit[2])
triggerServerEvent("zaloguj",getLocalPlayer(),getLocalPlayer(),login,haslo)
end
addEventHandler ( "onClientGUIClick", getRootElement(), function()
if source == GUIEditor.button[1] then
btn.logowanie()
elseif source == GUIEditor.button[2] then
btn.rejestracja()
end
end)
server.lua:
local connect = dbConnect( "mysql", "dbname=mtalogowanie;host=127.0.0.1", "root", "")
if connect then
outputDebugString ("Polaczenie z baza danych przebieglo pomyslnie!")
else
outputDebugString ("Polaczenie z baza danych nie udane!")
end
addEvent("zarejestruj",true)
function zarejestruj(player,login,haslo)
local acount = getAccount(login)
if acount == false then
local serial = getPlayerSerial(player)
local pieniadze = getPlayerMoney(player)
exports.mysql:_Exec("insert into gracze(serial,login,haslo,pieniadze) values (?,?,?,?)",serial,login,haslo,pieniadze)
local addAccount = addAccount(tostring(login),tostring(haslo))
if addAccount then
outputDebugString("User register with login ".. login)
else
outputDebugString("ERROR Occur while register.")
end
else
outputChatBox ( "Konto juz jest", getRootElement())
end
end
addEventHandler("zarejestruj",getRootElement(),zarejestruj)
addEvent("zaloguj",true)
function zaloguj(player,login,haslo)
local check = exports.mysql:_QuerySingle("select * from gracze where login = ? ",login)
if check then
local checkPass = check.haslo
if (checkPass == haslo) then
logIn(player,getAccount(login),tostring(haslo))
outputDebugString("User Logged In")
end
end
end
addEventHandler("zaloguj",getRootElement(),zaloguj)
[2017-02-04 17:01] Resources: 8 loaded, 0 failed
[2017-02-04 17:01] Starting resources...
[2017-02-04 17:02] Server minclientversion is now 1.3.0-9.04311
[2017-02-04 17:02] WARNING: Logowanie/client.lua [Client] is encoded in ANSI instead of UTF-8. Please convert your file to UTF-8.
[2017-02-04 17:02] Some files in 'Logowanie' use deprecated functions.
[2017-02-04 17:02] Use the 'upgrade' command to perform a basic upgrade of resources.
[2017-02-04 17:02] INFO: Polaczenie z baza danych przebieglo pomyslnie!
[2017-02-04 17:02] Querying MTA master server... no response. Retrying...
[2017-02-04 17:02] Authorized serial account protection is enabled for the ACL group(s): `Admin` See http://mtasa.com/authserial
[2017-02-04 17:02] Server started and is ready to accept connections!
[2017-02-04 17:02] To stop the server, type 'shutdown' or press Ctrl-C
[2017-02-04 17:02] Type 'help' for a list of commands.
[2017-02-04 17:02] CONNECT: Davi connected (IP: 25.113.56.74 Serial: 5F1E6CB0FC2DB44BFE1968B0CD1AC552 Version: 1.5.3-9.11164.1)
[2017-02-04 17:02] JOIN: Davi joined the game (IP: 25.113.56.74)
Nie możesz pisać nowych tematów Nie możesz odpowiadać w tematach Nie możesz zmieniać swoich postów Nie możesz usuwać swoich postów Nie możesz głosować w ankietach