Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "initRetro" event to addClassEventHandler #324

Merged
merged 4 commits into from
May 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion addons/xeh/fnc_addClassEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Parameters:
2: _eventFunc - Function to execute when event happens. <CODE>
3: _allowInheritance - Allow event for objects that only inherit from the given classname? [optional] <BOOLEAN> (default: true)
4: _excludedClasses - Exclude these classes from this event including their children [optional] <ARRAY> (default: [])
5: _applyInitRetroactively - Apply "init" event type on existing units that have already been initilized. [optional] <BOOLEAN> ((default: false)
Returns:
_success - Whether adding the event was successful or not. <BOOLEAN>
Expand All @@ -18,14 +19,15 @@ 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:
commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"

params [["_className", "", [""]], ["_eventName", "", [""]], ["_eventFunc", {}, [{}]], ["_allowInheritance", true, [false]], ["_excludedClasses", [], [[]]]];
params [["_className", "", [""]], ["_eventName", "", [""]], ["_eventFunc", {}, [{}]], ["_allowInheritance", true, [false]], ["_excludedClasses", [], [[]]], ["_applyInitRetroactively", false, [false]]];

private _config = configFile >> "CfgVehicles" >> _className;

Expand All @@ -47,6 +49,11 @@ if (_eventName == "FiredBIS") exitWith {
};
if !(_eventName in GVAR(EventsLowercase)) exitWith {false};

// don't use "apply retroactively" for non init events
if (_applyInitRetroactively && {!(_eventName in ["init", "initpost"])}) then {
_applyInitRetroactively = false;
};

// add events to already existing objects
private _entities = entities "" + allUnits;
private _eventVarName = format [QGVAR(%1), _eventName];
Expand All @@ -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 (_applyInitRetroactively && {ISINITIALIZED(_unit)}) then {
[_unit] call _eventFunc;
};
};
};
} forEach (_entities arrayIntersect _entities); // filter duplicates
Expand Down