SetWeaponClipAmmo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(/* Example)
(Remove obsolete Requirements section)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
{{Needs_Example}}
This function sets the ammo left in a [[Element/Weapon|custom weapon]]'s magazine/clip.
Set the ammo in a custom weapons magazine/clip.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool setWeaponClipAmmo ( weapon theWeapon, int clipAmmo )</syntaxhighlight>
<syntaxhighlight lang="lua">bool setWeaponClipAmmo ( weapon theWeapon, int clipAmmo )</syntaxhighlight>
{{OOP||[[Element/Weapon|weapon]]:setClipAmmo|clipAmmo|getWeaponClipAmmo}}


===Required Arguments===
===Required Arguments===
* '''theWeapon:''' The 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.


===Returns===
===Returns===
Returns ''true'' on success, ''false'' otherwise.
This function returns ''true'' if the arguments are valid and the weapon clip ammo could be changed; ''false'' otherwise.


==Example==
==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 onResourceStart()
function createWeaponWithLowClipAmmo()
setWeaponClipAmmo(thePlayer,31,30) -''This set M4 clip capacity from 50 to 30.''
local wep = createWeapon("m4", getElementPosition(localPlayer))
setWeaponClipAmmo(wep, 1) -- Give the weapon 1 clip ammo, so it will reload at the next shoot.
end
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onResourceStart)
addCommandHandler("weapon", createWeaponWithLowClipAmmo)
</syntaxhighlight>
</syntaxhighlight>


==Requirements==
==See also==
{{Requirements|n/a|1.3.0-9.04555|}}
 
==See Also==
{{Client weapon creation functions}}
{{Client weapon creation functions}}

Latest revision as of 17:06, 7 November 2024

This function sets the ammo left in a custom weapon's magazine/clip.

Syntax

bool setWeaponClipAmmo ( weapon theWeapon, int clipAmmo )

OOP Syntax Help! I don't understand this!

Method: weapon:setClipAmmo(...)
Variable: .clipAmmo
Counterpart: getWeaponClipAmmo


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; false 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)

See also