Jump to content

Weapon Save Per Account


Recommended Posts

function saveWeapons ( ) 
    local account = getPlayerAccount ( source ); 
    if ( isGuestAccount ( account ) ) then 
        return; 
    end 
     
    local t = { } 
    for slot = 0, 12 do 
        local weapon = getPedWeapon ( source, slot ); 
        if ( weapon > 0 ) then 
            local ammo = getPedTotalAmmo ( source, slot ); 
            if ( ammo > 0 ) then 
                t [ weapon ] = ammo; 
            end 
        end 
    end 
     
    setAccountData ( account, "weapons", t ); 
end 
  
function loadWeapons ( _, account ) 
    if ( isGuestAccount ( account ) ) then 
        return; 
    end 
     
    local t = getAccountData ( account, "weapons" ); 
    if ( t ) then 
        for weapon, ammo in pairs ( t ) do 
            giveWeapon ( source, tonumber ( weapon ), tonumber ( ammo ) ); 
        end 
    end 
end 
  
addEventHandler ( "onPlayerQuit", root, saveWeapons ); 
addEventHandler ( "onPlayerLogout", root, saveWeapons ); 
addEventHandler ( "onPlayerLogin", root, loadWeapons ); 

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