WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 I don't understand you know. SELECT or UPDATE? Link to comment
Karuzo Posted March 3, 2014 Author Share Posted March 3, 2014 Select. I want to get those datas to set the Skin/Money of the player. Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 So local query = dbQuery ( "SELECT * FROM accounts WHERE username=?", username ) local data = dbPoll ( query, -1 ) local x, y, z = data.x, data.y, data.z Link to comment
Karuzo Posted March 3, 2014 Author Share Posted March 3, 2014 Yup works fine. Thank you. Link to comment
Karuzo Posted March 4, 2014 Author Share Posted March 4, 2014 Hey, ive got an awkward error in my console: It says my database is locked ?!? How can i solve this ? Link to comment
WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 Give me a screen with this error. Link to comment
WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 What the... Is connection fine? Link to comment
WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 And other stuff using dbQuery works fine? Show me your dbExec code. Link to comment
Karuzo Posted March 4, 2014 Author Share Posted March 4, 2014 Yeah dbQuerys working fine. dbExec(connect, "UPDATE accounts SET x=?, y=?, z=?, skin=?, health=?,int=?,dim=?,money=? WHERE username=?", x, y, z, skin,health,int,dim,money, username ) The problem is , if i log in , i get killed. Wtf ? Link to comment
WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 (edited) Hm, I think there is problem with saving HP. It is setting to 0 i guess. Show me your full saving and spawning code. And show me your database structure (screenshot would be enough). Edited March 4, 2014 by Guest Link to comment
Karuzo Posted March 4, 2014 Author Share Posted March 4, 2014 Login: function login_func ( player, username, password) local query = dbQuery ( connect, "SELECT username, password FROM accounts WHERE username = ?", username ) local checkdatas = dbQuery (connect, "SELECT * FROM accounts WHERE username=?", username ) outputChatBox ( getElementType ( player ) ) if ( query ) and (checkdatas) then local data, rows = dbPoll ( query, -1 ) local setdata = dbPoll ( checkdatas, -1 ) if ( rows >= 1 ) then if ( data [ 1 ].password == password ) then local x, y, z = setdata.x, setdata.y, setdata.z local money = setdata.money local skin = setdata.skin local health = setdata.health local int = setdata.int local dim = setdata.dim setElementData(player, "LoggedIN",true) --outputChatBox ( tostring ( getElementData ( player, "LoggedIN" ) ) ) --outputChatBox(tostring(elementdata)) outputChatBox("Du hast dich erfolgreich eingeloggt!",player,0,125,0) outputChatBox("Willkommen zurück, "..string.gsub ( getPlayerName ( player ), '#%x%x%x%x%x%x', '' ),player,0,125,0) triggerClientEvent(player,"closeLoginPanel",player) setPlayerMoney(player,tostring(setdata.money)) setElementModel(player,tostring(setdata.skin)) setElementHealth(player,tostring(setdata.health)) setElementInterior(player,tostring(setdata.int)) setElementDimension(player,tostring(setdata.dim)) setElementPosition(player, tostring(setdata.x), tostring(setdata.y), tostring(setdata.z)) else outputChatBox("Error 404 : Dein Benutzername oder dein Passwort ist falsch!",player,125,0,0) end end end end addEvent("LoginRequest",true) addEventHandler("LoginRequest",getRootElement(),login_func) Quit: function onQuit (username) outputChatBox ( getElementType ( source ) ) local data = getElementData(source,"LoggedIN") outputChatBox ( tostring ( data ) ) if ( data ) then local money = getPlayerMoney ( source ) local skin = getElementModel ( source ) local health = getElementHealth ( source ) local int,dim = getElementInterior ( source ), getElementDimension ( source ) local x,y,z = getElementPosition (source) local inserting = dbExec(connect, "UPDATE accounts SET x=?, y=?, z=?, skin=?, health=?,int=?,dim=?,money=? WHERE username=?", x, y, z, skin,health,int,dim,money, username ) if inserting then outputDebugString("Inserting successfull") else outputDebugString("Inserting failed.") end end end addEventHandler ("onPlayerQuit", root, onQuit) addEvent("OnQuitPlayer", true) addEventHandler("OnQuitPlayer", root, onQuit) addCommandHandler("test", onQuit) Screenshot: //Edit: I know what the problem for the 'database is locked' was. I had SQLite Browser open, as i quit. So the accounts.db was used by SQlite Browser. But i still get killed. Link to comment
WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 (edited) function login_func ( player, username, password) local query = dbQuery (connect, "SELECT * FROM accounts WHERE username=?", username ) if ( query ) then local data, rows = dbPoll ( query, -1 ) if ( rows > 0 ) then if ( data.password == password ) then local x, y, z = data.x or 0, data.y or 0, data.z or 0 local money = data.money or 0 local skin = data.skin or 0 local health = data.health or 100 local int = data.int or 0 local dim = data.dim or 0 setElementData(player, "LoggedIN",true) outputChatBox("Du hast dich erfolgreich eingeloggt!",player,0,125,0) outputChatBox("Willkommen zurück, "..string.gsub ( getPlayerName ( player ), '#%x%x%x%x%x%x', '' ),player,0,125,0) triggerClientEvent(player,"closeLoginPanel",player) setPlayerMoney(player, money) setElementModel(player, skin) setElementHealth(player, health) setElementInterior(player, int) setElementDimension(player, dim) setElementPosition(player, x, y, z) else outputChatBox("Error 404 : Dein Benutzername oder dein Passwort ist falsch!",player,125,0,0) end end end end addEvent("LoginRequest",true) addEventHandler("LoginRequest",getRootElement(),login_func) Try this out. Edited March 4, 2014 by Guest Link to comment
WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 I edited the code, made some mistakes. Link to comment
Karuzo Posted March 4, 2014 Author Share Posted March 4, 2014 Huh, now i get the error message. Link to comment
Karuzo Posted March 4, 2014 Author Share Posted March 4, 2014 The 'else' message in my code. Line 24. Link to comment
WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 Try if ( tostring ( data[1].password ) == tostring ( password ) ) then Link to comment
Karuzo Posted March 4, 2014 Author Share Posted March 4, 2014 Works now, but if i quit, and log in i don't get the money/skin/health i had when i quitted. And in the accounts.db theres nothing inserted. But it says Inserting Successfull. Could it be on the UPDATE ? Link to comment
WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 How did u define username no quiting function? Maybe set data to player with his username and on quitting, get userdata and the do a query. Link to comment
Karuzo Posted March 4, 2014 Author Share Posted March 4, 2014 I'm triggering it from the ClientSide. addEventHandler("onClientGUIClick", loginsend, function() outputChatBox("button") local username = useredit:setText() local password = passedit:setText() if username == "" or password == "" then outputChatBox("Bitte trage deine Daten ein! Wenn du keinen Account hast melde dich auf ... an!", 125,0,0) else triggerServerEvent("LoginRequest",getLocalPlayer(),getLocalPlayer(),username,password) triggerServerEvent("OnQuitPlayer", getLocalPlayer(),username) setCameraTarget(localPlayer) end end) Link to comment
WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 That has no sense. addEventHandler("onClientGUIClick", loginsend, function() outputChatBox("button") local username = useredit:setText() local password = passedit:setText() if username == "" or password == "" then outputChatBox("Bitte trage deine Daten ein! Wenn du keinen Account hast melde dich auf ... an!", 125,0,0) else triggerServerEvent("LoginRequest", localPlayer, localPlayer, username,password) setCameraTarget(localPlayer) end end) Server: function onQuit () outputChatBox ( getElementType ( source ) ) local data = getElementData(source,"LoggedIN") local username = getElementData ( source, "username" ) outputChatBox ( tostring ( data ) ) if ( data ) then local money = getPlayerMoney ( source ) local skin = getElementModel ( source ) local health = getElementHealth ( source ) local int, dim = getElementInterior ( source ), getElementDimension ( source ) local x, y, z = getElementPosition ( source ) local inserting = dbExec(connect, "UPDATE accounts SET x=?, y=?, z=?, skin=?, health=?, int=?, dim=?, money=? WHERE username=?", x, y, z, skin,health,int,dim,money, username ) if inserting then outputDebugString("Inserting successfull") else outputDebugString("Inserting failed.") end end end addEventHandler ("onPlayerQuit", root, onQuit) addCommandHandler("test", onQuit) function login_func ( player, username, password) local query = dbQuery (connect, "SELECT * FROM accounts WHERE username=?", username ) if ( query ) then local data, rows = dbPoll ( query, -1 ) if ( rows > 0 ) then if ( tostring ( data[1].password ) == tostring ( password ) ) then local x, y, z = data.x or 0, data.y or 0, data.z or 0 local money = data.money or 0 local skin = data.skin or 0 local health = data.health or 100 local int = data.int or 0 local dim = data.dim or 0 setElementData(player, "LoggedIN",true) outputChatBox("Du hast dich erfolgreich eingeloggt!",player,0,125,0) outputChatBox("Willkommen zurück, "..string.gsub ( getPlayerName ( player ), '#%x%x%x%x%x%x', '' ),player,0,125,0) triggerClientEvent(player,"closeLoginPanel",player) setPlayerMoney(player, money) setElementModel(player, skin) setElementHealth(player, health) setElementInterior(player, int) setElementDimension(player, dim) setElementPosition(player, x, y, z) setElementData ( source, "username", username ) else outputChatBox("Error 404 : Dein Benutzername oder dein Passwort ist falsch!",player,125,0,0) end end end end addEvent("LoginRequest",true) addEventHandler("LoginRequest",getRootElement(),login_func) Link to comment
Karuzo Posted March 4, 2014 Author Share Posted March 4, 2014 The Inserting works now! But setting still doesn't work. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now