Jump to content

Edited. Source Closed.


GhostXoP

Recommended Posts

try this:

function storeWeps(player) 
    for i=0,12 do 
        local pedWep = getPedWeapon(player,i) 
        if(pedWep)then 
            playerTable[player]={pedWep} 
        end 
    end 
end 
  
function getMyWeps(player) 
    local myWep = playerTable[player] 
    if(myWep)then 
        for i,v in ipairs(myWep)do 
            giveWeapon(player,v) 
        end 
    end 
end 
  
addEventHandler("onPlayerWasted",root,function() 
    storeWeps(source) 
end) 
  
addEventHandler("onPlayerSpawn",root,function() 
    getMyWeps(source) 
end) 

Link to comment

My problem is the getPedWeapon on the second death says the ped does not have any weapons. If the ped dies once, it says the ped has a pistol and bat, stores it, then restores it after spawning. However, if the ped dies again, it doesn't say the ped has any weapons, like the first time the ped died.

Link to comment
function RecyclePlayerStats ( source ) 
    local PlayerSTATTable = { } 
    PlayerSTATTable.PlayerWeapons = makeClientWeaponsTable ( source ) 
    PlayerSTATTable.POSX, PlayerSTATTable.POSY, PlayerSTATTable.POSZ = getElementPosition ( source ) 
  
    return PlayerSTATTable  
end 
  
function makeClientWeaponsTable ( source ) 
    local temptable = { } 
    for slot = 0, 11 do --12 possible weapons 
        local weapon = getPedWeapon ( source, slot )  
        if ( weapon ~= 0 ) then 
            temptable [ weapon ] = getPedTotalAmmo ( source, slot )  
        end 
    end 
  
    return temptable 
end 

Link to comment

I'm not sure what it is you have changed other then the if block. Even so it doesn't work.

The problem is, One first spawn, the player has a pistol and a bat.

-Player dies, at the event the weapons are retrieved, saved, player spawns, then weapons are restored.

-Player dies again, at the event, weapons are NOT retrieved as none are found?

Link to comment

Ok, I've added a 1 second timer and it's working now.

function RecyclePlayerStats ( thePlayer ) 
    local PlayerSTATTable = { } 
    PlayerSTATTable.PlayerWeapons = makeClientWeaponsTable ( thePlayer ) 
    PlayerSTATTable.POSX, PlayerSTATTable.POSY, PlayerSTATTable.POSZ = getElementPosition ( thePlayer ) 
  
    return PlayerSTATTable 
end 
  
function makeClientWeaponsTable ( thePlayer ) 
    local temptable = { } 
    for slot = 0, 11 do --12 possible weapons 
        local weapon = getPedWeapon ( thePlayer, slot ) 
        if ( weapon ~= 0 ) then 
            temptable [ weapon ] = getPedTotalAmmo ( thePlayer, slot ) 
        end 
    end 
  
    return temptable 
end 

addEventHandler ( "onPlayerWasted", getRootElement(), 
    function ( ) 
        local PlayerTable = RecyclePlayerStats ( source ) 
        --Tell death 
  
        --Spawn the player 
        setTimer ( 
            function ( thePlayer, stats ) 
                if spawnPlayer ( thePlayer, stats.POSX, stats.POSY, stats.POSZ ) then 
                    --Give the player his weapons 
                    for Weapon, Ammo in pairs ( stats.PlayerWeapons ) do 
                        outputChatBox ( tostring ( Weapon ) ) --DEBUG 
                        giveWeapon ( thePlayer, Weapon, Ammo ) 
                    end 
  
                    fadeCamera ( thePlayer, true ) 
                    setCameraTarget ( thePlayer, thePlayer ) 
                end 
            end 
            ,1000, 1, source, PlayerTable 
        ) 
    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...