Jump to content

Edited. Source Closed.


GhostXoP

Recommended Posts

Posted

I had asked a question on the forums asking how many weapons a user could possibly have at one time and you said "a player could have 1 of every weapon"

Unless you misunderstood my former question

Posted

The first time, it goes through and the weapons Bat and Pistol show up once. The next death on getPedWeapon it says the user has no weapons.

Posted

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) 

Posted

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.

Posted
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 

Posted

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?

Posted

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 
) 

Posted (edited)

Can you please explain why you had to use a timer? Is it that the server asks for the information too fast? Just in case i run into this again.

Edited by Guest
Posted

So the time may range even longer then once second? Either way, Thank you very much for solving this Extensive problem. When this server is done, i may consider putting you as a mod for bug watch.

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