Jump to content

Guardar armas al desconectarse muerto


Recommended Posts

Hola, encontre en el foro algo que deberia guardar al morir, guarda, pero si estoy muerto y me desconecto, se me va todas las armas, nose como podria reparar esto aca dejo el codigo

  
local playerWeapons = { } 
  
addEventHandler ( "onPlayerWasted", root, 
    function ( ) 
        if ( not playerWeapons [ source ] ) then 
            playerWeapons [ source ] = { } 
        end 
        for slot = 0, 12 do 
            local weapon = getPedWeapon ( source, slot ) 
            if ( weapon > 0 ) then 
                local ammo = getPedTotalAmmo ( source, slot ) 
                if ( ammo > 0 ) then 
                    playerWeapons [ source ] [ weapon ] = ammo 
                end 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerSpawn", root, 
    function ( ) 
        if ( playerWeapons [ source ] ) then 
            for weapon, ammo in pairs ( playerWeapons [ source ] ) do 
                giveWeapon ( source, tonumber ( weapon ), tonumber ( ammo ) ) 
            end  
        end 
  
        playerWeapons [ source ] = nil 
    end 
) 
  
  
function saveWeapons(player, account) 
if player and account then 
    for i=0,12 do 
        local weapon = getPedWeapon(player, i) 
        local ammo = getPedTotalAmmo(player, i) 
        setAccountData(account,"w"..tonumber(i), weapon) 
        setAccountData(account,"a"..tonumber(i), ammo) 
    end 
    takeAllWeapons(player) 
    end 
end 
  
  
addEventHandler("onPlayerQuit",root,function () saveWeapons(source, getPlayerAccount(source)) end) 
addEventHandler("onPlayerWasted",root,function () saveWeapons(source, getPlayerAccount(source)) end) 
addEventHandler("onPlayerLogout",root,function(prev) saveWeapons(source, prev) end) 
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if not account or isGuestAccount(account) then return end 
    for i=0,12 do 
        local weapon = getAccountData(account,"w"..tonumber(i)) 
        local ammo = getAccountData(account,"a"..tonumber(i)) 
        if weapon and ammo then 
            setTimer(giveWeapon, 1000, 1, source, tonumber(weapon), tonumber(ammo), true) 
        end 
    end 
end) 
  
  

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