Jump to content

Saving weapons


Baseplate

Recommended Posts

Posted

Why wouldn't it be possible? save them on death, then load on spawn.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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?

Posted

Why don't you simply use arrays and JSON with account data? It's much easier.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

I remember when I used account data long ago, I stored weapons as JSON string, it ended cutting the string because of limit.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Well, never heard about that string limit. Seems like it gotta be done that way then ( unless there's some other way I'm not remembering ).

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted
I remember when I used account data long ago, I stored weapons as JSON string, it ended cutting the string because of limit.
Well, never heard about that string limit. Seems like it gotta be done that way then ( unless there's some other way I'm not remembering ).

What is JSON?

If you need an Intermediate scripter feel free to PM me as I will accept "almost" any job, STATUS: UNAVAILABLE

SCOTLAND, my hometown, and the Home of GTA!

Posted
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?

Posted

What stops you from testing it?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
What stops you from testing it?

Haha, good point!

If you need an Intermediate scripter feel free to PM me as I will accept "almost" any job, STATUS: UNAVAILABLE

SCOTLAND, my hometown, and the Home of GTA!

Posted

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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