setAmmo: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Replaced <code> with <sqf>)
m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(3 intermediate revisions by the same user not shown)
Line 16: Line 16:
|s1= unit [[setAmmo]] [weaponOrMuzzle, count]
|s1= unit [[setAmmo]] [weaponOrMuzzle, count]


|p1= unit: [[Object]] - Gunner or vehicle.
|p1= unit: [[Object]] - gunner or vehicle.


|p2= weaponOrMuzzle: [[String]] - Weapon name. Muzzle name in case the weapon has more than one muzzle, e.g. weapon with grenade launcher. See [[:Category:Weapons|CfgWeapons]] for muzzle names
|p2= weaponOrMuzzle: [[String]] - weapon name. Muzzle name in case the weapon has more than one muzzle, e.g. weapon with grenade launcher. See [[:Category:Weapons|CfgWeapons]] for muzzle names


|p3= count: [[Number]]
|p3= count: [[Number]]
Line 31: Line 31:


|x3= If player is a gunner in a vehicle, set current weapon magazine ammo count to 5 rounds:
|x3= If player is a gunner in a vehicle, set current weapon magazine ammo count to 5 rounds:
<sqf>if (local vehicle player) then {
<sqf>
if (local vehicle player) then {
vehicle player setAmmo [currentWeapon vehicle player, 5];
vehicle player setAmmo [currentWeapon vehicle player, 5];
} else {
} else {
hint "Vehicle must be local to this machine for 'setAmmo' to work";
hint "Vehicle must be local to this machine for 'setAmmo' to work";
};</sqf>
};
</sqf>


|x4= If you try to set more ammo than the magazine can hold, it will be clipped at default magazine capacity:
|x4= If you try to set more ammo than the magazine can hold, it will be clipped at default magazine capacity:
Line 41: Line 43:


|x5= Some weapons has more than one muzzles:
|x5= Some weapons has more than one muzzles:
<sqf>_marshall setAmmo ["autocannon_40mm_CTWS", 0];// won't work
<sqf>
_marshall setAmmo ["HE", 0];// works</sqf>
_marshall setAmmo ["autocannon_40mm_CTWS", 0];// won't work
_marshall setAmmo ["HE", 0];// works
</sqf>


|seealso= [[ammo]] [[setVehicleAmmo]] [[setFuel]] [[setHit]]
|seealso= [[ammo]] [[setVehicleAmmo]] [[setFuel]] [[setHit]]
}}
}}

Latest revision as of 19:42, 3 September 2024

Hover & click on the images for description

Description

Description:
Sets custom ammo count in the currently loaded magazine of the specified weapon or muzzle.
Groups:
Unit InventoryVehicle Inventory

Syntax

Syntax:
unit setAmmo [weaponOrMuzzle, count]
Parameters:
unit: Object - gunner or vehicle.
weaponOrMuzzle: String - weapon name. Muzzle name in case the weapon has more than one muzzle, e.g. weapon with grenade launcher. See CfgWeapons for muzzle names
count: Number
Return Value:
Nothing

Examples

Example 1:
Set player's handgun magazine ammo count to 10 rounds:
player setAmmo [handgunWeapon player, 10];
Example 2:
Set player's current weapon magazine ammo count to 1 round:
Example 3:
If player is a gunner in a vehicle, set current weapon magazine ammo count to 5 rounds:
if (local vehicle player) then { vehicle player setAmmo [currentWeapon vehicle player, 5]; } else { hint "Vehicle must be local to this machine for 'setAmmo' to work"; };
Example 4:
If you try to set more ammo than the magazine can hold, it will be clipped at default magazine capacity:
player setAmmo [primaryWeapon player, 1000000]; // full mag with default ammo count
Example 5:
Some weapons has more than one muzzles:
_marshall setAmmo ["autocannon_40mm_CTWS", 0];// won't work _marshall setAmmo ["HE", 0];// works

Additional Information

See also:
ammo setVehicleAmmo setFuel setHit

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note