Jump to content

Element Data Setting


Karuzo

Recommended Posts

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
  • Replies 77
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...