GamingTim Posted April 26, 2014 Share Posted April 26, 2014 Alright so whenever a player respawns, their weapon would be disarmed. What are the functions/events needed to cancel that?. Link to comment
tosfera Posted April 26, 2014 Share Posted April 26, 2014 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
GamingTim Posted April 26, 2014 Author Share Posted April 26, 2014 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
myonlake Posted April 26, 2014 Share Posted April 26, 2014 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
GamingTim Posted April 26, 2014 Author Share Posted April 26, 2014 So basically there are two ways to do this? cool!. I'll try to learn from them, thanks again myonlake Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now