Jump to content
RoryRothon

foreach allPlayers - dedicated server

Recommended Posts

I currently have this.

It works fine on my local system under lan hosted session but when i upload it to my dedi, it does not....

Can someone see any mistakes ive made?

And yes i have done the server check in my sqf :)

 

{

		// Starting spawning RED units
		0 = [] spawn {

			for '_i' from 0 to 999999 do {

				_islamicState = [
					configfile >> "CfgGroups" >> "east" >> "LOP_ISTS_OPF" >> "Infantry" >> "LOP_ISTS_OPF_AT_section",
					configfile >> "CfgGroups" >> "east" >> "LOP_ISTS_OPF" >> "Infantry" >> "LOP_ISTS_OPF_Fireteam",
					configfile >> "CfgGroups" >> "east" >> "LOP_ISTS_OPF" >> "Infantry" >> "LOP_ISTS_OPF_InfSupTeam",
					configfile >> "CfgGroups" >> "east" >> "LOP_ISTS_OPF" >> "Infantry" >> "LOP_ISTS_OPF_Patrol_section",
					configfile >> "CfgGroups" >> "east" >> "LOP_ISTS_OPF" >> "Infantry" >> "LOP_ISTS_OPF_Rifle_squad",
					configfile >> "CfgGroups" >> "east" >> "LOP_ISTS_OPF" >> "Infantry" >> "LOP_ISTS_OPF_Support_section"
				];

				_spawnPos = [player, 500, (RANDOM 360)] call BIS_fnc_relPos;
				_spawnPos = [_spawnPos, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;
				_grp = [ _spawnPos, EAST, ( selectRandom _islamicState ) ] call BIS_fnc_spawnGroup;
				{ _x setskill 0.25; } forEach units _grp;
				_wp = _grp addWaypoint [position player, 0];
				[_grp, 1] setWaypointType "SAD";
				[_grp, 1] setWaypointSpeed "FULL";
				{ null = [_x] execVM "AL_searchlight\al_search_light_ini.sqf" } forEach units _grp;

				while {({alive _x} count units _grp) > 1} do {  
					sleep 120;
					deleteWaypoint [_grp, 1];
					_wp = _grp addWaypoint [position player, 1];
					[_grp, 1] setWaypointType "SAD";
					[_grp, 1] setWaypointSpeed "FULL";
				}; 

				waitUntil {({alive _x} count units _grp) < 1};
				deleteWaypoint [_grp, 1];
				deleteGroup _grp;

			};

		};

	} forEach playableUnits;

 

Share this post


Link to post
Share on other sites
33 minutes ago, shuko said:

Don't use the command player in dedi.

 

Is that the reason for it not working do you think?

Share this post


Link to post
Share on other sites
57 minutes ago, RoryRothon said:

Is that the reason for it not working do you think?

 

Absolutely.  On the server, player is defined as objNull.

 

Think of each of the clients and the server as separate boxes.  There is information in each of those boxes, and when you want to run a script in a given box, you can only use the information in that box.  Learning what information is available in each box, at what times, and under what circumstances is a critical part of writing multiplayer script for ARMA.

 

When you start a session through the editor, you get a client and a server running in the same box.  The client sets the value of player, so you can use it in your server code because they're in the same box. But that single box structure is not something you want to get used to because it's not how client/server applications work.  It's cheating.

 

When you start a session through a dedicated server, you get a server box.  There is no client box, so nobody sets the value of player.  Any server code that you run in the server box will look for player and get an objNull value.

 

That said, the server keeps track of all the players in a list called allPlayers.  You can use that to see which player objects have been created by various clients.  When nobody has connected, that variable has zero elements.  But it could have 1, 2, 10 or 100 elements, depending on how many clients are connected.

 

So the server doesn't think in terms of "the current player".  When you write script for the server that operates on a specific player, you have to somehow decide which player you want to operate on.  You could perform an action on all of the players by just going through every player in the allPlayers list.  You could also have a client tell your server to do something for its player via remoteExec. You can spot a player by virtue of something that it does.  For example, activate a trigger.  Then you'd have the player that activated the trigger and you could operate on that player.  You can spot a player through various events as well by setting up event handlers on the server (addEventHandler) on each player and acting when those events take place.

 

Make sure you understand the split between clients and server before attempting any multiplayer scripting.  It'll be a nightmare until you do.

  • Thanks 1

Share this post


Link to post
Share on other sites

In your code, try to modify:

0 = [] spawn {...

by:

this spawn { _plyr = _this;

 

then replace player by _plyr.

 

Note: use playableUnits + switchableUnits for an SP/MP context (if needed).

Share this post


Link to post
Share on other sites

This is what i have thus far, and it is still broken :(

Trying to learn dedi scripting is fun but hard lol

all wrapped in:

 

if (isServer) then {
//here
};

 

0 = [] spawn {

	_players = playableUnits + switchableUnits;

	waitUntil { count _players > 0 };

	if ( count _players > 0 ) then {

		{

			_player = _x;

			if (!isNull _player) then {

				_pos = getPosATL _player;

				for '_i' from 0 to 999999 do {

					_islamicState = [
						configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Patrol",
						configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Team",
						configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Support_Team",
						configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Detail",
						configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Specialists",
						configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_VIP_Bodyguard"
					];

					_spawnPos = [_pos, 200, (RANDOM 360)] call BIS_fnc_relPos;
					_spawnPos = [_spawnPos, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;
					_grp = [ _spawnPos, INDEPENDENT, ( selectRandom _islamicState ) ] call BIS_fnc_spawnGroup;
					{ _x setskill 0.25; } forEach units _grp;
					_wp = _grp addWaypoint [position _player, 0];
					[_grp, 1] setWaypointType "SAD";
					[_grp, 1] setWaypointSpeed "FULL";

					{ null = [_x] execVM "AL_searchlight\al_search_light_ini.sqf" } forEach units _grp;

					while {({alive _x} count units _grp) > 1} do {

						sleep 90;
						deleteWaypoint [_grp, 1];
						_wp = _grp addWaypoint [position _player, 1];
						[_grp, 1] setWaypointType "SAD";
						[_grp, 1] setWaypointSpeed "FULL";

					};

					waitUntil {({alive _x} count units _grp) < 1};
					deleteWaypoint [_grp, 1];
					deleteGroup _grp;

				};

			};

		} forEach _players;

	}

	else {};

};

 

Share this post


Link to post
Share on other sites

what do you mean by "broken" ? 

Errors in rpt ? No errors but working partially ? No errors but not working at all ? 

By the way you should put the variable "_islamicState " out of your foreach as it should always have the same value

Share this post


Link to post
Share on other sites
1 minute ago, xjoker_ said:

what do you mean by "broken" ? 

Errors in rpt ? No errors but working partially ? No errors but not working at all ? 

By the way you should put the variable "_islamicState " out of your foreach as it should always have the same value

 

I have no errors, works superbly on my LAN hosted session, but on my dedicated server the enemy do not spawn.

I have vehicles and choppers spawning fine, but im trying to spawn an enemy squad for each player that moves towards them....

Im getting quite frustrated with it lol

Share this post


Link to post
Share on other sites

Well, if you can't figure out what's wrong i guess you'll have to diag_log your variables and see which one hasn't the good value

Share this post


Link to post
Share on other sites
1 hour ago, RoryRothon said:

 

I have no errors, works superbly on my LAN hosted session, but on my dedicated server the enemy do not spawn.

I have vehicles and choppers spawning fine, but im trying to spawn an enemy squad for each player that moves towards them....

Im getting quite frustrated with it lol

 

Take a closer look at your code and how it is executed.

You define _players array which will never change once it's being defined.

Now you check for _players to hold more than zero players, due to the nature that _players remains static this will never change and you'll never leave the waitUntil loop.

The next if then statement is nonsensical too, since it will basically exit the entire spawn when false but due to the above you'll never make it that far.

The if isNull _player check doesn't make sense, since allPlayers will never hold null objects.

 

The for "_i" from 0 to 999999 loop will run for the first player inside the _players array only, not simultaneously for multiple players.

You also don't need to delete waypoints from groups before deleting the group. Waypoints get deleted with the group.

 

Perfect example of being in over your head, heh.

 

Try to make small portions of the script work, if this succeeds try to figure out how to either break it up into smaller functions for better readability or improve readability in the first place.

I broke up your snippet into multiple smaller portions, enhanced it to hold a separate group spawning function and only spawn hostile groups if the player currently isn't being already chased by one (if that's your intention).

Also added comments and removed the redundant else {} statement.

 

Feel free to ask if you got further questions:


//do this in initserver.sqf or wherever you call the script, no need to do this every time you spawn a group
TAG_fnc_groupTemplates = [

	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Patrol",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Support_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Detail",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Specialists",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_VIP_Bodyguard"

];


//do this in initserver.sqf or wherever you call the script
TAG_fnc_spawnHostileGroups = {

	params ["_unit"];
	_debug = false;

	_pos = getPosATL _unit;
	_unit setVariable ["TAG_fnc_isBeingHunted",true,true];

	_spawnPos = _pos getPos [200, random 360];
	_spawnPos = [_spawnPos, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;

	if (_debug) then {systemchat format ["Spawning enemies to hunt %1!",name _unit]};

	_grp = [ _spawnPos, INDEPENDENT, ( selectRandom TAG_fnc_groupTemplates ) ] call BIS_fnc_spawnGroup;

	_grp deleteGroupWhenEmpty true;//handles group deletion automatically

	{
		_x setskill 0.25;

	} forEach units _grp;

	_wp = _grp addWaypoint [position _unit, 0];
	[_grp, 1] setWaypointType "SAD";
	[_grp, 1] setWaypointSpeed "FULL";

	{

		_youCanNameThisWhateverthefuckyouwantItDoesntHaveToBeNullAllTheTimeForCryingOutLoud = [_x] execVM "AL_searchlight\al_search_light_ini.sqf"

	} forEach units _grp;

	while {({alive _x} count units _grp) >= 1} do {

		//sleep 90;//this sleep is bad since it can cause an unwanted delay between spawning groups, the delay will be handled later
		_timer = time + 10;
		waituntil {

			sleep 1;
			position _unit distance _spawnpos > 30 OR time > _timer OR ({alive _x} count units _grp) isEqualTo 0

		};

		deleteWaypoint [_grp, 1];
		_wp = _grp addWaypoint [position _unit, 1];
		[_grp, 1] setWaypointType "SAD";
		[_grp, 1] setWaypointSpeed "FULL";

	};

	if (_debug) then {systemchat format ["All units hunting %1 died!",name _unit]};

	//wait 1 second to allow spawning of new groups to hunt the player, adjust this to your liking
	sleep 1;
	_unit setVariable ["TAG_fnc_isBeingHunted",false,true];

};


_spawningEnemies = [] spawn {

	_debug = false;
	_players = [];
	TAG_fnc_spawnEnemies = true;

	if (_debug) then {systemchat "System Initialized"};

	//wait until the mission is running
	waitUntil {time > 0};

	if (_debug) then {systemchat "Mission Running"};

	while {TAG_fnc_spawnEnemies} do {

		if (_debug) then {systemchat "Loop Running"};

		//wait until there's players on the server
		waitUntil {

			if (_debug) then {systemchat "Waiting for players..."};
			sleep 3;
			 (count (allplayers - switchableUnits) > 0)

		};

		if (_debug) then {systemchat "Players detected!"};

		//will only select players that are not currently hunted
		_players = (allplayers - switchableUnits) select {!(_x getVariable ["TAG_fnc_isBeingHunted",false])};

		_players apply {_hunt = [_x] spawn TAG_fnc_spawnHostileGroups};

	};

};

 

Cheers

 

 

Share this post


Link to post
Share on other sites

Grumpy!

I can always rely on you to dig me out the sh*t!

As always, you rock....

I'll look into this cheers.

  • Like 1

Share this post


Link to post
Share on other sites
38 minutes ago, Grumpy Old Man said:

 

Take a closer look at your code and how it is executed.

You define _players array which will never change once it's being defined.

Now you check for _players to hold more than zero players, due to the nature that _players remains static this will never change and you'll never leave the waitUntil loop.

The next if then statement is nonsensical too, since it will basically exit the entire spawn when false but due to the above you'll never make it that far.

The if isNull _player check doesn't make sense, since allPlayers will never hold null objects.

 

The for "_i" from 0 to 999999 loop will run for the first player inside the _players array only, not simultaneously for multiple players.

You also don't need to delete waypoints from groups before deleting the group. Waypoints get deleted with the group.

 

Perfect example of being in over your head, heh.

 

Try to make small portions of the script work, if this succeeds try to figure out how to either break it up into smaller functions for better readability or improve readability in the first place.

I broke up your snippet into multiple smaller portions, enhanced it to hold a separate group spawning function and only spawn hostile groups if the player currently isn't being already chased by one (if that's your intention).

Also added comments and removed the redundant else {} statement.

 

Feel free to ask if you got further questions:



//do this in initserver.sqf or wherever you call the script, no need to do this every time you spawn a group
TAG_fnc_groupTemplates = [

	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Patrol",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Support_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Detail",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Specialists",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_VIP_Bodyguard"

];


//do this in initserver.sqf or wherever you call the script
TAG_fnc_spawnHostileGroups = {

	params ["_unit"];
	_debug = false;

	_pos = getPosATL _unit;
	_unit setVariable ["TAG_fnc_isBeingHunted",true,true];

	_spawnPos = _pos getPos [200, random 360];
	_spawnPos = [_spawnPos, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;

	if (_debug) then {systemchat format ["Spawning enemies to hunt %1!",name _unit]};

	_grp = [ _spawnPos, INDEPENDENT, ( selectRandom TAG_fnc_groupTemplates ) ] call BIS_fnc_spawnGroup;

	_grp deleteGroupWhenEmpty true;//handles group deletion automatically

	{
		_x setskill 0.25;

	} forEach units _grp;

	_wp = _grp addWaypoint [position _unit, 0];
	[_grp, 1] setWaypointType "SAD";
	[_grp, 1] setWaypointSpeed "FULL";

	{

		_youCanNameThisWhateverthefuckyouwantItDoesntHaveToBeNullAllTheTimeForCryingOutLoud = [_x] execVM "AL_searchlight\al_search_light_ini.sqf"

	} forEach units _grp;

	while {({alive _x} count units _grp) >= 1} do {

		//sleep 90;//this sleep is bad since it can cause an unwanted delay between spawning groups, the delay will be handled later
		_timer = time + 10;
		waituntil {

			sleep 1;
			position _unit distance _spawnpos > 30 OR time > _timer OR ({alive _x} count units _grp) isEqualTo 0

		};

		deleteWaypoint [_grp, 1];
		_wp = _grp addWaypoint [position _unit, 1];
		[_grp, 1] setWaypointType "SAD";
		[_grp, 1] setWaypointSpeed "FULL";

	};

	if (_debug) then {systemchat format ["All units hunting %1 died!",name _unit]};

	//wait 1 second to allow spawning of new groups to hunt the player, adjust this to your liking
	sleep 1;
	_unit setVariable ["TAG_fnc_isBeingHunted",false,true];

};


_spawningEnemies = [] spawn {

	_debug = false;
	_players = [];
	TAG_fnc_spawnEnemies = true;

	if (_debug) then {systemchat "System Initialized"};

	//wait until the mission is running
	waitUntil {time > 0};

	if (_debug) then {systemchat "Mission Running"};

	while {TAG_fnc_spawnEnemies} do {

		if (_debug) then {systemchat "Loop Running"};

		//wait until there's players on the server
		waitUntil {

			if (_debug) then {systemchat "Waiting for players..."};
			sleep 3;
			 (count (allplayers - switchableUnits) > 0)

		};

		if (_debug) then {systemchat "Players detected!"};

		//will only select players that are not currently hunted
		_players = (allplayers - switchableUnits) select {!(_x getVariable ["TAG_fnc_isBeingHunted",false])};

		_players apply {_hunt = [_x] spawn TAG_fnc_spawnHostileGroups};

	};

};

 

Cheers

 

 

That works nicely in testing locally.

My plan is to spawn 1 green and 1 red group to hunt down players.
Is there a semantic way to add in a red group too or would i need to replicate this with edits?

  • Like 1

Share this post


Link to post
Share on other sites

You could easily add the possibility to spawn multiple sides, just change the groupTemplate array to this:

TAG_fnc_groupTemplates = [

	[
	//east configs here
	],

	[
	//west configs here
	],

	[
	//indep configs here
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Patrol",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Support_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Detail",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Specialists",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_VIP_Bodyguard"
	]

];

Add east and west side group configs as seen in the comments.

Then replace the spawn group function with this:

TAG_fnc_spawnHostileGroups = {

	params ["_unit",["_side",independent]];//side will default to indep

	_debug = false;
	_sideID = _side call BIS_fnc_sideID;

	_pos = getPosATL _unit;
	_unit setVariable ["TAG_fnc_isBeingHunted",true,true];

	_spawnPos = _pos getPos [200, random 360];
	_spawnPos = [_spawnPos, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;

	if (_debug) then {systemchat format ["Spawning enemies to hunt %1!",name _unit]};

	_grp = [ _spawnPos, INDEPENDENT, ( selectRandom (TAG_fnc_groupTemplates select _sideID) ) ] call BIS_fnc_spawnGroup;

	_grp deleteGroupWhenEmpty true;//handles group deletion automatically

	{
		_x setskill 0.25;

	} forEach units _grp;

	_wp = _grp addWaypoint [position _unit, 0];
	[_grp, 1] setWaypointType "SAD";
	[_grp, 1] setWaypointSpeed "FULL";

	{

		_youCanNameThisWhateverthefuckyouwantItDoesntHaveToBeNullAllTheTimeForCryingOutLoud = [_x] execVM "AL_searchlight\al_search_light_ini.sqf"

	} forEach units _grp;

	while {({alive _x} count units _grp) >= 1} do {

		//sleep 90;//this sleep is bad since it can cause an unwanted delay between spawning groups, the delay will be handled later
		_timer = time + 10;
		waituntil {

			sleep 1;
			position _unit distance _spawnpos > 30 OR time > _timer OR ({alive _x} count units _grp) isEqualTo 0

		};

		deleteWaypoint [_grp, 1];
		_wp = _grp addWaypoint [position _unit, 1];
		[_grp, 1] setWaypointType "SAD";
		[_grp, 1] setWaypointSpeed "FULL";

	};

	if (_debug) then {systemchat format ["All units hunting %1 died!",name _unit]};

	//wait 1 second to allow spawning of new groups to hunt the player, adjust this to your liking
	sleep 1;
	_unit setVariable ["TAG_fnc_isBeingHunted",false,true];

};

Notice the additional input parameter.

You now call it like this:

_hunt = [_x,east] spawn TAG_fnc_spawnHostileGroups;

If no side input parameter is given it will default to independent.

Note that you need to modify the group templates or it won't work.

To round it up your spawn loop will look like this to spawn one independend and one east group hunting the player:


_spawningEnemies = [] spawn {

	_debug = false;
	_players = [];
	TAG_fnc_spawnEnemies = true;

	if (_debug) then {systemchat "System Initialized"};

	//wait until the mission is running
	waitUntil {time > 0};

	if (_debug) then {systemchat "Mission Running"};

	while {TAG_fnc_spawnEnemies} do {

		if (_debug) then {systemchat "Loop Running"};

		//wait until there's players on the server
		waitUntil {

			if (_debug) then {systemchat "Waiting for players..."};
			sleep 3;
			 (count (allplayers - switchableUnits) > 0)

		};

		if (_debug) then {systemchat "Players detected!"};

		//will only select players that are not currently hunted
		_players = (allplayers - switchableUnits) select {!(_x getVariable ["TAG_fnc_isBeingHunted",false])};

		_players apply {

			_hunt = [_x,independent] spawn TAG_fnc_spawnHostileGroups;
			_hunt = [_x,east] spawn TAG_fnc_spawnHostileGroups;

		};

	};

};

 

Cheers

Share this post


Link to post
Share on other sites
43 minutes ago, Grumpy Old Man said:

You could easily add the possibility to spawn multiple sides, just change the groupTemplate array to this:


TAG_fnc_groupTemplates = [

	[
	//east configs here
	],

	[
	//west configs here
	],

	[
	//indep configs here
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Patrol",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Support_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Detail",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Specialists",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_VIP_Bodyguard"
	]

];

Add east and west side group configs as seen in the comments.

Then replace the spawn group function with this:


TAG_fnc_spawnHostileGroups = {

	params ["_unit",["_side",independent]];//side will default to indep

	_debug = false;
	_sideID = _side call BIS_fnc_sideID;

	_pos = getPosATL _unit;
	_unit setVariable ["TAG_fnc_isBeingHunted",true,true];

	_spawnPos = _pos getPos [200, random 360];
	_spawnPos = [_spawnPos, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;

	if (_debug) then {systemchat format ["Spawning enemies to hunt %1!",name _unit]};

	_grp = [ _spawnPos, INDEPENDENT, ( selectRandom (TAG_fnc_groupTemplates select _sideID) ) ] call BIS_fnc_spawnGroup;

	_grp deleteGroupWhenEmpty true;//handles group deletion automatically

	{
		_x setskill 0.25;

	} forEach units _grp;

	_wp = _grp addWaypoint [position _unit, 0];
	[_grp, 1] setWaypointType "SAD";
	[_grp, 1] setWaypointSpeed "FULL";

	{

		_youCanNameThisWhateverthefuckyouwantItDoesntHaveToBeNullAllTheTimeForCryingOutLoud = [_x] execVM "AL_searchlight\al_search_light_ini.sqf"

	} forEach units _grp;

	while {({alive _x} count units _grp) >= 1} do {

		//sleep 90;//this sleep is bad since it can cause an unwanted delay between spawning groups, the delay will be handled later
		_timer = time + 10;
		waituntil {

			sleep 1;
			position _unit distance _spawnpos > 30 OR time > _timer OR ({alive _x} count units _grp) isEqualTo 0

		};

		deleteWaypoint [_grp, 1];
		_wp = _grp addWaypoint [position _unit, 1];
		[_grp, 1] setWaypointType "SAD";
		[_grp, 1] setWaypointSpeed "FULL";

	};

	if (_debug) then {systemchat format ["All units hunting %1 died!",name _unit]};

	//wait 1 second to allow spawning of new groups to hunt the player, adjust this to your liking
	sleep 1;
	_unit setVariable ["TAG_fnc_isBeingHunted",false,true];

};

Notice the additional input parameter.

You now call it like this:


_hunt = [_x,east] spawn TAG_fnc_spawnHostileGroups;

If no side input parameter is given it will default to independent.

Note that you need to modify the group templates or it won't work.

To round it up your spawn loop will look like this to spawn one independend and one east group hunting the player:



_spawningEnemies = [] spawn {

	_debug = false;
	_players = [];
	TAG_fnc_spawnEnemies = true;

	if (_debug) then {systemchat "System Initialized"};

	//wait until the mission is running
	waitUntil {time > 0};

	if (_debug) then {systemchat "Mission Running"};

	while {TAG_fnc_spawnEnemies} do {

		if (_debug) then {systemchat "Loop Running"};

		//wait until there's players on the server
		waitUntil {

			if (_debug) then {systemchat "Waiting for players..."};
			sleep 3;
			 (count (allplayers - switchableUnits) > 0)

		};

		if (_debug) then {systemchat "Players detected!"};

		//will only select players that are not currently hunted
		_players = (allplayers - switchableUnits) select {!(_x getVariable ["TAG_fnc_isBeingHunted",false])};

		_players apply {

			_hunt = [_x,independent] spawn TAG_fnc_spawnHostileGroups;
			_hunt = [_x,east] spawn TAG_fnc_spawnHostileGroups;

		};

	};

};

 

Cheers

 

This is throwing me an error stating:

Error Params: type string, expected array.

But thanks for your help thus far again.

This is also helping me to understand a little better.

Share this post


Link to post
Share on other sites
26 minutes ago, RoryRothon said:

 

This is throwing me an error stating:

Error Params: type string, expected array.

But thanks for your help thus far again.

This is also helping me to understand a little better.

 

Nevermind, it's patch day lol

Had to disable my mods

Share this post


Link to post
Share on other sites
14 hours ago, RoryRothon said:

 

Nevermind, it's patch day lol

Had to disable my mods

 

Although it seems to loop over and over spawning groups in every second or so....

And it is only spawning in INDEP.

Share this post


Link to post
Share on other sites

Right.

I have fixed the issue with spawning only INDEP (my mistake, i removed the WEST config array as not needed, but putting it back works).

I have also made a check on _sideID as follows:

 

systemchat format ["SideID: %1", _sideID]; //<< Debug to grab _sideID

_faction = Nil;
if ( _sideID == 0 ) then { _faction = East };
if ( _sideID == 1 ) then { _faction = West };
if ( _sideID == 2 ) then { _faction = Independent };

_grp = [_spawnPos, _faction, (selectRandom ( CFC_fnc_groupTemplates select _sideID ) ) ] call BIS_fnc_spawnGroup;

This will now change the faction depending on the _sideID so all is working.

However, when 1 group is dead, the code loops and spawns in 2 more groups (1x INDEP & 1x OPFOR) thus giving me 3 groups hunting a player when i need a maximum of 2 per player.

Share this post


Link to post
Share on other sites

That's why you should brainstorm first, think about what features you want to have, how you want stuff to happen and put a very detailed description of it.

Going from A to B to C only gets you so far, having a well thought out "roadmap" for the features and functionality is the most important part and should take up most of the time.

Scripting it can be done in a few minutes in most cases.

 

To prevent multiple groups from spawning you need to change the lockout check variable "TAG_fnc_isBeingHunted" from bool to an integer, increase it by 1 every time a group hunts the player, reduce it by 1 when a hunting group has no more alive members and only if the number is equal to 0 allow spawning of further groups.

Here's the whole thing with commented changes as mentioned before:


TAG_fnc_groupTemplates = [

	[
	//east configs here
	],
	[
	//west configs here
	],
	[
	//indep configs here
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Patrol",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Security_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Field_Support_Team",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Detail",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_Security_Specialists",
	configfile >> "CfgGroups" >> "Indep" >> "CUP_I_PMC_ION" >> "Infantry" >> "CUP_I_PMC_ION_VIP_Bodyguard"
	]
];


//do this in initserver.sqf or wherever you call the script
TAG_fnc_spawnHostileGroups = {

	params ["_unit",["_side",independent]];//side will default to indep

	_debug = false;
	_sideID = _side call BIS_fnc_sideID;

	_pos = getPosATL _unit;

	//we're spawning a group, so we increase the hunting groups counter by one
	_huntingGroups = _unit getVariable ["TAG_fnc_isBeingHunted",0];
	_huntingGroups = _huntingGroups + 1;
	_unit setVariable ["TAG_fnc_isBeingHunted",_huntingGroups,true];


	_spawnPos = _pos getPos [200, random 360];
	_spawnPos = [_spawnPos, 1, 150, 3, 0, 20, 0] call BIS_fnc_findSafePos;

	if (_debug) then {systemchat format ["Spawning enemies to hunt %1!",name _unit]};

	_grp = [ _spawnPos, INDEPENDENT, ( selectRandom (TAG_fnc_groupTemplates select _sideID) ) ] call BIS_fnc_spawnGroup;

	_grp deleteGroupWhenEmpty true;//handles group deletion automatically

	{
		_x setskill 0.25;

	} forEach units _grp;

	_wp = _grp addWaypoint [position _unit, 0];
	[_grp, 1] setWaypointType "SAD";
	[_grp, 1] setWaypointSpeed "FULL";

	{

		_youCanNameThisWhateverthefuckyouwantItDoesntHaveToBeNullAllTheTimeForCryingOutLoud = [_x] execVM "AL_searchlight\al_search_light_ini.sqf"

	} forEach units _grp;

	while {({alive _x} count units _grp) >= 1} do {

		//sleep 90;//this sleep is bad since it can cause an unwanted delay between spawning groups, the delay will be handled later
		_timer = time + 10;
		waituntil {

			sleep 1;
			position _unit distance _spawnpos > 30 OR time > _timer OR ({alive _x} count units _grp) isEqualTo 0

		};

		deleteWaypoint [_grp, 1];
		_wp = _grp addWaypoint [position _unit, 1];
		[_grp, 1] setWaypointType "SAD";
		[_grp, 1] setWaypointSpeed "FULL";

	};

	if (_debug) then {systemchat format ["All units hunting %1 died!",name _unit]};

	//wait 1 second to allow spawning of new groups to hunt the player, adjust this to your liking
	sleep 1;
	//group died, reduce the hunted check by one:
	_huntingGroups = _unit getVariable ["TAG_fnc_isBeingHunted",0];
	_huntingGroups = _huntingGroups - 1;
	_unit setVariable ["TAG_fnc_isBeingHunted",_huntingGroups,true];

};


_spawningEnemies = [] spawn {

	_debug = false;
	_players = [];
	TAG_fnc_spawnEnemies = true;

	if (_debug) then {systemchat "System Initialized"};

	//wait until the mission is running
	waitUntil {time > 0};

	if (_debug) then {systemchat "Mission Running"};

	while {TAG_fnc_spawnEnemies} do {

		if (_debug) then {systemchat "Loop Running"};

		//wait until there's players on the server
		waitUntil {

			if (_debug) then {systemchat "Waiting for players..."};
			sleep 3;
			 (count (allplayers - switchableUnits) > 0)

		};

		if (_debug) then {systemchat "Players detected!"};

		//will only select players that are not currently hunted by any groups
		_players = (allplayers - switchableUnits) select {(_x getVariable ["TAG_fnc_isBeingHunted",0]) isEqualTo 0};

		_players apply {

			_hunt = [_x,independent] spawn TAG_fnc_spawnHostileGroups;
			_hunt = [_x,east] spawn TAG_fnc_spawnHostileGroups;

		};

	};

};

Didn't test it but should do the trick anyway.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

@Grumpy Old Man of all the grumpy guys I know, you are the most helpful!  You give people fish AND teach people how to fish at the same time.   Thanks for all you do.

  • Like 5

Share this post


Link to post
Share on other sites
6 minutes ago, johnnyboy said:

You give people fish AND teach people how to fish at the same time.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

@johnnyboy - It's Doug Stanhope - he's very abrasive but I love his stuff.  I'd say probably a good one to start with would be Dead Beat Hero.  As I say, sometimes he can seem ott but his hearts in the right place (even if everything else is maligned).  Enjoy!

 

 

  • Like 1

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

×