Example Code: Remove NVGs From Enemies: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\{\{ArgTitle *\| *([^\|]+) *\| *([1-6]) *\|" to "{{ArgTitle|$2|$1|")
m (Some wiki formatting)
Line 6: Line 6:
}}
}}


[[private]] _enemySide = [[opfor]]; {{cc|definition of the enemy side}}
<sqf>
[[private]] _enemies = [[allUnits]] [[select]] { [[side]] [[Magic Variables#x|_x]] == _enemySide; }; {{cc|selection of all enemy units ''from'' allUnits}}
private _enemySide = opfor; // definition of the enemy side
{
private _enemies = allUnits select { side _x == _enemySide; }; // selection of all enemy units from allUnits
[[Magic Variables#x|_x]] [[unlinkItem]] [[hmd]] [[Magic Variables#x|_x]]; {{cc|removal of each unit's [[hmd]]}}
{
} [[forEach]] _enemies; {{cc|code is to be executed for each enemy}}
_x unlinkItem hmd _x; // removal of each unit's hmd
} forEach _enemies; // code is to be executed for each enemy
</sqf>




Line 18: Line 20:
}}
}}


[[private]] "_enemySide"; {{cc|private definition of the _enemySide variable}}
<sqf>
_enemySide = [[east]]; {{cc|value attribution to _enemySide}}
private "_enemySide"; // private definition of the _enemySide variable
{
_enemySide = east; // value attribution to _enemySide
if ([[side]] [[Magic Variables#x|_x]] == _enemySide) [[then]] {{cc|if the unit is on the _enemySide, process the next step}}
{
{
if (side _x == _enemySide) then // if the unit is on the _enemySide, process the next step
[[Magic Variables#x|_x]] [[removeWeapon]] "NVGoggles"; {{cc|removal of the enemy unit's NVG}}
{
}
_x removeWeapon "NVGoggles"; // removal of the enemy unit's NVG
} [[forEach]] [[allUnits]]; {{cc|going through ''all'' units}}
}
} forEach allUnits; // going through -all- units
</sqf>




Line 32: Line 36:
* [[SQF Syntax]] has been introduced in {{GVI|ofpr|1.85}}
* [[SQF Syntax]] has been introduced in {{GVI|ofpr|1.85}}
}}
}}
[[private]] "_enemySide"; {{cc|private definition of the _enemySide variable}}
 
_enemySide = [[east]]; {{cc|value attribution to _enemySide}}
<sqf>
{
private "_enemySide"; // private definition of the _enemySide variable
if ([[side]] [[Magic Variables#x|_x]] == _enemySide) [[then]] {{cc|if the unit is on the _enemySide, process the next step}}
_enemySide = east; // value attribution to _enemySide
{
{
[[Magic Variables#x|_x]] [[removeWeapon]] "NVGoggles"; {{cc|removal of the enemy unit's NVG}}
if (side _x == _enemySide) then // if the unit is on the _enemySide, process the next step
}
{
} [[forEach]] ''_unitsArray''; {{cc|going through ''provided'' units - [[allUnits]] has been introduced in {{arma2}}}}
_x removeWeapon "NVGoggles"; // removal of the enemy unit's NVG
}
} forEach _unitsArray; // going through provided units - allUnits has been introduced in Arma 2
</sqf>





Revision as of 19:47, 2 April 2022

Arma 3

private _enemySide = opfor; // definition of the enemy side private _enemies = allUnits select { side _x == _enemySide; }; // selection of all enemy units from allUnits { _x unlinkItem hmd _x; // removal of each unit's hmd } forEach _enemies; // code is to be executed for each enemy


Arma 2

private "_enemySide"; // private definition of the _enemySide variable _enemySide = east; // value attribution to _enemySide { if (side _x == _enemySide) then // if the unit is on the _enemySide, process the next step { _x removeWeapon "NVGoggles"; // removal of the enemy unit's NVG } } forEach allUnits; // going through -all- units


Armed Assault / Operation Flashpoint: Resistance

private "_enemySide"; // private definition of the _enemySide variable _enemySide = east; // value attribution to _enemySide { if (side _x == _enemySide) then // if the unit is on the _enemySide, process the next step { _x removeWeapon "NVGoggles"; // removal of the enemy unit's NVG } } forEach _unitsArray; // going through provided units - allUnits has been introduced in Arma 2


Operation Flashpoint

This is an SQS Syntax example.
// remove its NVG for each provided enemy units
"_x removeWeapon ""NVGoggles""" forEach _enemyUnitsArray