Jump to content

Saving weapons


Baseplate

Recommended Posts

I dunno, as everyone is using those functions on login and logout only made me a bit confused. Thanks mate :D

addEventHandler("onPlayerWasted", root, 
function() 
if (account) then 
setAccountData(account, "save-wep0", getPedWeapon(source, 0)) 
setAccountData (account, "save-ammo0", getPedTotalAmmo (source, 0)) 
setAccountData(account, "save-wep1", getPedWeapon(source, 1)) 
setAccountData (account, "save-ammo1", getPedTotalAmmo (source, 1)) 
setAccountData(account, "save-wep2", getPedWeapon(source, 2)) 
setAccountData (account, "save-ammo2", getPedTotalAmmo (source, 2)) 
setAccountData(account, "save-wep3", getPedWeapon(source, 3)) 
setAccountData (account, "save-ammo3", getPedTotalAmmo (source, 3)) 
setAccountData(account, "save-wep4", getPedWeapon(source, 4)) 
setAccountData (account, "save-ammo4", getPedTotalAmmo (source, 4)) 
setAccountData(account, "save-wep5", getPedWeapon(source, 5)) 
setAccountData (account, "save-ammo5", getPedTotalAmmo (source, 5)) 
setAccountData(account, "save-wep6", getPedWeapon(source, 6)) 
setAccountData (account, "save-ammo6", getPedTotalAmmo (source, 6)) 
setAccountData(account, "save-wep7", getPedWeapon(source, 7)) 
setAccountData (account, "save-ammo7", getPedTotalAmmo (source, 7)) 
setAccountData(account, "save-wep8", getPedWeapon(source, -- s8) -->) 
setAccountData (account, "save-ammo8", getPedTotalAmmo (source, -- s8) -->) 
setAccountData(account, "save-wep9", getPedWeapon(source, 9)) 
setAccountData (account, "save-ammo9", getPedTotalAmmo (source, 9)) 
setAccountData(account, "save-wep10", getPedWeapon(source, 10)) 
setAccountData (account, "save-ammo10", getPedTotalAmmo (source, 10)) 
setAccountData(account, "save-wep11", getPedWeapon(source, 11)) 
setAccountData (account, "save-ammo11", getPedTotalAmmo (source, 11)) 
setAccountData(account, "save-wep12", getPedWeapon(source, 12)) 
setAccountData (account, "save-ammo12", getPedTotalAmmo (source, 12)) 
end 
end 
end 
) 
addEventHandler("onPlayerSpawn", root, 
function() 
local account = getPlayerAccount(source) 
if not (isGuestAccount (getPlayerAccount (source))) then 
local wep1 = getAccountData(theCurrentAccount, "save-wep1") 
local ammo1 = getAccountData(theCurrentAccount, "save-ammo1") 
local wep2 = getAccountData(theCurrentAccount, "save-wep2") 
local ammo2 = getAccountData(theCurrentAccount, "save-ammo2") 
local wep3 = getAccountData(theCurrentAccount, "save-wep3") 
local ammo3 = getAccountData(theCurrentAccount, "save-ammo3") 
local wep4 = getAccountData(theCurrentAccount, "save-wep4") 
local ammo4 = getAccountData(theCurrentAccount, "save-ammo4") 
local wep5 = getAccountData(theCurrentAccount, "save-wep5") 
local ammo5 = getAccountData(theCurrentAccount, "save-ammo5") 
local wep6 = getAccountData(theCurrentAccount, "save-wep6") 
local ammo6 = getAccountData(theCurrentAccount, "save-ammo6") 
local wep7 = getAccountData(theCurrentAccount, "save-wep7") 
local ammo7 = getAccountData(theCurrentAccount, "save-ammo7") 
local wep8 = getAccountData(theCurrentAccount, "save-wep8") 
local ammo8 = getAccountData(theCurrentAccount, "save-ammo8") 
local wep9 = getAccountData(theCurrentAccount, "save-wep9") 
local ammo9 = getAccountData(theCurrentAccount, "save-ammo9") 
local wep10 = getAccountData(theCurrentAccount, "save-wep10") 
local ammo10 = getAccountData(theCurrentAccount, "save-ammo10") 
local wep11 = getAccountData(theCurrentAccount, "save-wep11") 
local ammo11 = getAccountData(theCurrentAccount, "save-ammo11") 
local wep12 = getAccountData(theCurrentAccount, "save-wep12") 
local ammo12 = getAccountData(theCurrentAccount, "save-ammo12") 
setElementData(source, "Occupation", occupation) 
spawnPlayer(source, x, y, z, interior, dimension) 
setElementHealth(source, health) 
setElementModel(source, skin) 
setPlayerTeam(source, getTeamFromName(team)) 
setPlayerMoney(source, money) 
setPedArmor(source, armor) 
setPlayerWantedLevel(source, wanted) 
giveWeapon(source, wep1, ammo1) 
giveWeapon(source, wep2, ammo2) 
giveWeapon(source, wep3, ammo3) 
giveWeapon(source, wep4, ammo4) 
giveWeapon(source, wep5, ammo5) 
giveWeapon(source, wep6, ammo6) 
giveWeapon(source, wep7, ammo7) 
giveWeapon(source, wep8, ammo8) 
giveWeapon(source, wep9, ammo9) 
giveWeapon(source, wep10, ammo10) 
giveWeapon(source, wep11, ammo11) 
giveWeapon(source, wep12, ammo12) 
end 
end 
) 

