GetWeaponClipAmmo: Difference between revisions
Jump to navigation
Jump to search
(Added OOP syntax and improved example (using a table to store a single value makes no sense)) |
mNo edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 16: | Line 16: | ||
This function outputs the remaining ammo in clip of a specific weapon using the command ''/getammoinclip''. | This function outputs the remaining ammo in clip of a specific weapon using the command ''/getammoinclip''. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local customWeapon | local customWeapon | ||
Line 31: | Line 30: | ||
function getM4WeaponAmmo() | function getM4WeaponAmmo() | ||
-- Tell the player the remaining ammo in clip | if customWeapon then | ||
-- Tell the player the remaining ammo in clip | |||
outputChatBox(getWeaponClipAmmo(customWeapon)) | |||
else | |||
-- Weapon was not created, give an error | |||
outputChatBox("There is no weapon to get clip ammo of.") | |||
end | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 21:44, 7 May 2017
This function gets the amount of ammo left in a custom weapon's magazine/clip.
Syntax
int getWeaponClipAmmo ( weapon theWeapon )
OOP Syntax Help! I don't understand this!
- Method: weapon:getClipAmmo(...)
- Variable: .clipAmmo
- Counterpart: setWeaponClipAmmo
Required Arguments
- theWeapon: the weapon to get the clip ammo of.
Returns
Returns the amount of ammo in the custom weapon's clip, false if an error occured.
Example
This function outputs the remaining ammo in clip of a specific weapon using the command /getammoinclip.
local customWeapon addEventHandler( "onClientResourceStart", resourceRoot, function() local x, y, z = getElementPosition(localPlayer) -- Get player position customWeapon = createWeapon("m4", x, y, z + 1) -- Create a M4 setWeaponClipAmmo(customWeapon, 99999) -- Set the ammo in clip of the weapon to 99999, so it never should reload setWeaponState(customWeapon, "firing") -- Fire it permanently -- Add the 'getammoinclip' command to get the remaining ammo in clip of the weapon addCommandHandler("getammoinclip", getM4WeaponAmmo) end ) function getM4WeaponAmmo() if customWeapon then -- Tell the player the remaining ammo in clip outputChatBox(getWeaponClipAmmo(customWeapon)) else -- Weapon was not created, give an error outputChatBox("There is no weapon to get clip ammo of.") end end
See also
- createWeapon
- fireWeapon
- getWeaponAmmo
- getWeaponClipAmmo
- getWeaponFiringRate
- getWeaponFlags
- getWeaponOwner
- getWeaponProperty
- getWeaponState
- getWeaponTarget
- resetWeaponFiringRate
- setWeaponAmmo
- setWeaponClipAmmo
- setWeaponFiringRate
- setWeaponFlags
- setWeaponProperty
- setWeaponState
- setWeaponTarget