Karuzo Posted March 3, 2014 Share Posted March 3, 2014 Hey Community, i have a problem with setting element data to the player. Here's my code: function login_func ( player, username, password) local query = dbQuery ( connect, "SELECT username, password FROM accounts WHERE username = ?", username ) if ( query ) then local data, rows = dbPoll ( query, -1 ) if ( rows >= 1 ) then if ( data [ 1 ].password == password ) then local elementdata = setElementData(player, "LoggedIN",true) 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) else outputChatBox("Error 404 : Dein Benutzername oder dein Passwort ist falsch!",player,125,0,0) end end end end So what is my problem ? I'm trying to set the element data to the player that he is LoggedIn. But if i wanna output the data it says false. Why ? Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 Those messages after loggin in are showing? Link to comment
Karuzo Posted March 3, 2014 Author Share Posted March 3, 2014 Yeah they were showing. That's why im confused. Link to comment
Castillo Posted March 3, 2014 Share Posted March 3, 2014 Are you sure that the "player" argument is correct? Link to comment
Karuzo Posted March 3, 2014 Author Share Posted March 3, 2014 Yeah im triggering the local player. Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 Are you sure that you put player in 1st argument to call this function? After 2nd line add outputChatBox ( getElementType ( player ) ) Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 Well, that is strange. outputChatBox(tostring(elementdata)) This outputs false? Link to comment
Karuzo Posted March 3, 2014 Author Share Posted March 3, 2014 Exactly. As you can see here: Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 Try to add after 8th lane outputChatBox ( tostring ( getElementData ( player, "LoggedIN" ) ) ) Link to comment
Karuzo Posted March 3, 2014 Author Share Posted March 3, 2014 lol, that outputs true. Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 So it's kinda bug. Anyway, if you don't use returns of setElementData, just delete variable. Link to comment
Karuzo Posted March 3, 2014 Author Share Posted March 3, 2014 Yeah but i can't get the Element Data.. function onQuit () if getElementData(localPlayer,"LoggedIN") == true then outputChatBox("GetElementData Successfull") local x,y,z = getElementPosition (source) local inserting = dbExec ( connect, "INSERT INTO accounts ( money,skin,health,x,y,z,int,dim ) VALUES (?,?,?,?,?,?,?,? )",tostring (getPlayerMoney (source)),tostring (getPedSkin (source)),tostring (getElementHealth (source)),x,y,z,getElementInterior (source),getElementDimension (source) ) if inserting then outputChatBox("Inserting successfull") else outputChatBox("Inserting failed.") end end end addEventHandler ("onPlayerQuit", root, onQuit) addCommandHandler("test", onQuit) Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 And there also try to output data outputChatBox ( tostring ( getElementData ( localPlayer, "LoggedIN" ) ) ) Link to comment
pa3ck Posted March 3, 2014 Share Posted March 3, 2014 As far as I know, dbExec doesn't return anything, just saying. Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 Of course it outputs nothing. function onQuit () if ( getElementData(source,"LoggedIN") ) then outputChatBox("GetElementData Successfull") local x,y,z = getElementPosition (source) local inserting = dbExec ( connect, "INSERT INTO accounts ( money,skin,health,x,y,z,int,dim ) VALUES (?,?,?,?,?,?,?,? )",tostring (getPlayerMoney (source)),tostring (getPedSkin (source)),tostring (getElementHealth (source)),x,y,z,getElementInterior (source),getElementDimension (source) ) if inserting then outputChatBox("Inserting successfull") else outputChatBox("Inserting failed.") end end end addEventHandler ("onPlayerQuit", root, onQuit) And you don't need to do such a thing if getElementData(localPlayer,"LoggedIN") == true then Just do if ( getElementData(source,"LoggedIN") ) then @UP: dbExec returns true if succesfully, false otherwise. Link to comment
Karuzo Posted March 3, 2014 Author Share Posted March 3, 2014 Same as yours. function onQuit () if ( getElementData(source,"LoggedIN") ) then outputChatBox("GetElementData Successfull") local x,y,z = getElementPosition (source) local inserting = dbExec ( connect, "INSERT INTO accounts ( money,skin,health,x,y,z,int,dim ) VALUES (?,?,?,?,?,?,?,? )",tostring (getPlayerMoney (source)),tostring (getPedSkin (source)),tostring (getElementHealth (source)),x,y,z,getElementInterior (source),getElementDimension (source) ) if inserting then outputChatBox("Inserting successfull") else outputChatBox("Inserting failed.") end end end addEventHandler ("onPlayerQuit", root, onQuit) Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 Well, when you quit the values are not saving? Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 And I want to know how would you whose this values are? I mean that you are not saving id of player or account. Link to comment
Karuzo Posted March 3, 2014 Author Share Posted March 3, 2014 You mean the dbExec ? Just leave that. I know i have to specify the player/account. The problem is just the element data. Link to comment
pa3ck Posted March 3, 2014 Share Posted March 3, 2014 Are you 100% sure, that it is not in the table already? I mean, don't you want to update it instead of inserting it? 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