SetWeaponClipAmmo: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
m (Added OOP syntax and improved some things) |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client function}} | {{Client function}} | ||
This function sets the ammo left in a [[Element/Weapon|custom weapon]]'s magazine/clip. | |||
==Syntax== | ==Syntax== | ||
Line 9: | Line 9: | ||
* '''theWeapon:''' The [[Element/Weapon|weapon]] to set the clip ammo of. | * '''theWeapon:''' The [[Element/Weapon|weapon]] to set the clip ammo of. | ||
* '''clipAmmo:''' The amount of ammo in the clip. | * '''clipAmmo:''' The amount of ammo in the clip. | ||
===Example== | |||
===Returns=== | |||
This function returns ''true'' if the arguments are valid and the weapon clip ammo could be changed; ''fañse'' otherwise. | |||
==Example== | |||
This example adds a ''/weapon'' command that creates a M4 where the player uses it, and gives 1 clip ammo to it. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | function createWeaponWithLowClipAmmo() | ||
local wep = createWeapon("m4", | local wep = createWeapon("m4", getElementPosition(localPlayer)) | ||
setWeaponClipAmmo(wep, | setWeaponClipAmmo(wep, 1) -- Give the weapon 1 clip ammo, so it will reload at the next shoot. | ||
end | end | ||
addCommandHandler("weapon", | addCommandHandler("weapon", createWeaponWithLowClipAmmo) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Requirements== | ==Requirements== | ||
{{Requirements|n/a|1.3.0-9.04555|}} | {{Requirements|n/a|1.3.0-9.04555|}} | ||
==See | |||
==See also== | |||
{{Weapon functions}} | {{Weapon functions}} |
Revision as of 17:22, 23 December 2014
This function sets the ammo left in a custom weapon's magazine/clip.
Syntax
bool setWeaponClipAmmo ( weapon theWeapon, int clipAmmo )
Required Arguments
- theWeapon: The weapon to set the clip ammo of.
- clipAmmo: The amount of ammo in the clip.
Returns
This function returns true if the arguments are valid and the weapon clip ammo could be changed; fañse otherwise.
Example
This example adds a /weapon command that creates a M4 where the player uses it, and gives 1 clip ammo to it.
function createWeaponWithLowClipAmmo() local wep = createWeapon("m4", getElementPosition(localPlayer)) setWeaponClipAmmo(wep, 1) -- Give the weapon 1 clip ammo, so it will reload at the next shoot. end addCommandHandler("weapon", createWeaponWithLowClipAmmo)
Requirements
This template will be deleted.
See also
- getWeaponProperty
- getPickupWeapon
- getOriginalWeaponProperty
- getSlotFromWeapon
- getWeaponIDFromName
- getWeaponNameFromID
- setWeaponAmmo
- setWeaponProperty