Jump to content

Saving player statistics failure


Recommended Posts

Posted

When a player disconnects, I'd like to save all their statistics, but so far the database isn't getting updated at all, what is incorrect in my coding? Nothing shows up in the debug either:

I let you know that I had a for loop on the player element, but that caused other issues.

  
local mysql=exports.mysql 
function savePlayer(reason) 
    outputChatBox( tostring(source) )   
    local vehicle = getPedOccupiedVehicle(source) 
        if (vehicle) then 
            local seat = getPedOccupiedVehicleSeat(source) 
            triggerEvent("onVehicleExit", vehicle, source, seat) 
        end 
         
        local x, y, z, rot, health, armour, interior, dimension 
         
        local x, y, z = getElementPosition(source) 
        local rot = getPedRotation(source) 
        local health = getElementHealth(source) 
        local armor = getPedArmor(source) 
        local interior = getElementInterior(source) 
        local dimension = getElementDimension(source) 
        --money = getElementData(source, "money") 
         
        local skin = getElementModel(source) 
         
        mysql:query_free("UPDATE characters SET x='" .. mysql:escape_string(x) .. "', y='" .. mysql:escape_string(y) .. "', z='" .. mysql:escape_string(z) .. "', rotation='" .. mysql:escape_string(rot) .. "', health='" .. mysql:escape_string(health) .. "', armor='" .. mysql:escape_string(armor) .. "', dimension_id='" .. mysql:escape_string(dimension) .. "', interior_id='" .. mysql:escape_string(interior) .. "' WHERE id="..(mysql:escape_string(tonumber(getElementData(source, "character:id"))))) 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), savePlayer) 
addEvent("savePlayer", false) 
addEventHandler("savePlayer", getRootElement(), savePlayer) 
addCommandHandler("saveall", savePlayer) 
  

Posted

for that case, is not better to use setAccountData / getAccountData.

?

there are two kinds of people: those who know C++ and those who don´t. .)

Posted

i mean, for example, if you want to save the dimension of the player ....

  
addEventHandler ("onPlayerQuit", getRootElement (), 
   function ()  
        local account = getPlayerAccount (source); 
        setAccountData (account, "dimension", getElementDimension(source));  
   end);  
  

when player connects again to the server, you can do this to restore the dimension in which the player is in.

  
addEventHandler ("onPlayerJoin", getRootElement(),  
    function ()  
         local account = getPlayerAccount(source); 
         local dimension = getAccountData(accout,"dimension"); 
         if dimension then setElementDimension (source, tonumber(dimension); end;  
    end);  
  

is just another way to do it.

there are two kinds of people: those who know C++ and those who don´t. .)

Posted
i mean, for example, if you want to save the dimension of the player ....
  
addEventHandler ("onPlayerQuit", getRootElement (), 
   function ()  
        local account = getPlayerAccount (source); 
        setAccountData (account, "dimension", getElementDimension(source));  
   end);  
  

when player connects again to the server, you can do this to restore the dimension in which the player is in.

  
addEventHandler ("onPlayerJoin", getRootElement(),  
    function ()  
         local account = getPlayerAccount(source); 
         local dimension = getAccountData(accout,"dimension"); 
         if dimension then setElementDimension (source, tonumber(dimension); end;  
    end);  
  

is just another way to do it.

Actually it's impossible to collect data without knowing if the players logged in or not, hence no account defined.

Use "onPlayerLogin"

And now Aurora is back again, pm for more info.

Ex. Lead dev & L6 Staff at AUR, NGC, MTA RP & SAA.

Ex. Developer at Community of Social Gamers - CSG

Ex Founder of International Gaming Community - IGC and Union of Individual Players- UIP

9o6E8.png Ab-47

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