Will this work?

Link to comment
I dunno, as everyone is using those functions on login and logout only made me a bit confused. Thanks mate :D
addEventHandler("onPlayerWasted", root, 
function() 
if (account) then 
setAccountData(account, "save-wep0", getPedWeapon(source, 0)) 
setAccountData (account, "save-ammo0", getPedTotalAmmo (source, 0)) 
setAccountData(account, "save-wep1", getPedWeapon(source, 1)) 
setAccountData (account, "save-ammo1", getPedTotalAmmo (source, 1)) 
setAccountData(account, "save-wep2", getPedWeapon(source, 2)) 
setAccountData (account, "save-ammo2", getPedTotalAmmo (source, 2)) 
setAccountData(account, "save-wep3", getPedWeapon(source, 3)) 
setAccountData (account, "save-ammo3", getPedTotalAmmo (source, 3)) 
setAccountData(account, "save-wep4", getPedWeapon(source, 4)) 
setAccountData (account, "save-ammo4", getPedTotalAmmo (source, 4)) 
setAccountData(account, "save-wep5", getPedWeapon(source, 5)) 
setAccountData (account, "save-ammo5", getPedTotalAmmo (source, 5)) 
setAccountData(account, "save-wep6", getPedWeapon(source, 6)) 
setAccountData (account, "save-ammo6", getPedTotalAmmo (source, 6)) 
setAccountData(account, "save-wep7", getPedWeapon(source, 7)) 
setAccountData (account, "save-ammo7", getPedTotalAmmo (source, 7)) 
setAccountData(account, "save-wep8", getPedWeapon(source, -- s8) -->) 
setAccountData (account, "save-ammo8", getPedTotalAmmo (source, -- s8) -->) 
setAccountData(account, "save-wep9", getPedWeapon(source, 9)) 
setAccountData (account, "save-ammo9", getPedTotalAmmo (source, 9)) 
setAccountData(account, "save-wep10", getPedWeapon(source, 10)) 
setAccountData (account, "save-ammo10", getPedTotalAmmo (source, 10)) 
setAccountData(account, "save-wep11", getPedWeapon(source, 11)) 
setAccountData (account, "save-ammo11", getPedTotalAmmo (source, 11)) 
setAccountData(account, "save-wep12", getPedWeapon(source, 12)) 
setAccountData (account, "save-ammo12", getPedTotalAmmo (source, 12)) 
end 
end 
end 
) 
addEventHandler("onPlayerSpawn", root, 
function() 
local account = getPlayerAccount(source) 
if not (isGuestAccount (getPlayerAccount (source))) then 
local wep1 = getAccountData(theCurrentAccount, "save-wep1") 
local ammo1 = getAccountData(theCurrentAccount, "save-ammo1") 
local wep2 = getAccountData(theCurrentAccount, "save-wep2") 
local ammo2 = getAccountData(theCurrentAccount, "save-ammo2") 
local wep3 = getAccountData(theCurrentAccount, "save-wep3") 
local ammo3 = getAccountData(theCurrentAccount, "save-ammo3") 
local wep4 = getAccountData(theCurrentAccount, "save-wep4") 
local ammo4 = getAccountData(theCurrentAccount, "save-ammo4") 
local wep5 = getAccountData(theCurrentAccount, "save-wep5") 
local ammo5 = getAccountData(theCurrentAccount, "save-ammo5") 
local wep6 = getAccountData(theCurrentAccount, "save-wep6") 
local ammo6 = getAccountData(theCurrentAccount, "save-ammo6") 
local wep7 = getAccountData(theCurrentAccount, "save-wep7") 
local ammo7 = getAccountData(theCurrentAccount, "save-ammo7") 
local wep8 = getAccountData(theCurrentAccount, "save-wep8") 
local ammo8 = getAccountData(theCurrentAccount, "save-ammo8") 
local wep9 = getAccountData(theCurrentAccount, "save-wep9") 
local ammo9 = getAccountData(theCurrentAccount, "save-ammo9") 
local wep10 = getAccountData(theCurrentAccount, "save-wep10") 
local ammo10 = getAccountData(theCurrentAccount, "save-ammo10") 
local wep11 = getAccountData(theCurrentAccount, "save-wep11") 
local ammo11 = getAccountData(theCurrentAccount, "save-ammo11") 
local wep12 = getAccountData(theCurrentAccount, "save-wep12") 
local ammo12 = getAccountData(theCurrentAccount, "save-ammo12") 
setElementData(source, "Occupation", occupation) 
spawnPlayer(source, x, y, z, interior, dimension) 
setElementHealth(source, health) 
setElementModel(source, skin) 
setPlayerTeam(source, getTeamFromName(team)) 
setPlayerMoney(source, money) 
setPedArmor(source, armor) 
setPlayerWantedLevel(source, wanted) 
giveWeapon(source, wep1, ammo1) 
giveWeapon(source, wep2, ammo2) 
giveWeapon(source, wep3, ammo3) 
giveWeapon(source, wep4, ammo4) 
giveWeapon(source, wep5, ammo5) 
giveWeapon(source, wep6, ammo6) 
giveWeapon(source, wep7, ammo7) 
giveWeapon(source, wep8, ammo8) 
giveWeapon(source, wep9, ammo9) 
giveWeapon(source, wep10, ammo10) 
giveWeapon(source, wep11, ammo11) 
giveWeapon(source, wep12, ammo12) 
end 
end 
) 

