Mittell Buurman Posted August 5, 2013 Share Posted August 5, 2013 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) Link to comment
Vector Posted August 5, 2013 Share Posted August 5, 2013 for that case, is not better to use setAccountData / getAccountData. ? Link to comment
Mittell Buurman Posted August 5, 2013 Author Share Posted August 5, 2013 I'm using ElementData, not AccountData, everything is being exported to the MySQL Link to comment
Vector Posted August 5, 2013 Share Posted August 5, 2013 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. Link to comment
Ab-47 Posted August 5, 2013 Share Posted August 5, 2013 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" 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