Jump to content

Need help with mySQL login script.


Jeeveegee

Recommended Posts

I was wondering if anyone could help me out. I am working on a custom script with the following functions:

-You can register an account via a Register gui, which is stored in a mysql database (works perfectly fine)

-You can login using the account you registered, again via a Login gui. (works perfectly fine)

-Your Player data (like money and position) is stored in the mysql database everytime you disconnect. (works not so perfectly fine!)

Now there is one little problem. When a player enters the server with a name that is already registered in the server, and he disconnects before logging on and spawning, the player data is still stored in the mysql database. This resets all the data that was previously there with '0' in every field.

I have no idea how I can fix this, since I have no way of checking if a player has logged on or not before storing his data when he disconnects again. Is there some way of setting a sort of 'cookie' like websites do to check if you are logged in or not? Please help me.

This is the current disconnect script, but it is certainly lacking something to check if you are logged on, however I have no idea how to make that.

function onPlayerDisconnect(quitType) 
        local x, y, z = getElementPosition(source) 
        local rx,ry,rz = getElementRotation(source) 
     
        mysql_query(handler,"UPDATE players SET playerHealth='"..getElementHealth(source).."', playerArmor='"..getPedArmor(source).."', playerMoney='"..getPlayerMoney(source).."', playerSkin='"..getElementModel(source).."', playerX='"..x.."', playerY='"..y.."', playerZ='"..z.."', playerA='"..rx.."' WHERE playerName='" .. getPlayerName(source) .. "'") 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerDisconnect) 

Link to comment

Alright so I don't fully understand how to use the setElementData and getElementData, but this is what I tried in my script and it didn't work, so maybe you guys can tell me how to properly use them?

added this to the login script:

setElementData(source,"playerLoggedIn", true) 

and this is the changed disconnect script:

function onPlayerDisconnect(quitType) 
    if (getElementData(source, "playerLoggedIn") == true) then 
        local x, y, z = getElementPosition(source) 
        local rx,ry,rz = getElementRotation(source) 
     
        mysql_query(handler,"UPDATE players SET playerHealth='"..getElementHealth(source).."', playerArmor='"..getPedArmor(source).."', playerMoney='"..getPlayerMoney(source).."', playerSkin='"..getElementModel(source).."', playerX='"..x.."', playerY='"..y.."', playerZ='"..z.."', playerA='"..rx.."' WHERE playerName='" .. getPlayerName(source) .. "'") 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerDisconnect) 

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...