giveWeapon
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
giveWeapon gives a specified weapon to a certain player or ped. There is an optional argument to specify ammunition. For example, a melee weapon doesn't need an ammo argument.
When setting ammo for weapons in slot 0,1,10,11 or 12, the ammo max is 1 When setting ammo for weapons in slot 3,4,5, the ammo is added When setting ammo for weapons in slot 2,6,7,8,9 and the slot weapon is changing, the ammo is replaced
Syntax
bool giveWeapon ( ped thePlayer, int weapon, [ int ammo = 30, bool setAsCurrent = false ] )Required Arguments
- thePlayer: A player or ped object referencing the specified player (or ped )
- weapon: A whole number integer that refers to a Weapon ID.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- ammo (default: 30): A whole number integer serving as the ammo amount for the given weapon. For weapons that do not require ammo, such as melee, this should be at least 1.
- setAsCurrent (default: false): A boolean value determining whether or not the weapon will be set as the players current.
Returns
- bool: value
Returns true if weapon was successfully acquired, false otherwise.
Code Examples
Example 1:This example gives a player an M4 with 200 ammo whenever they spawn.
function giveWeaponsOnSpawn ( theSpawnpont, theTeam ) giveWeapon ( source, 31, 200 ) -- Gives the M4 weapon with 200 ammoendaddEventHandler ( "onPlayerSpawn", root, giveWeaponsOnSpawn ) -- attach the event handler