Will this work?

Link to comment

at "onPlayerWasted" event you forgot to define 'account', I've changed your script a bit:

addEventHandler ( "onPlayerWasted", root, 
    function ( ) 
        local account = getPlayerAccount ( source ) 
        if ( account and not isGuestAccount ( account ) ) then 
            for slot = 1, 12 do 
                setAccountData ( account, "save-wep".. slot, getPedWeapon ( source, slot ) ) 
                setAccountData ( account, "save-ammo".. slot, getPedTotalAmmo ( source, slot ) ) 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerSpawn", root, 
    function ( ) 
        local account = getPlayerAccount ( source ) 
        if ( account and not isGuestAccount ( account ) ) then 
            setElementData ( source, "Occupation", occupation ) 
            spawnPlayer ( source, x, y, z, interior, dimension ) 
            setElementHealth ( source, health ) 
            setElementModel ( source, skin ) 
            setPlayerTeam ( source, getTeamFromName(team) ) 
            setPlayerMoney ( source, money ) 
            setPedArmor ( source, armor ) 
            setPlayerWantedLevel ( source, wanted ) 
            for slot = 1, 12 do 
                local wep = getAccountData ( account, "save-wep".. slot ) 
                local ammo = getAccountData ( account, "save-ammo".. slot ) 
                giveWeapon ( source, wep, ammo ) 
            end 
        end 
    end 
) 

It works ( tested ).

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