GivePedWeapon: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ {{Client function}} {{New feature/item|3.0141|1.4.1|6937| This function gives a specified weapon to the specified ped, this function cannot be used for players. The...") |
mNo edit summary |
||
Line 31: | Line 31: | ||
local x, y, z = getElementPosition(localPlayer) -- Get your position | local x, y, z = getElementPosition(localPlayer) -- Get your position | ||
local thePed = createPed(0, x + 1, y, z) -- Create a CJ ped nearby | local thePed = createPed(0, x + 1, y, z) -- Create a CJ ped nearby | ||
givePedWeapon(thePed, 31, 5000, true) -- Give him 5000 rounds of M4 | |||
setControlState(thePed, "fire", true) -- Make him shoot continuously | setControlState(thePed, "fire", true) -- Make him shoot continuously | ||
end | end |
Revision as of 23:18, 18 November 2014
This function gives a specified weapon to the specified ped, this function cannot be used for players. There is an optional argument to specify ammunition and whether to set as current weapon. For example, a melee weapon doesn't need an ammo argument.
Syntax
bool givePedWeapon ( ped thePed, int weapon [, int ammo=30, bool setAsCurrent=false ] )
Required Arguments
- thePed: A ped element.
- 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.
Returns
Returns true if weapon was successfully given to the ped, false otherwise.
Example
Example 1: This example creates a client side ped, gives them an M4 and make them shoot once you do the command '/armedped'
function cmdArmedPed( command ) local x, y, z = getElementPosition(localPlayer) -- Get your position local thePed = createPed(0, x + 1, y, z) -- Create a CJ ped nearby givePedWeapon(thePed, 31, 5000, true) -- Give him 5000 rounds of M4 setControlState(thePed, "fire", true) -- Make him shoot continuously end addCommandHandler("armedped", cmdArmedPed)
See Also
- Shared
- getWeaponProperty
- getPickupWeapon
- getOriginalWeaponProperty
- getSlotFromWeapon
- getWeaponIDFromName
- getWeaponNameFromID
- setWeaponAmmo
- setWeaponProperty