Jump to content

Account Data Problem...!


Jammie

Recommended Posts

Hi People,

I've got a problem about this save system for your weapons. I work with account data and the problem is that if you die then it saved your weapons and if you die and you type after die /logout then it saved your weapons too.. but without die and you type: /logout or /disconnect (quit) then you lost all your weapons... doesnt save!. And if you after die type: /disconnect then it will not save too!! :S

This will be saved in accounts.xml.

I hope someone knows the problem... thanks!

local playerWeapons = createElement("playerWeapons")
 
 
function resourceStart()
local players = getElementsByType("player")
for index, value in pairs(players) do
local newElement = createElement("playerWeapons")
setElementData(newElement, "player", value, false)
setElementData(newElement, "weapons", {}, false)
setElementParent(newElement, playerWeapons)
end
end
 
 
addEventHandler("onResourceStart", getResourceRootElement(), resourceStart)
 
 
function playerLogin(previousAcc, currentAcc)
local weaponList = getElementChildren(playerWeapons)
for index, value in pairs(weaponList) do
if getElementData(value, "player", false) == source then
local weapons = getElementData(value, "weapons", false)
for count = 0, 11, 1 do
local weapon, ammo = getAccountData(currentAcc, "weapon"..count), getAccountData(currentAcc, "ammo"..count)
if weapon and ammo then
				weapons[count] = { [0] = weapon, [1] = ammo }
giveWeapon(source, weapon, ammo)
end
end
setElementData(value, "weapons", weapons, false)
return
end
end
end
 
 
addEventHandler("onPlayerLogin", getRootElement(), playerLogin)
 
 
 
 
function playerLogout(prevAccount)
local weaponList = getElementChildren(playerWeapons)
for index, value in pairs(weaponList) do
if getElementData(value, "player", false) == source then
local weapons = getElementData(value, "weapons", false)
for count = 0, 11, 1 do
if weapons[count] then
setAccountData(prevAccount, "weapon"..count, weapons[count][0])
setAccountData(prevAccount, "ammo"..count, weapons[count][1])
setWeaponAmmo(source, weapons[count][0], getPedTotalAmmo(source, count) - weapons[count][1])
				weapons[count][1] = getPedTotalAmmo(source, count) - weapons[count][1]
end
end
end
end
end
 
 
addEventHandler("onPlayerLogout", getRootElement(), playerLogout)
 
 
 
 
function playerSpawn()
local weaponList = getElementChildren(playerWeapons)
for index, value in pairs(weaponList) do
if getElementData(value, "player", false) == source then
local weapons = getElementData(value, "weapons", false)
for count = 0, 11, 1 do
if weapons[count] then
giveWeapon(source, weapons[count][0], weapons[count][1])
end
end
return
end
end
end
 
 
addEventHandler("onPlayerSpawn", getRootElement(), playerSpawn)
 
 
 
 
function playerWasted()
local weaponList = getElementChildren(playerWeapons)
for index, value in pairs(weaponList) do
if getElementData(value, "player", false) == source then
local weapons = getElementData(value, "weapons", false)
for count = 0, 11, 1 do
			weapons[count] = { [0] = getPedWeapon(source, count), [1] = getPedTotalAmmo(source, count) }
end
setElementData(value, "weapons", weapons, false)
return
end
end
end
 
 
addEventHandler("onPlayerWasted", getRootElement(), playerWasted)
 
 
 
 
function playerQuit(prevAccount)
local weaponList = getElementChildren(playerWeapons)
for index, value in pairs(weaponList) do
if getElementData(value, "player", false) == source then
local weapons = getElementData(value, "weapons", false)
for count = 0, 11, 1 do
if weapons[count] then
setAccountData(prevAccount, "weapon"..count, weapons[count][0])
setAccountData(prevAccount, "ammo"..count, weapons[count][1])
setWeaponAmmo(source, weapons[count][0], getPedTotalAmmo(source, count) - weapons[count][1])
				weapons[count][1] = getPedTotalAmmo(source, count) - weapons[count][1]
end
end
end
end
end
 
 
addEventHandler("onPlayerQuit", getRootElement(), playerQuit)

Edited by Guest
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...