GetWeaponClipAmmo: Difference between revisions
Jump to navigation
Jump to search
(The code is client-side only, so outputChatBox haven't visibleTo argument.) |
(This function works only for custom weapons!) |
||
Line 13: | Line 13: | ||
===Example=== | ===Example=== | ||
This | This function outputs the remaining ammo in clip of a specific weapon using the command 'getammoinclip'. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
[lua] | [lua] | ||
function | customWeapon = {} | ||
addEventHandler( "onClientResourceStart", resourceRoot, | |||
function() | |||
end | local x, y, z = getElementPosition(localPlayer) -- Get the player's position. | ||
customWeapon.M4 = createWeapon("m4", x, y, z + 1) -- Create a M4 weapon | |||
setWeaponClipAmmo(customWeapon.M4, 99999) -- Set the ammo in clip of the weapon to 99999 | |||
setWeaponState(customWeapon.M4, "firing") | |||
-- Add the 'getammoinclip' command to get the remaining ammo in clip of the weapon. | |||
addCommandHandler("getammoinclip", getM4WeaponAmmo) | |||
end | |||
) | |||
function getM4WeaponAmmo() | |||
-- Tell the player the remaining ammo in clip | |||
outputChatBox( tostring(getWeaponClipAmmo(customWeapon.M4)) ) | |||
end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Client weapon creation functions}} | {{Client weapon creation functions}} |
Revision as of 04:13, 15 October 2014
This function gets the amount of ammo in a custom weapons magazine/clip.
Syntax
int getWeaponClipAmmo ( weapon theWeapon )
Required Arguments
- theWeapon: the weapon to get the clip ammo of.
Returns
Returns the amount of ammo in the custom weapons clip, false otherwise.
Example
This function outputs the remaining ammo in clip of a specific weapon using the command 'getammoinclip'.
[lua] customWeapon = {} addEventHandler( "onClientResourceStart", resourceRoot, function() local x, y, z = getElementPosition(localPlayer) -- Get the player's position. customWeapon.M4 = createWeapon("m4", x, y, z + 1) -- Create a M4 weapon setWeaponClipAmmo(customWeapon.M4, 99999) -- Set the ammo in clip of the weapon to 99999 setWeaponState(customWeapon.M4, "firing") -- Add the 'getammoinclip' command to get the remaining ammo in clip of the weapon. addCommandHandler("getammoinclip", getM4WeaponAmmo) end ) function getM4WeaponAmmo() -- Tell the player the remaining ammo in clip outputChatBox( tostring(getWeaponClipAmmo(customWeapon.M4)) ) end
See Also
- createWeapon
- fireWeapon
- getWeaponAmmo
- getWeaponClipAmmo
- getWeaponFiringRate
- getWeaponFlags
- getWeaponOwner
- getWeaponProperty
- getWeaponState
- getWeaponTarget
- resetWeaponFiringRate
- setWeaponAmmo
- setWeaponClipAmmo
- setWeaponFiringRate
- setWeaponFlags
- setWeaponProperty
- setWeaponState
- setWeaponTarget