Jump to content
mcnools

skill + Loadout for units spawned in SOG:PF Tracker Module

Recommended Posts

EDIT: Updating my initial post with a probable solution.

 

Well, it seems I might have managed to solve it in the end. I "simply" mashed the scripts together and added the skill-level stuff into the loadout script and it seems to be working (might have faults that will appear later though). Figured I'd post it all here so it's available to anyone looking to do the same thing.  Big thanks to Larrow, couldn't have done it without you!

 

initserver.sqf

  Reveal hidden contents

//initServer.sqf
//include function

_handle = [] execVM "onTrackerSpawn.sqf";
_handle = [] execVM "customizeTrackerLoadout.sqf";

waitUntil{ scriptDone _handle };

//Tell the monitoring function the Module to monitor, the Function to call when new units are spawned by the module
[ Trackermodule1, vet_fnc_customizeTrackerLoadout] call vet_fnc_onTrackerSpawn;

 

onTrackerSpawn.sqf

  Reveal hidden contents

/*
    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};
    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;
    };
};

 

customizeTrackerLoadout.sqf (also sets the skill)

  Reveal hidden contents

/*
    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_nva_dc_01", "vn_o_men_nva_dc_02", "vn_o_men_nva_dc_03", "vn_o_men_nva_dc_04", "vn_o_men_nva_dc_05", "vn_o_men_nva_dc_06", "vn_o_men_nva_dc_08", "vn_o_men_nva_dc_09", "vn_o_men_nva_dc_10", "vn_o_men_nva_dc_11", "vn_o_men_nva_dc_13", "vn_o_men_nva_dc_14", "vn_o_men_nva_dc_18"]],
    ["stalker", ["vn_o_men_nva_dc_01", "vn_o_men_nva_dc_02", "vn_o_men_nva_dc_03", "vn_o_men_nva_dc_04", "vn_o_men_nva_dc_05", "vn_o_men_nva_dc_06", "vn_o_men_nva_dc_08", "vn_o_men_nva_dc_09", "vn_o_men_nva_dc_10", "vn_o_men_nva_dc_11", "vn_o_men_nva_dc_13", "vn_o_men_nva_dc_14", "vn_o_men_nva_dc_18"]],
    ["patrol", ["vn_o_men_nva_15", "vn_o_men_nva_16", "vn_o_men_nva_17", "vn_o_men_nva_18", "vn_o_men_nva_19", "vn_o_men_nva_20", "vn_o_men_nva_21", "vn_o_men_nva_22", "vn_o_men_nva_23", "vn_o_men_nva_24", "vn_o_men_nva_25", "vn_o_men_nva_26", "vn_o_men_nva_27", "vn_o_men_nva_28"]],
    ["avalanche", ["vn_o_men_nva_15", "vn_o_men_nva_16", "vn_o_men_nva_17", "vn_o_men_nva_18", "vn_o_men_nva_19", "vn_o_men_nva_20", "vn_o_men_nva_21", "vn_o_men_nva_22", "vn_o_men_nva_23", "vn_o_men_nva_24", "vn_o_men_nva_25", "vn_o_men_nva_26", "vn_o_men_nva_27", "vn_o_men_nva_28"]]
];

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;
	_x params[ "_unit" ];
	_unit setSkill 0.40;
    } forEach units _group;
};

[ Trackermodule1, vet_fnc_customizeTrackerLoadout] call vet_fnc_onTrackerSpawn;

 

 

 

 

ORIGINAL POST:
 

Spoiler


 

 

NEW PROBLEM:

Quote

So, of course I have to go complicate things now, I hope you can help out with this issue too. The skill-script works perfectly but now I also wanted to look into changing the loadout of the spawned groups using the script from the same page.

So, I went ahead and added the customizeTrackerLoadout.sqf  to my mission and then added _handle = [] execVM "customizeTrackerLoadout.sqf";  to my initserver.sqf. However, that seems to override the skill-level script so they spawn with the new loadouts I've given them but with max skill. Of course I have no idea why.

 

Currently my initserver sqf looks like this:

Spoiler



//initServer.sqf

//include function
_handle = [] execVM "onTrackerSpawn.sqf";
_handle = [] execVM "customizeTrackerLoadout.sqf";

waitUntil{ scriptDone _handle };

//Function to call when new units are spawned
TAG_fnc_setTrackerGroupSkill = {
	params[ "_group", "_module" ];
	
	{
		_x params[ "_unit" ];
		
		_unit setSkill 0.30;
	}forEach units _group;
};

//Tell the monitoring function the Module to monitor, the Function to call when new units are spawned by the module
[ TrackerModule1, TAG_fnc_setTrackerGroupSkill ] call vet_fnc_onTrackerSpawn;

 

 

customizeTrackerLoadout.sqf looks like this:

Spoiler



/*
    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_nva_dc_01", "vn_o_men_nva_dc_02", "vn_o_men_nva_dc_03", "vn_o_men_nva_dc_04", "vn_o_men_nva_dc_05", "vn_o_men_nva_dc_06", "vn_o_men_nva_dc_08", "vn_o_men_nva_dc_09", "vn_o_men_nva_dc_10", "vn_o_men_nva_dc_11", "vn_o_men_nva_dc_13", "vn_o_men_nva_dc_14", "vn_o_men_nva_dc_18"]],
    ["stalker", ["vn_o_men_nva_dc_01", "vn_o_men_nva_dc_02", "vn_o_men_nva_dc_03", "vn_o_men_nva_dc_04", "vn_o_men_nva_dc_05", "vn_o_men_nva_dc_06", "vn_o_men_nva_dc_08", "vn_o_men_nva_dc_09", "vn_o_men_nva_dc_10", "vn_o_men_nva_dc_11", "vn_o_men_nva_dc_13", "vn_o_men_nva_dc_14", "vn_o_men_nva_dc_18"]],
    ["patrol", ["vn_o_men_nva_15", "vn_o_men_nva_27", "vn_o_men_nva_23", "vn_o_men_nva_18", "vn_o_men_nva_19", "vn_o_men_nva_16", "vn_o_men_nva_17", "vn_o_men_nva_20", "vn_o_men_nva_22", "vn_o_men_nva_25", "vn_o_men_nva_28"]],
    ["avalanche", ["vn_o_men_nva_15", "vn_o_men_nva_27", "vn_o_men_nva_23", "vn_o_men_nva_18", "vn_o_men_nva_19", "vn_o_men_nva_16", "vn_o_men_nva_17", "vn_o_men_nva_20", "vn_o_men_nva_22", "vn_o_men_nva_25", "vn_o_men_nva_28"]]
];

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;
};


[Trackermodule1, vet_fnc_customizeTrackerLoadout] call vet_fnc_onTrackerSpawn;

 

 

and onTrackerSpawn.sqf looks like this:

Spoiler



/*
    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};
    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;
    };
};

 

 

OLD PROBLEM:

Quote

 

Hello, I'm making a SOG: Prairie Fire campaign for my group and I'm planning on using the tracker module for some missions where we operate behind enemy lines. Now the default skill level for units spawned in the module seems to be set to 100% which is probably too much for my group to handle, so I was hoping to be able to set it lower.  From what I've gathered it should be possible to modify this script and add a "handler" to it in order to set the skill of spawned units (the SetSkill command I suppose). However, I'm terrible at understanding scripting and I don't even understand what a handler is so I need some help. I also don't really understand where to put the onTrackerSpawn.sqf and activate it but that's a different story I suppose.

 

I would be really grateful if someone with more scripting experience could help me out here.

 

 

 


 

 

Edited by mcnools
Solved (hopefully)

Share this post


Link to post
Share on other sites
2 hours ago, mcnools said:

From what I've gathered it should be possible to modify this script and add a "handler" to it in order to set the skill of spawned units

No, you pass the tracker module and a function to the function defined in the onTrackerSpawn script(no modification needed).

vet_fnc_onTrackerSpawn then monitors the passed tracker module and when it spawns new units it calls the given function passing the function [ _groupSpawned, _moduleSpawnedFrom ].

So something like...

Spoiler

Place the onTrackerSpawn.sqf in your mission folder.


//initServer.sqf

//include function
_handle = [] execVM "onTrackerSpawn.sqf";

waitUntil{ scriptDone _handle };

//Function to call when new units are spawned
TAG_fnc_setTrackerGroupSkill = {
	params[ "_group", "_module" ];
	
	{
		_x params[ "_unit" ];
		
		_unit setSkill 0.5;
	}forEach units _group;
};

//Tell the monitoring function the Module to monitor, the Function to call when new units are spawned by the module
[ VarNameOfTrackerModule, TAG_fnc_setTrackerGroupSkill ] call vet_fnc_onTrackerSpawn;

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks for replying! I really appreciate you helping out man. I've tried it but it gives me this error message:

TnhR7Lk.jpg

 

I'm guessing for some reason it doesn't recognize the vet_fnc_onTrackerSpawn-command but I have no idea why. I've tested in both SP and MP (but not on a dedicated server) and it gives me the same error each time.

EDIT: if I include all the code from onTrackerSpawn.sqf in my initserver.sqf it seems to work fine, so I'm guessing the issue is that onTrackerSpawn.sqf isn't being included properly? Are there any downsides to having all the code in initserver.sqf or is it mostly just to keep things neat and tidy?

 

In my missions folder I have:

initServer.sqf

with the code:

//initServer.sqf

//include function
[] execVM "onTrackerSpawn.sqf";

//Function to call when new units are spawned
TAG_fnc_setTrackerGroupSkill = {
	params[ "_group", "_module" ];
	
	{
		_x params[ "_unit" ];
		
		_unit setSkill 0.5;
	}forEach units _group;
};

//Tell the monitoring function the Module to monitor, the Function to call when new units are spawned by the module
[ TrackerModule1, TAG_fnc_setTrackerGroupSkill ] call vet_fnc_onTrackerSpawn;

and onTrackerSpawn.sqf with the code:

/*
    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};
    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;
    };
};

 

Share this post


Link to post
Share on other sites

May just be a timing problem due to execVM scheduling the code and its not ready before function gets called.

See updated code in previous post.

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

That did the trick! Thank you so much, very much appreciated!

Share this post


Link to post
Share on other sites
19 hours ago, Larrow said:

May just be a timing problem due to execVM scheduling the code and its not ready before function gets called.

See updated code in previous post.

 

 

So, of course I have to go complicate things now, I hope you can help out with this issue too. The skill-script works perfectly but now I also wanted to look into changing the loadout of the spawned groups using the script from the same page.

So, I went ahead and added the customizeTrackerLoadout.sqf  to my mission and then added _handle = [] execVM "customizeTrackerLoadout.sqf";  to my initserver.sqf. However, that seems to override the skill-level script so they spawn with the new loadouts I've given them but with max skill. Of course I have no idea why.

 

Currently my initserver sqf looks like this:

Spoiler

//initServer.sqf

//include function
_handle = [] execVM "onTrackerSpawn.sqf";
_handle = [] execVM "customizeTrackerLoadout.sqf";

waitUntil{ scriptDone _handle };

//Function to call when new units are spawned
TAG_fnc_setTrackerGroupSkill = {
	params[ "_group", "_module" ];
	
	{
		_x params[ "_unit" ];
		
		_unit setSkill 0.30;
	}forEach units _group;
};

//Tell the monitoring function the Module to monitor, the Function to call when new units are spawned by the module
[ TrackerModule1, TAG_fnc_setTrackerGroupSkill ] call vet_fnc_onTrackerSpawn;

 

 

customizeTrackerLoadout.sqf looks like this:

Spoiler

/*
    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_nva_dc_01", "vn_o_men_nva_dc_02", "vn_o_men_nva_dc_03", "vn_o_men_nva_dc_04", "vn_o_men_nva_dc_05", "vn_o_men_nva_dc_06", "vn_o_men_nva_dc_08", "vn_o_men_nva_dc_09", "vn_o_men_nva_dc_10", "vn_o_men_nva_dc_11", "vn_o_men_nva_dc_13", "vn_o_men_nva_dc_14", "vn_o_men_nva_dc_18"]],
    ["stalker", ["vn_o_men_nva_dc_01", "vn_o_men_nva_dc_02", "vn_o_men_nva_dc_03", "vn_o_men_nva_dc_04", "vn_o_men_nva_dc_05", "vn_o_men_nva_dc_06", "vn_o_men_nva_dc_08", "vn_o_men_nva_dc_09", "vn_o_men_nva_dc_10", "vn_o_men_nva_dc_11", "vn_o_men_nva_dc_13", "vn_o_men_nva_dc_14", "vn_o_men_nva_dc_18"]],
    ["patrol", ["vn_o_men_nva_15", "vn_o_men_nva_27", "vn_o_men_nva_23", "vn_o_men_nva_18", "vn_o_men_nva_19", "vn_o_men_nva_16", "vn_o_men_nva_17", "vn_o_men_nva_20", "vn_o_men_nva_22", "vn_o_men_nva_25", "vn_o_men_nva_28"]],
    ["avalanche", ["vn_o_men_nva_15", "vn_o_men_nva_27", "vn_o_men_nva_23", "vn_o_men_nva_18", "vn_o_men_nva_19", "vn_o_men_nva_16", "vn_o_men_nva_17", "vn_o_men_nva_20", "vn_o_men_nva_22", "vn_o_men_nva_25", "vn_o_men_nva_28"]]
];

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;
};


[Trackermodule1, vet_fnc_customizeTrackerLoadout] call vet_fnc_onTrackerSpawn;

 

 

and onTrackerSpawn.sqf looks like this:

Spoiler

/*
    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};
    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;
    };
};

 

 

Share this post


Link to post
Share on other sites

?

Spoiler

//initServer.sqf

//include functions
call compileScript[ "onTrackerSpawn.sqf" ];
call compileScript[ "customizeTrackerLoadout.sqf" ];

//Function to call when new units are spawned
TAG_fnc_setTrackerGroupSkill = {
	params[ "_group", "_module" ];
	
	{
		_x params[ "_unit" ];
		_unit setSkill 0.30;
	}forEach units _group;
};

//Tell the monitoring function the Module to monitor, the Function to call when new units are spawned by the module
[ TrackerModule1, TAG_fnc_setTrackerGroupSkill ] call vet_fnc_onTrackerSpawn;

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Unfortunately it doesn't work. The loadouts are correct but the skill levels are 1.0 instead of 0.30 for some reason. Is something in the customizeTrackerLoadout.sqf overriding the other script somehow maybe?

Share this post


Link to post
Share on other sites
2 hours ago, mcnools said:

Is something in the customizeTrackerLoadout.sqf overriding the other script

I don't see how, the loadout just creates a function to call and calls onTrackerSpawn to create a while true waituntil loop to monitor the module. Much the same as you do in initServer for TAG_fnc_setTrackerGroupSkill.

Try this instead. Rewritten as one EH that handles all onTrackerSpawn callbacks, rather than filling up the scheduler with while true waituntil loops.

Spoiler

onTrackerSpawn.sqf


/*
    Author: veteran29
    Original Source: https://gist.github.com/veteran29/cdff6bc1d43378eff0b96bd332ca4324#file-customizetrackerloadout-sqf
    UpdatedBy: Larrow to handle multiple callbacks for a module https://forums.bohemia.net/forums/topic/240113-setting-skill-for-units-spawned-in-sogpf-tracker-module/
    Description:
        Execute custom callbacks on groups spawned by the Tracker Area module.
    Parameter(s):
        _module       - Tracker Area module [OBJECT]
        _fnc_callback - Function as STRING name 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 = {
	params [
		["_module", objNull, [objNull]],
		["_fnc_callback", "", [""]],
		["_interval", 3, [0]]
	];
	
	if ( isNull _module ) exitWith {
		"Module is null for vet_fnc_onTrackerSpawn" call BIS_fnc_error;
	};

	if ( _fnc_callback isEqualTo "" ) exitWith {
		"No callback given for vet_fnc_onTrackerSpawn" call BIS_fnc_error;
	};
	
	if ( isNil _fnc_callback || { !( missionNamespace getVariable _fnc_callback isEqualType {} ) } ) exitWith {
		format[ "Callback ( %1 ) given for vet_fnc_onTrackerSpawn is not code", _fnc_callback ] call BIS_fnc_error;
	};
	
	private _fsmId = _module getVariable ["vn_fsm", -1];
	if (_fsmId == -1) exitWith {
		format[ "Could not get Tracker FSM from module: %1", _module ] call BIS_fnc_error;
	};

	if ( isNil "vet_fnc_onTrackerSpawn_EH" ) then {
		vet_fnc_onTrackerSpawn_callbacks = [];
		vet_fnc_onTrackerSpawn_EH = addMissionEventHandler[ "EachFrame", {
			{
				_x params[ "_lastRun", "_interval", "_fsmID", "_module", "_fnc_callback", "_handledGroups" ];

				if ( _lastRun - time >= _interval ) then {
					// last element always contains all Overlord managed groups
					private _fsmGroups = _fsmId call vn_ms_fnc_tracker_overlord_getGroups;
					_fsmGroups = _fsmGroups select ( count _fsmGroups - 1 );
					
					if ( _handledGroups isNotEqualTo _fsmGroups ) then {
						vet_fnc_onTrackerSpawn_callbacks select _forEachIndex set[ 0, time ];
						private _newGroups = _fsmGroups - _handledGroups;
						{
							[ _x, _module ] call ( missionNamespace getVariable _fnc_callback );
						}forEach _newGroups;
						vet_fnc_onTrackerSpawn_callbacks select _forEachIndex set[ 5, _fsmGroups ];
					};
				};
			}forEach vet_fnc_onTrackerSpawn_callbacks;
		}];
	};
	
	vet_fnc_onTrackerSpawn_callbacks pushBack [ time, _interval, _fsmID, _module, _fnc_callback, [] ];
};

Change your calls to vet_fnc_onTrackerSpawn so the functions are the STRING name of the function. so...

initServer.sqf


//initServer.sqf

//include functions
call compileScript[ "onTrackerSpawn.sqf" ];
call compileScript[ "customizeTrackerLoadout.sqf" ];

//Function to call when new units are spawned
TAG_fnc_setTrackerGroupSkill = {
	params[ "_group", "_module" ];
	
	{
		_x params[ "_unit" ];
		_unit setSkill 0.30;
	}forEach units _group;
};

//Tell the monitoring function the Module to monitor, the Function to call when new units are spawned by the module
[ TrackerModule1, "TAG_fnc_setTrackerGroupSkill" ] call vet_fnc_onTrackerSpawn; //Function name as STRING

And the bottom of customizeTrackerLoadout.sqf change the call to...


[ Trackermodule1, "vet_fnc_customizeTrackerLoadout" ] call vet_fnc_onTrackerSpawn; //Function name as STRING

 

 

Notice that I have changed the _callback parameter for vet_fnc_onTrackerSpawn. It is now a STRING name of the function to call rather than the actual function variable.

I have not tested these changes, so let me know if you encounter errors.

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks for taking the time trying to help me, unfortunately once again it doesn't work, this time neither the loadouts nor the skill level seems to set correctly. Strangely enough I don't get any error messages at all.

If I change initserver.sqf to just init.sqf (just took a chance) I get the error message "Could not get tracker FSM from module TrackerModule1" though. Not sure if that can be a clue or if it's just because the script doesn't work properly in init.sqf.

Share this post


Link to post
Share on other sites

Is it just a timing issue maybe? Maybe the module and fsm are not initialised before the tracker function queries it.

Try putting...

waitUntil{
	getClientStateNumber >= 10 &&
	{ TrackerModule1 getVariable[ "bis_fnc_moduleInit_status", false ] }
};

... right at the top of your initServer.sqf

Otherwise, I'm out of ideas as I don't own SOG to be able to do any testing.

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Unfortunately that didn't help. You have my thanks for trying to help! The most important thing is the skill-level anyway, the rest is just cosmetics/details. I'll try asking around some more in the SOG Prairie Fire Discord and see if anyone can help out. Thank you again for helping!

Share this post


Link to post
Share on other sites

Well, it seems I might have managed to solve it in the end. I "simply" mashed the scripts together and added the skill-level stuff into the loadout script and it seems to be working (might have faults that will appear later though). Figured I'd post it all here so it's available to anyone looking to do the same thing.  Big thanks to Larrow, couldn't have done it without you!

 

initserver.sqf

Spoiler

//initServer.sqf
//include function

_handle = [] execVM "onTrackerSpawn.sqf";
_handle = [] execVM "customizeTrackerLoadout.sqf";

waitUntil{ scriptDone _handle };

//Tell the monitoring function the Module to monitor, the Function to call when new units are spawned by the module
[ Trackermodule1, vet_fnc_customizeTrackerLoadout] call vet_fnc_onTrackerSpawn;

 

onTrackerSpawn.sqf

Spoiler

/*
    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};
    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;
    };
};

 

customizeTrackerLoadout.sqf (also sets the skill)

Spoiler

/*
    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_nva_dc_01", "vn_o_men_nva_dc_02", "vn_o_men_nva_dc_03", "vn_o_men_nva_dc_04", "vn_o_men_nva_dc_05", "vn_o_men_nva_dc_06", "vn_o_men_nva_dc_08", "vn_o_men_nva_dc_09", "vn_o_men_nva_dc_10", "vn_o_men_nva_dc_11", "vn_o_men_nva_dc_13", "vn_o_men_nva_dc_14", "vn_o_men_nva_dc_18"]],
    ["stalker", ["vn_o_men_nva_dc_01", "vn_o_men_nva_dc_02", "vn_o_men_nva_dc_03", "vn_o_men_nva_dc_04", "vn_o_men_nva_dc_05", "vn_o_men_nva_dc_06", "vn_o_men_nva_dc_08", "vn_o_men_nva_dc_09", "vn_o_men_nva_dc_10", "vn_o_men_nva_dc_11", "vn_o_men_nva_dc_13", "vn_o_men_nva_dc_14", "vn_o_men_nva_dc_18"]],
    ["patrol", ["vn_o_men_nva_15", "vn_o_men_nva_16", "vn_o_men_nva_17", "vn_o_men_nva_18", "vn_o_men_nva_19", "vn_o_men_nva_20", "vn_o_men_nva_21", "vn_o_men_nva_22", "vn_o_men_nva_23", "vn_o_men_nva_24", "vn_o_men_nva_25", "vn_o_men_nva_26", "vn_o_men_nva_27", "vn_o_men_nva_28"]],
    ["avalanche", ["vn_o_men_nva_15", "vn_o_men_nva_16", "vn_o_men_nva_17", "vn_o_men_nva_18", "vn_o_men_nva_19", "vn_o_men_nva_20", "vn_o_men_nva_21", "vn_o_men_nva_22", "vn_o_men_nva_23", "vn_o_men_nva_24", "vn_o_men_nva_25", "vn_o_men_nva_26", "vn_o_men_nva_27", "vn_o_men_nva_28"]]
];

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;
	_x params[ "_unit" ];
	_unit setSkill 0.40;
    } forEach units _group;
};

[ Trackermodule1, vet_fnc_customizeTrackerLoadout] call vet_fnc_onTrackerSpawn;

 

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×