Files
Mission_Functions/fn_toggleLayerSim.sqf
T

43 lines
2.0 KiB
Plaintext

/*
Author:
Clarky
Last Updated:
06-05-2026
Description:
This function mimics the default functionality of the Show/Hide editor module, with the addition of allowing or disallowing damage.
Show/Hide does NOT toggle damage states on affected units, meaning you can hide a unit but it will still be affected by nearby explosions or vehicle collisions once un-hidden. Suboptimal for densely packed and layered instances where you may be hiding a number of different units/objects across different stages of an op.
This functionality can be applied to an entire layer of entities, making it easy to set up layers of units that will remain hidden, not simulating, and not processing any damage event until such a time as you are ready.
Paramters:
0: STRING - Name of the layer you wish to enable/disable
1: BOOLEAN - true = enable layer, false = disable layer
Returns:
BOOLEAN
Examples:
["Objective01-Assault", true] call TAG_fnc_toggleLayerSim;
*/
// Define variables. _layerName is the input parameter for the name of the layer, _show is the true/false value to turn the named layer on or off
params ["_layerName", "_show"];
// Import data based on provided parameters
private _layerEntities = getMissionLayerEntities _layerName;
private _objects = _layerEntities select 0;
private _allowDamage = _show;
private _enableSim = _show;
private _hideObj = !_show;
// Run the code based on provided input.
// First brackets input the current looped object (_x) and the toggle on/off for the relevant simulation requirement as set in the params
// The second bracket of params lists the desired variable to update based on the input (e.g allowDamage = _allowDamage, the locality of the remoteExec (0 = Server + Client), and if the call should be persistent or not (true = JIP users will also run this code, ensuring state parity)
{
[_x, _allowDamage] remoteExec ["allowDamage", 0, true];
[_x, _enableSim] remoteExec ["enableSimulationGlobal", 0, true];
[_x, _hideObj] remoteExec ["hideObjectGlobal", 0, true];
} forEach _objects;
true;