Skip to content

Instantly share code, notes, and snippets.

@veteran29
Last active January 2, 2024 14:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veteran29/cdff6bc1d43378eff0b96bd332ca4324 to your computer and use it in GitHub Desktop.
Save veteran29/cdff6bc1d43378eff0b96bd332ca4324 to your computer and use it in GitHub Desktop.
Code examples on how to customize S.O.G. Prairie Fire Tracker area module behaviour
/*
This script shows example usage of vet_fnc_onTrackerSpawn to customize the loadouts of spawned groups.
vet_trackerLoadoutsHash - hash map of tracker type and parameters for setUnitLoadout
vet_fnc_customizeTrackerLoadout - function that randomly assigns loadouts to the group units depending on type of the tracker group
*/
vet_trackerLoadoutsHash = createHashMapFromArray [
["sentry", ["vn_o_men_vc_local_01", "vn_o_men_vc_local_02"]],
["stalker", ["vn_o_men_vc_local_01", "vn_o_men_vc_local_02"]],
["patrol", ["vn_o_men_vc_regional_01", "vn_o_men_vc_regional_02"]],
["avalanche", ["vn_o_men_vc_08", "vn_o_men_vc_09"]]
];
vet_fnc_customizeTrackerLoadout = {
params [["_group", grpNull, [grpNull]]];
systemChat str ["Changing loadout of", _group];
private _groupType = _group getVariable ["vn_type", ""];
private _loadouts = vet_trackerLoadoutsHash getOrDefault [_groupType, []];
if (_loadouts isEqualTo []) exitWith {
diag_log text format ["Could not get loadouts for group %1 of type %2", _group, _groupType];
};
{
_x setUnitLoadout selectRandom _loadouts;
} forEach units _group;
};
[my_trackerModule1, vet_fnc_customizeTrackerLoadout] spawn vet_fnc_onTrackerSpawn;
[my_trackerModule2, vet_fnc_customizeTrackerLoadout] spawn vet_fnc_onTrackerSpawn;
/*
Author: veteran29
Description:
Execute custom callback on groups spawned by the Tracker Area module.
Parameter(s):
_module - Tracker Area module [OBJECT]
_fnc_callback - Function to execute on newly created groups, arguments passed to the callback are: [_group, _module] [CODE]
_interval - How often to check for new groups [NUMBER, defaults to 3]
*/
vet_fnc_onTrackerSpawn = {
if (!canSuspend) exitWith {_this spawn vet_fnc_onTrackerSpawn};
waitUntil {missionNamespace getVariable ["BIS_fnc_init", false]};
params [
["_module", objNull, [objNull]],
["_fnc_callback", {}, [{}]],
["_interval", 3, [0]]
];
private _fsmId = _module getVariable ["vn_fsm", -1];
if (_fsmId == -1) exitWith {
diag_log text format ["Could not get Tracker FSM from module: %1", _module];
};
private _handledGroups = [];
private _fsmGroups = [];
while {true} do {
waitUntil {
sleep _interval;
// last element always contains all Overlord managed groups
_fsmGroups = _fsmId call vn_ms_fnc_tracker_overlord_getGroups;
reverse _fsmGroups;
_fsmGroups = _fsmGroups select 0;
_handledGroups isNotEqualTo _fsmGroups
};
private _newGroups = _fsmGroups - _handledGroups;
_handledGroups = _fsmGroups;
{[_x, _module] call _fnc_callback} foreach _newGroups;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment