Hello there i used Account and Element data to make a weapon save system and works fine , but if someone dead and disconnected from the server His weapons will be lost. Here is the code :
function onPlayerQuitWeaponSave()
local playeraccount = getPlayerAccount(source)
if (playeraccount) and not isGuestAccount(playeraccount) then
if getElementData(source,"22") == false then
local ca = 3
setAccountData(playeraccount, "cadd", ca)
else
if getElementData(source,"22") == true then
local caa = 2
setAccountData(playeraccount, "cadd", caa)
end
end
if getElementData(source,"24") == false then
local da = 3
setAccountData ( playeraccount, "dadd", da )
else
if getElementData(source,"24") == true then
local daa = 2
setAccountData ( playeraccount, "dadd", daa )
end
end
if getElementData(source,"23") == false then
local sila = 3
setAccountData ( playeraccount, "siladd", sila )
else
if getElementData(source,"23") == true then
local silaa = 2
setAccountData ( playeraccount, "siladd", silaa )
end
end
if getElementData(source,"25") == false then
local sha = 3
setAccountData ( playeraccount, "shadd", sha )
else
if getElementData(source,"25") == true then
local shaa = 2
setAccountData ( playeraccount, "shadd", shaa )
end
end
if getElementData(source,"26") == false then
local swa = 3
setAccountData ( playeraccount, "swadd", swa )
else
if getElementData(source,"26") == true then
local swaa = 2
setAccountData ( playeraccount, "swadd", swaa )
end
end
if getElementData(source,"27") == false then
local spa = 3
setAccountData ( playeraccount, "spadd", spa )
else
if getElementData(source,"27") == true then
local spaa = 2
setAccountData ( playeraccount, "spadd", spaa )
end
end
if getElementData(source,"30") == false then
local aka = 3
setAccountData ( playeraccount, "akadd", aka )
else
if getElementData(source,"30") == true then
local akaa = 2
setAccountData ( playeraccount, "akadd", akaa )
end
end
if getElementData(source,"31") == false then
local ma = 3
setAccountData ( playeraccount, "madd", ma )
else
if getElementData(source,"31") == true then
local maa = 2
setAccountData ( playeraccount, "madd", maa )
end
end
if getElementData(source,"28") == false then
local ua = 3
setAccountData ( playeraccount, "uadd", ua )
else
if getElementData(source,"28") == true then
local uaa = 2
setAccountData ( playeraccount, "uadd", uaa )
end
end
if getElementData(source,"32") == false then
local ta = 3
setAccountData ( playeraccount, "tadd", ta )
else
if getElementData(source,"32") == true then
local taa = 2
setAccountData ( playeraccount, "tadd", taa )
end
end
if getElementData(source,"29") == false then
local mpa = 3
setAccountData ( playeraccount, "mpadd", mpa )
else
if getElementData(source,"29") == true then
local mpaa = 2
setAccountData ( playeraccount, "mpadd", mpaa )
end
end
if getElementData(source,"33") == false then
local ra = 3
setAccountData ( playeraccount, "radd", ra )
else
if getElementData(source,"33") == true then
local raa = 2
setAccountData ( playeraccount, "radd", raa )
end
end
if getElementData(source,"34") == false then
local sna = 3
setAccountData ( playeraccount, "snadd", sna )
else
if getElementData(source,"34") == true then
local snaa = 2
setAccountData ( playeraccount, "snadd", snaa )
end
end
if getElementData(source,"38") == false then
local mia = 3
setAccountData ( playeraccount, "miadd", mia )
else
if getElementData(source,"38") == true then
local miaa = 2
setAccountData ( playeraccount, "miadd", miaa )
end
end
end
end
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuitWeaponSave)
function onPlayerLoginWeaponSave(_, playeraccount)
if ( playeraccount ) then
local ca = getAccountData ( playeraccount, "cadd" )
if (ca == 2 ) then
setElementData (source, "22", true)
end
local da = getAccountData ( playeraccount, "dadd" )
if (da == 2 ) then
setElementData (source, "24", true)
end
local sila = getAccountData ( playeraccount, "siladd" )
if (sila == 2 ) then
setElementData (source, "23", true)
end
local sha = getAccountData ( playeraccount, "shadd" )
if (sha == 2 ) then
setElementData (source, "25", true)
end
local swa = getAccountData ( playeraccount, "swadd" )
if (swa == 2 ) then
setElementData (source, "26", true)
end
local spa = getAccountData ( playeraccount, "spadd" )
if (spa == 2 ) then
setElementData (source, "27", true)
end
local aka = getAccountData ( playeraccount, "akadd" )
if (aka == 2 ) then
setElementData (source, "30", true)
end
local ma = getAccountData ( playeraccount, "madd" )
if (ma == 2 ) then
setElementData (source, "31", true)
end
local ua = getAccountData ( playeraccount, "uadd" )
if (ua == 2 ) then
setElementData (source, "28", true)
end
local ta = getAccountData ( playeraccount, "tadd" )
if (ta == 2 ) then
setElementData (source, "32", true)
end
local mpa = getAccountData ( playeraccount, "mpadd" )
if (mpa == 2 ) then
setElementData (source, "29", true)
end
local ra = getAccountData ( playeraccount, "radd" )
if (ra == 2 ) then
setElementData (source, "33", true)
end
local sna = getAccountData ( playeraccount, "snadd" )
if (sna == 2 ) then
setElementData (source, "34", true)
end
local mia = getAccountData ( playeraccount, "miadd" )
if (mia == 2 ) then
setElementData (source, "38", true)
end
end
end
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLoginWeaponSave)
i tried to use addEventHandler("onPlayerWasted", getRootElement(), onPlayerQuitWeaponSave) but it didnt work with me .