GiveWeapon: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 7: | Line 7: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''thePlayer:''' A [[player]] object referencing the specified player | *'''thePlayer:''' A [[player]] object referencing the specified player | ||
*'''weapon:''' A whole number integer that refers to a [[Weapon]] ID. Click | *'''weapon:''' A whole number integer that refers to a [[Weapon]] ID. Click [[Weapon|here]] for a list of possible weapon IDs. | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{OptionalArg}} | {{OptionalArg}} | ||
*'''ammo:''' A whole number integer serving as the ammo amount for the given weapon | *'''ammo:''' 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:''' A boolean value determining whether or not the weapon will be set as the players current. | *'''setAsCurrent:''' A boolean value determining whether or not the weapon will be set as the players current. | ||
==Example== | ==Example== | ||
This example gives a player an M4 with 200 ammo whenever they spawn. | '''Example 1:''' This example gives a player an M4 with 200 ammo whenever they spawn. | ||
<syntaxhighlight lang="lua">addEventHandler ( "onSpawnpointUse", getRootElement(), " | <syntaxhighlight lang="lua"> | ||
function | function giveWeaponsOnSpawn ( thePlayer ) | ||
giveWeapon ( thePlayer, 31, 200 ) -- Gives the M4 weapon with 200 ammo | |||
end</syntaxhighlight> | end | ||
addEventHandler ( "onSpawnpointUse", getRootElement(), giveWeaponsOnSpawn ) --attach the event handler | |||
</syntaxhighlight> | |||
'''Example 2:''' This example adds a "give" command in console which allows giving of any weapon by entering "give <id> <amount>". | |||
<syntaxhighlight lang="lua"> | |||
function consoleGive ( thePlayer, commandName, weaponID, ammo ) | |||
local status = giveWeapon ( thePlayer, weaponID, ammo, true ) --attempt to give the weapon, forcing | |||
if ( not status ) then --if it was unsuccessful | |||
outputConsole ( "Failed to give weapon.", thePlayer ) --tell the player | |||
end | |||
end | |||
end | |||
addCommandHandler ( "give", consoleGive ) | |||
</syntaxhighlight> | |||
==See Also== | ==See Also== | ||
{{Weapon functions}} | {{Weapon functions}} |
Revision as of 15:58, 29 July 2007
giveWeapon gives a specified weapon to a certain player. There is an optional argument to specify ammunition. For example, a melee weapon doesn't need an ammo argument.
Syntax
giveWeapon ( player thePlayer, int weapon, [ int ammo=30, bool setAsCurrent=false ] )
Required Arguments
- thePlayer: A player object referencing the specified player
- weapon: A whole number integer that refers to a Weapon ID. Click here for a list of possible weapon IDs.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- ammo: 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: A boolean value determining whether or not the weapon will be set as the players current.
Example
Example 1: This example gives a player an M4 with 200 ammo whenever they spawn.
function giveWeaponsOnSpawn ( thePlayer ) giveWeapon ( thePlayer, 31, 200 ) -- Gives the M4 weapon with 200 ammo end addEventHandler ( "onSpawnpointUse", getRootElement(), giveWeaponsOnSpawn ) --attach the event handler
Example 2: This example adds a "give" command in console which allows giving of any weapon by entering "give <id> <amount>".
function consoleGive ( thePlayer, commandName, weaponID, ammo ) local status = giveWeapon ( thePlayer, weaponID, ammo, true ) --attempt to give the weapon, forcing if ( not status ) then --if it was unsuccessful outputConsole ( "Failed to give weapon.", thePlayer ) --tell the player end end end addCommandHandler ( "give", consoleGive )
See Also
- getWeaponProperty
- getPickupWeapon
- getOriginalWeaponProperty
- getSlotFromWeapon
- getWeaponIDFromName
- getWeaponNameFromID
- setWeaponAmmo
- setWeaponProperty