Jump to content

Weapon save


nick1995

Recommended Posts

local tempData = { } 
      
    addEventHandler ( "onPlayerWasted", getRootElement(), 
        function ( ) 
            tempData [ source ] = 
                { 
                    weapons = getWeaponsTable ( source ), 
                    skin = getElementModel ( source ) 
                } 
        end 
    ) 
      
    addEventHandler ( "onPlayerSpawn", getRootElement(), 
        function ( ) 
            if ( tempData [ source ] ) then 
                setElementModel ( source, tempData [ source ].skin ) 
                for weapon, ammo in pairs ( tempData [ source ].weapons ) do 
                    giveWeapon ( source, weapon, ammo, true ) 
                end 
            end 
        end 
    ) 
      
    function getWeaponsTable ( thePlayer ) 
        local weapons = { } 
        local hasAnyWeapon = false 
        for slot = 0, 12 do 
            local weapon = getPedWeapon ( thePlayer, slot ) 
            if ( weapon > 0 ) then 
                local ammo = getPedTotalAmmo ( thePlayer, slot ) 
                if ( ammo > 0 ) then 
                    weapons [ weapon ] = ammo 
                    hasAnyWeapon = true 
                end 
            end 
        end 
        if ( hasAnyWeapon ) then 
            return weapons 
        end 
    end 

Here you have :)

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