Jump to content

Respawning without getting weapons removed


GamingTim

Recommended Posts

Alright so whenever a player respawns, their weapon would be disarmed. What are the functions/events needed to cancel that?.
onPlayerWasted 
getPedWeapon 
giveWeapon 
getPedTotalAmmo 
setWeaponAmmo 
setElementData -- to set its data, it's a way to do it 
getElementData -- get the weapons, it's a way to do it 

Think that'll do. :)

Link to comment
Alright so whenever a player respawns, their weapon would be disarmed. What are the functions/events needed to cancel that?.
onPlayerWasted 
getPedWeapon 
giveWeapon 
getPedTotalAmmo 
setWeaponAmmo 
setElementData -- to set its data, it's a way to do it 
getElementData -- get the weapons, it's a way to do it 

Think that'll do. :)

Thanks i'll go on wiki and research on those, thanks ;)

Edit: I'm kinda lost atm idk if i'm doing it right.

http://puu.sh/8nYn8.png

Link to comment

That's a good start, gladly I had some spare time to make you something useful.

To perform this with tables

local playerWeapons = { } 
  
function getAllWeapons( element ) 
    if ( not isElement( element ) ) or ( getElementType( element ) ~= "ped" and getElementType( element ) ~= "player" ) then return end 
    local weapons = { } 
    for i=0,12 do 
        local slotWeapon, slotAmmo = getPedWeapon( element, i ), getPedTotalAmmo( element, i ) 
        if ( slotWeapon > 0 ) and ( slotAmmo > 0 ) then 
            weapons[ i ] = { weaponID = slotWeapon, ammo = slotAmmo, currentSlot = getPedWeaponSlot( element ) == i or false } 
        end 
    end 
    return weapons 
end 
  
addEventHandler( "onPlayerWasted", root, 
    function( ) 
        local weapons = getAllWeapons( source ) 
        if ( weapons ) then 
            playerWeapons[ source ] = weapons 
        end 
    end 
) 
addEventHandler( "onPlayerSpawn", root, 
    function( ) 
        local weapons = playerWeapons[ source ] 
        if ( not weapons ) then return end 
        for slot,data in pairs( weapons ) do 
            giveWeapon( source, data.weaponID, data.ammo, data.currentSlot ) 
        end 
        outputChatBox( "Your weapons were restored from your death.", source, 20, 245, 20, false ) 
    end 
) 

To perform this with element data

function getAllWeapons( element ) 
    if ( not isElement( element ) ) or ( getElementType( element ) ~= "ped" and getElementType( element ) ~= "player" ) then return end 
    local weapons = { } 
    for i=0,12 do 
        local slotWeapon, slotAmmo = getPedWeapon( element, i ), getPedTotalAmmo( element, i ) 
        if ( slotWeapon > 0 ) and ( slotAmmo > 0 ) then 
            weapons[ i ] = { weaponID = slotWeapon, ammo = slotAmmo, currentSlot = getPedWeaponSlot( element ) == i or false } 
        end 
    end 
    return weapons 
end 
  
addEventHandler( "onPlayerWasted", root, 
    function( ) 
        local weapons = getAllWeapons( source ) 
        if ( weapons ) then 
            setElementData( source, "player:restore.weapons", weapons, false ) 
        end 
    end 
) 
addEventHandler( "onPlayerSpawn", root, 
    function( ) 
        local weapons = getElementData( source, "player:restore.weapons" ) or nil 
        if ( not weapons ) then return end 
        for slot,data in pairs( weapons ) do 
            giveWeapon( source, data.weaponID, data.ammo, data.currentSlot ) 
        end 
        removeElementData( source, "player:restore.weapons" ) 
        outputChatBox( "Your weapons were restored from your death.", source, 20, 245, 20, false ) 
    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...