sylver Posted January 16, 2011 Posted January 16, 2011 Hello. I want to do to save some data from mysql I did so, however, do not save local function savePlayer( player ) if not player then for key, value in ipairs( getElementsByType( "player" ) ) do savePlayer( value ) end else if isLoggedIn( player ) then -- save character since it's logged in local x, y, z = getElementPosition( player ) exports.sql:query_free( "UPDATE characters SET money = " .. getPlayerMoney( player ) .. ", karne = ".. getPlayerPkt(value)..", rotation = " .. getPedRotation( player ) .. ", health = " .. math.floor( getElementHealth( player ) ) .. ", armor = " .. math.floor( getPedArmor( player ) ) .. ", weapons = " .. getWeaponString( player ) .. ", lastLogin = NOW() WHERE characterID = " .. tonumber( getCharacterID( player ) ) ) end end end setTimer( savePlayer, 3000, 0 ) -- Auto-Save every five minutes function getPlayerPkt(player) if isElement(player) then local pkt = getElementData(player,"Pkt") if tonumber(pkt) then return tonumber(pkt) else return tonumber(0) end else return tonumber(0) end end I made a simple script to save but nothing is save function onPlayerLogin () local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then if not isGuestAccount ( playeraccount ) then local playerpkt = getAccountData ( playeraccount, "Pkt" ) if ( playerpkt ) then setElementData(source, "Pkt", tonumber(playerpkt)) end end end end function onPlayerQuit () local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then if not isGuestAccount ( playeraccount ) then local playerpkt = getElementData ( source, "Pkt" ) if ( playerpkt ) then setAccountData ( playeraccount, "Pkt", playerpkt ) end end end end addEventHandler ( "onPlayerLogin", getRootElement (), onPlayerLogin ) addEventHandler ( "onPlayerQuit", getRootElement (), onPlayerQuit )
sylver Posted January 16, 2011 Author Posted January 16, 2011 What do you want me to say? I made a script to show money in the scoreboard I after reconnect is: is 0 cash in scoreboard and I'm have 21 ...
SDK Posted January 16, 2011 Posted January 16, 2011 I don't see the code to load all the player stats when logging in, only saving, where is it?
sylver Posted January 16, 2011 Author Posted January 16, 2011 Downloading statistics such code: function getPlayerPkt(player) if isElement(player) then local pkt = getElementData(player,"Pkt") if tonumber(pkt) then return tonumber(pkt) else return tonumber(0) end else return tonumber(0) end end
sylver Posted January 16, 2011 Author Posted January 16, 2011 I did already write in a mysql database. But now my question is how do I read? Saving made as follows: local function savePlayer( player ) if not player then for key, value in ipairs( getElementsByType( "player" ) ) do savePlayer( value ) end else if isLoggedIn( player ) then -- save character since it's logged in local sw22 = getPlayerPkt1(player) local x, y, z = getElementPosition( player ) exports.sql:query_free( "UPDATE characters SET money = " .. getPlayerMoney( player ) .. ", pkt = ".. sw22..", rotation = " .. getPedRotation( player ) .. ", health = " .. math.floor( getElementHealth( player ) ) .. ", armor = " .. math.floor( getPedArmor( player ) ) .. ", weapons = " .. getWeaponString( player ) .. ", lastLogin = NOW() WHERE characterID = " .. tonumber( getCharacterID( player ) ) ) end end end setTimer( savePlayer, 3000, 0 ) -- Auto-Save every five minutes function getPlayerPkt1(player) if isElement(player) then local pkt = getElementData(player,"Pkt") if tonumber(pkt) then return tonumber(pkt) else return tonumber(0) end else return tonumber(0) end end Only now how to load it on the scoreboard it was?
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