04-28-2015, 12:08 AM
Expanded version of safeAddLoadout. Can name the variable, allowing more than one use, can pick execVM or execFSM with an optional argument, default is call compile preprocess.
Use as function recommended.
Use as function recommended.
Code:
/*
Execute script in init field only once.
Example:
[this, "loadouts\loadout.sqf","OTL7_loadout_handled"] call OTL7_fnc_oneTimeInit;
[this, "loadouts\loadout.sqf","OTL7_loadout_handled",1] call OTL7_fnc_oneTimeInit;
*/
_unit = _this select 0;
_scriptName = _this select 1;
_customVariable = _this select 2;
_howToExec = if (count _this > 3) then {_this select 3} else {0};
if (!local _unit) exitWith {};
_isHandled = _unit getVariable _customVariable;
 Â
if (isNil "_isHandled") then {Â Â
 _unit setVariable [_customVariable, true, true];
 switch (_howToExec ) do {
   case 0: { _unit call compile preprocessFileLineNumbers _scriptName };
     case 1: { _unit execVM _scriptName };
     case 2: { _unit execFSM _scriptName };
     default { ["Error: 4th argument must be 0,1 or 2. (%1)",_howToExec] call BIS_fnc_error; };
 };
};