luskanek Posted July 5, 2018 Share Posted July 5, 2018 -- This piece of code in located in the 'onPlayerQuit' event handler. It saves the player's weapons and ammo if he has any, this is all working correctly local weapons = {} for slot = 1, 12 do local weapon = getPedWeapon(source, slot) if weapon > 0 then local ammo = getPedTotalAmmo(source, slot) if ammo > 0 then table.insert(weapons, {weapon, ammo}) end end end -- This is what appears under the 'weapons' column in the player's account table entry [ [ [ 30, 176 ] ] ] -- Which means the player left the server and had an AK-47 with total 176 ammo left -- And this is the part which loads the SQL weapons data for weapon, ammo in ipairs(fromJSON(accountData.weapons)) do giveWeapon(player, tonumber(weapon), tonumber(ammo)) end -- The problem is, the player doesn't get the weapons he has saved, instead, he'll be given a brassknuckle everytime and the SQL entry is reset Any ideas why it is not working properly? I'm using SQLite not MySQL. The weapons are saved correctly, so it would seem that the problems stems in the loading part. Link to comment
Mr.Loki Posted July 6, 2018 Share Posted July 6, 2018 This is how i save and load: --save function getPlayerWeapons( p ) local weps={} for i=1,12 do weps[i]={getPedWeapon( p, i ),getPedTotalAmmo( p, i )} end return toJSON(weps) end --load local weaponTable = fromJSON(d.weapons) for i=1,12 do local row = weaponTable[i] if tonumber(row[2]) > 0 then giveWeapon( plr, row[1], row[2] ) end end 1 Link to comment
luskanek Posted July 6, 2018 Author Share Posted July 6, 2018 Thanks, that fixed the problem! 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