Hello there,
I have a mysql login system.
I want to spawn the player after he logged in and i did this.
The problem is that the user is logging in with username "test" (entry in mysql is Test) he will be spawned but the gui wil not disappear so there is a problem.
If the user is logging in with the correct mysql entry "Test" it will work.
function loginPlayer(username, password)
qh = dbQuery(db, "SELECT * FROM accounts WHERE BINARY username=? and password=?", username, md5(password))
result , numrows, errmsg = dbPoll (qh, -1)
local row = result[1]
if row then
triggerClientEvent(client, "login.success", client)
local account = getAccount(username, password)
if (account ~= false) then
logIn(client, getAccount(username), password)
outputChatBox("Logged in as administrator.", client)
else
outputChatBox("Welcome.", client)
end
setElementData(client, "isPlayedLoggedIn", true)
setElementData(client, "getPlayerUsername", username)
outputServerLog("Login: User: " .. getPlayerName(client) .. " successfully logged in as " .. username .. "! (IP: " .. getPlayerIP(client) .. " | Serial: " .. getPlayerSerial(client) ..")")
else
outputChatBox("", client)
outputChatBox("", client)
outputChatBox("Wrong username or password.", client)
end
end
addEvent("loginPlayer", true)
addEventHandler("loginPlayer", resourceRoot, loginPlayer)
function playerAfterLogin()
spawnPlayer(client, 1743,-1860.9,14,0) --spawn player gara
fadeCamera(client, true)
setCameraTarget(client, client)
end
addEventHandler("loginPlayer", resourceRoot, playerAfterLogin)
After trying to debug i got a solution.
Directly adding the spawnPlayer, fadeCamera and setCameraTarge after the if statement that checks if player is registered.
(check the - spawn player comment)
function loginPlayer(username, password)
qh = dbQuery(db, "SELECT * FROM accounts WHERE BINARY username=? and password=?", username, md5(password))
result , numrows, errmsg = dbPoll (qh, -1)
local row = result[1]
if row then
triggerClientEvent(client, "login.success", client)
local account = getAccount(username, password)
if (account ~= false) then
logIn(client, getAccount(username), password)
outputChatBox("Logged in as administrator.", client)
else
outputChatBox("Welcome.", client)
end
setElementData(client, "isPlayedLoggedIn", true)
setElementData(client, "getPlayerUsername", username)
spawnPlayer(client, 1743,-1860.9,14,0) --spawn player
fadeCamera(client, true) --spawn player
setCameraTarget(client, client) --spawn player
outputServerLog("Login: User: " .. getPlayerName(client) .. " successfully logged in as " .. username .. "! (IP: " .. getPlayerIP(client) .. " | Serial: " .. getPlayerSerial(client) ..")")
else
outputChatBox("", client)
outputChatBox("", client)
outputChatBox("Wrong username or password.", client)
end
end
addEvent("loginPlayer", true)
addEventHandler("loginPlayer", resourceRoot, loginPlayer)
But I thinking that it's not the correct way to do it so i tried to keep the function that spawn the player but how do i call it after that if condition?
function spawnPlayerAfterLogin()
spawnPlayer(client, 1743,-1860.9,14,0) --spawn player gara
fadeCamera(client, true)
setCameraTarget(client, client)
end
or there is another solution?
Thanks for your time !