From 7d9099593145fffcfeeae3660736c766528d01d1 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Mon, 2 May 2016 13:18:24 -0500 Subject: [PATCH 1/4] Add "initRetro" event to addClassEventHandler Runs init code on all current and future objects --- addons/xeh/fnc_addClassEventHandler.sqf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons/xeh/fnc_addClassEventHandler.sqf b/addons/xeh/fnc_addClassEventHandler.sqf index a59e750b1..140ab1568 100644 --- a/addons/xeh/fnc_addClassEventHandler.sqf +++ b/addons/xeh/fnc_addClassEventHandler.sqf @@ -38,6 +38,13 @@ if (!GVAR(fallbackRunning) && {ISINCOMP(_className)}) then { // no such CfgVehicles class if (!isClass _config) exitWith {false}; +//Handle initReto event type: +private _runRetroactiveInit = false; +if (_eventName == "initRetro") then { + _runRetroactiveInit = true; + _eventName = "init"; +}; + _eventName = toLower _eventName; // no such event @@ -61,6 +68,11 @@ private _eventVarName = format [QGVAR(%1), _eventName]; }; (_unit getVariable _eventVarName) pushBack _eventFunc; + + //Run initReto now if the unit has already been initialized + if (_runRetroactiveInit && {ISINITIALIZED(_unit)}) then { + [_unit] call _eventFunc; + }; }; }; } forEach (_entities arrayIntersect _entities); // filter duplicates From f3cf6ab1f2ffa7fe77aa9ddb9fea520b84b7239f Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 10 May 2016 10:29:21 -0500 Subject: [PATCH 2/4] Change initRetro event to be an optional parameter --- addons/xeh/fnc_addClassEventHandler.sqf | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/addons/xeh/fnc_addClassEventHandler.sqf b/addons/xeh/fnc_addClassEventHandler.sqf index 140ab1568..751b27c45 100644 --- a/addons/xeh/fnc_addClassEventHandler.sqf +++ b/addons/xeh/fnc_addClassEventHandler.sqf @@ -10,6 +10,7 @@ Parameters: 2: _eventFunc - Function to execute when event happens. 3: _allowInheritance - Allow event for objects that only inherit from the given classname? [optional] (default: true) 4: _excludedClasses - Exclude these classes from this event including their children [optional] (default: []) + 5: _applyInitRetroactivly - Apply "init" event type on existing units that have already been initilized. [optional] ((default: false) Returns: _success - Whether adding the event was successful or not. @@ -18,6 +19,7 @@ Examples: (begin example) ["CAManBase", "fired", {systemChat str _this}] call CBA_fnc_addClassEventHandler; ["All", "init", {systemChat str _this}] call CBA_fnc_addClassEventHandler; + ["Car", "init", {(_this select 0) engineOn true}, true, [], true] call CBA_fnc_addClassEventHandler; //Starts all current cars and those created later (end) Author: @@ -25,7 +27,7 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" -params [["_className", "", [""]], ["_eventName", "", [""]], ["_eventFunc", {}, [{}]], ["_allowInheritance", true, [false]], ["_excludedClasses", [], [[]]]]; +params [["_className", "", [""]], ["_eventName", "", [""]], ["_eventFunc", {}, [{}]], ["_allowInheritance", true, [false]], ["_excludedClasses", [], [[]]], ["_applyInitRetroactivly", false, [false]]]; private _config = configFile >> "CfgVehicles" >> _className; @@ -38,13 +40,6 @@ if (!GVAR(fallbackRunning) && {ISINCOMP(_className)}) then { // no such CfgVehicles class if (!isClass _config) exitWith {false}; -//Handle initReto event type: -private _runRetroactiveInit = false; -if (_eventName == "initRetro") then { - _runRetroactiveInit = true; - _eventName = "init"; -}; - _eventName = toLower _eventName; // no such event @@ -70,7 +65,7 @@ private _eventVarName = format [QGVAR(%1), _eventName]; (_unit getVariable _eventVarName) pushBack _eventFunc; //Run initReto now if the unit has already been initialized - if (_runRetroactiveInit && {ISINITIALIZED(_unit)}) then { + if (_applyInitRetroactivly && {ISINITIALIZED(_unit)}) then { [_unit] call _eventFunc; }; }; From e0821927c31c7d3d497035333ecb7b00ae9bfaa3 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 10 May 2016 20:20:58 +0200 Subject: [PATCH 3/4] don't use 'apply retroactively' for non init events --- addons/xeh/fnc_addClassEventHandler.sqf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/xeh/fnc_addClassEventHandler.sqf b/addons/xeh/fnc_addClassEventHandler.sqf index 751b27c45..9faf63989 100644 --- a/addons/xeh/fnc_addClassEventHandler.sqf +++ b/addons/xeh/fnc_addClassEventHandler.sqf @@ -49,6 +49,11 @@ if (_eventName == "FiredBIS") exitWith { }; if !(_eventName in GVAR(EventsLowercase)) exitWith {false}; +// don't use "apply retroactively" for non init events +if (_applyInitRetroactivly && {!(_eventName in ["init", "initpost"])}) then { + _applyInitRetroactivly = false; +}; + // add events to already existing objects private _entities = entities "" + allUnits; private _eventVarName = format [QGVAR(%1), _eventName]; From c30ee09807b68a0514ecae8354381581bbc0bc66 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 10 May 2016 13:44:30 -0500 Subject: [PATCH 4/4] Fix spelling --- addons/xeh/fnc_addClassEventHandler.sqf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/xeh/fnc_addClassEventHandler.sqf b/addons/xeh/fnc_addClassEventHandler.sqf index 9faf63989..50e905543 100644 --- a/addons/xeh/fnc_addClassEventHandler.sqf +++ b/addons/xeh/fnc_addClassEventHandler.sqf @@ -10,7 +10,7 @@ Parameters: 2: _eventFunc - Function to execute when event happens. 3: _allowInheritance - Allow event for objects that only inherit from the given classname? [optional] (default: true) 4: _excludedClasses - Exclude these classes from this event including their children [optional] (default: []) - 5: _applyInitRetroactivly - Apply "init" event type on existing units that have already been initilized. [optional] ((default: false) + 5: _applyInitRetroactively - Apply "init" event type on existing units that have already been initilized. [optional] ((default: false) Returns: _success - Whether adding the event was successful or not. @@ -27,7 +27,7 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" -params [["_className", "", [""]], ["_eventName", "", [""]], ["_eventFunc", {}, [{}]], ["_allowInheritance", true, [false]], ["_excludedClasses", [], [[]]], ["_applyInitRetroactivly", false, [false]]]; +params [["_className", "", [""]], ["_eventName", "", [""]], ["_eventFunc", {}, [{}]], ["_allowInheritance", true, [false]], ["_excludedClasses", [], [[]]], ["_applyInitRetroactively", false, [false]]]; private _config = configFile >> "CfgVehicles" >> _className; @@ -50,8 +50,8 @@ if (_eventName == "FiredBIS") exitWith { if !(_eventName in GVAR(EventsLowercase)) exitWith {false}; // don't use "apply retroactively" for non init events -if (_applyInitRetroactivly && {!(_eventName in ["init", "initpost"])}) then { - _applyInitRetroactivly = false; +if (_applyInitRetroactively && {!(_eventName in ["init", "initpost"])}) then { + _applyInitRetroactively = false; }; // add events to already existing objects @@ -70,7 +70,7 @@ private _eventVarName = format [QGVAR(%1), _eventName]; (_unit getVariable _eventVarName) pushBack _eventFunc; //Run initReto now if the unit has already been initialized - if (_applyInitRetroactivly && {ISINITIALIZED(_unit)}) then { + if (_applyInitRetroactively && {ISINITIALIZED(_unit)}) then { [_unit] call _eventFunc; }; };