Jump to content

Recommended Posts

Im working on a mission using Ryans Zombies & Demons, and im sure you can guess what type of mission it is lol

Im using the Proving Grounds map from CUP Terrains 1.3 and am spawning in 6 playable units at different locations on the map and ungrouped (well, not it a squad).

 

What i am trying to accomplish is:

 

When players get to below 10 meters from another player = Check is both are in a squad, if not create one and place both units in, or if one is a member of a squad then place the other unit into his squad.

Sounds crazy when i type it out but hopefully you get my meaning...

 

Im just unsure how to go about this...

 

forEach / distance / join / createGroup / etc etc....

Any info regarding this would be greatly appreciated and placed into my pastebin once completed :)

 

Kind regards

Rory

Share this post


Link to post
Share on other sites

Something like this?

 


_isInGroup = {

	params ["_unit"];
	count units group _unit > 1

};

{

	if (player call _isInGroup AND !(_x call _isInGroup) AND player distance _x <= 10) then {

		[_x] join group player;
	}

} forEach (allPlayers - [player]);

 

Cheers

  • Like 1
  • Haha 1

Share this post


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

Something like this?

 



_isInGroup = {

	params ["_unit"];
	count units group _unit > 1

};

{

	if (player call _isInGroup AND !(_x call _isInGroup) AND player distance _x <= 10) then {

		[_x] join group player;
	}

} forEach (allPlayers - [player]);

 

Cheers

 

That looks promising, ill give it a try now :)

Share this post


Link to post
Share on other sites

Would i need to put this into a while true loop?

This is my code thus far:

 

// Center Map Coordinates = [1000,1000]
// Map size = 2000 x 2000
// 900 x 900 marker size
// Chopper Class = (B_Heli_Transport_01_camo_F)

// ** NEED TO GET CLASS NAME FOR RYANS ZOMBIES ANTI VIRUS EQUIPMENT !!

if (!isServer) exitWith {};

// Central marker creation
//========================
centerMarker = createMarker ["Spawn", [1000,1000]];

// Chopper spawn into safe position
//=================================
chopperSafePos = [getMarkerpos "Spawn", 1, 900, 3, 0, 40, 0] call BIS_fnc_findSafePos;
chopper = "B_Heli_Transport_01_camo_F" createVehicle (chopperSafePos);

// include arrays
//===============
#include "vehicleArray.sqf"
#include "itemArray.sqf"

// 10 Random vehicles around map
//==============================
for '_i' from 1 to 10 do {
	_randomVehicle = selectRandom _randomVehiclearray;
	_SafePos = [getMarkerpos "Spawn", 1, 800, 10, 0, 40, 0] call BIS_fnc_findSafePos;
	_veh = _randomVehicle createVehicle (_SafePos);
	_veh setDir (RANDOM 360);

	// Remove eveything from the vehicle
	//==================================
	clearItemCargoGlobal _veh;
	clearWeaponCargoGlobal _veh;
	clearMagazineCargoGlobal _veh;

	// Place 5 random items into the vehicle
	//======================================
	for '_i' from 1 to 5 do { _veh addItemCargoGlobal [selectRandom _randomItemsArray, 1]; };

	// A bit of ammo to help them along the poor buggers
	//==================================================
	_veh addItemCargoGlobal ["30Rnd_65x39_caseless_mag_Tracer", 10];

	// Damage vehicles and light them up
	//==================================
	_veh setFuel 0;
	_veh setDamage 0.8;
	player action["lightOn",_veh];
};

// Make players join group when they are close to eachother
//=========================================================
while { true } do {
	_isInGroup = { params ["_unit"]; count units group _unit > 1 };
	{ if (player call _isInGroup AND !(_x call _isInGroup) AND player distance _x <= 10) then { [_x] join group player; } } forEach (allPlayers - [player]);
};

// DEBUG TESTING PURPOSES -----------------
//waitUntil {getPos chopper select 2 > 15};
//"end1" call BIS_fnc_endMission;
//-----------------------------------------

Regards

Rory

Share this post


Link to post
Share on other sites

Never do while {true} loops. You might wanna stop the loop mid mission, but can't without terminating the entire script.

You can always come up with some global variable to control the loop.

Also you should spawn the loop and put a sleep into it, so you won't run into performance issues.

Something like this:

_loop = [] spawn {
		
	_isInGroup = {

		params ["_unit"];
		count units group _unit > 1

	};

	MyPlayerAutojoin = true;

	while {MyPlayerAutojoin} do {

		{

			if (player call _isInGroup AND !(_x call _isInGroup) AND player distance _x <= 10) then {

				[_x] join group player;
				
			}

		} forEach (allPlayers - [player]);

		sleep 1;

	};

};

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

After tinkering with it, i have noticed that the coded checks for 1 player in a group, and 1 thats not....

It does not check for both not in group.

 

Ive used an else statement for testing:

 

		{ if (player call _isInGroup AND !(_x call _isInGroup) AND player distance _x <= 10) then {
			[_x] join group player;
		} else { [_x] join player; }
		} forEach (allPlayers - [player]);

And this seems to work (ignore the lack of checks), but loops over and over and i i get is "2 JOIN GROUP" over and over lol

The foundations are good, i'll just need to play around with it :)

 

Thanks for the help !

Share this post


Link to post
Share on other sites

Your if then else statement makes no sense, since it will make the checked player join the reference players group in any case.

Hence the "2 JOIN GROUP" spam.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Grumpy Old Man - You are a legend!

Ive gotten over my blonde moment and got it working lol

Here is what i have:

 

_loop = [] spawn {
		
	_isInGroup = {

		params ["_unit"];
		count units group _unit > 1

	};

	MyPlayerAutojoin = true;

	while {MyPlayerAutojoin} do {

		{

			if ( player call _isInGroup AND !(_x call _isInGroup) AND player distance _x <= 10) then {

				[_x] join group player;
				
			} else { 

				if ( !(player call _isInGroup) AND !(_x call _isInGroup) AND player distance _x <= 10) then {

				[_x] join group player;
				
			}

			} forEach (allPlayers - [player]);

		} forEach (allPlayers - [player]);

		sleep 1;

	};

};

Tested with 2 un-grouped players, and 1 grouped / 1 un-grouped and all seems to work :)

Thanks again, this will certainly be used on a lot of my future mission devs :)

 

thanks and regards

Rory

  • Like 1

Share this post


Link to post
Share on other sites

Although players now join a group if they are are ungrouped, i now have the issue of 2 groups getting less than 10m away from each other.

For the life of me i cant seem to find out how to get 2 groups merged to one.

Is there a way i can do the same check as above but for groups?

Anyone in the know care to share their thoughts?

 

Regards

Rory

Share this post


Link to post
Share on other sites

Do you want the smaller group to join the bigger group? Or generally join player groups together if they're within 10m of each other?

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, Grumpy Old Man said:

Do you want the smaller group to join the bigger group? Or generally join player groups together if they're within 10m of each other?

 

Cheers

 

Just to join any 2 groups that get close to eachother.

The first objective is to find all fellow players with a trigger to check all players are grouped before firing the next task, if that makes sense lol

So i'm not fussed about smaller group joining bigger, but simply having 2 groups regardless of size merge into 1.

 

1) Player group player

2) player join player group

3) group merge group

4) Final - group with all players in.

 

Regards

Share this post


Link to post
Share on other sites

Updated example and removed the bracket errors and forEach error from the above example.

Tested it in the editor, working fine:

_loop = [] spawn {

	_isInGroup = {

		params ["_unit"];
		count units group _unit > 1

	};

	MyPlayerAutojoin = true;

	while {MyPlayerAutojoin} do {

		{


			if (player call _isInGroup AND (_x call _isInGroup) AND player distance _x <= 10 AND !(_x in units group player)) then {

				units group _x join group player;

			};

			if (player call _isInGroup AND !(_x call _isInGroup) AND player distance _x <= 10) then {

				[_x] join group player;

			} else {

				if ( !(player call _isInGroup) AND !(_x call _isInGroup) AND player distance _x <= 10) then {

				[_x] join group player;

				}

			};

		} forEach (allPlayers - [player]);

		sleep 1;

	};

};

 

Cheers

Edited by Grumpy Old Man
Removed bracket and forEach error taken over from the above example
  • Like 1

Share this post


Link to post
Share on other sites

Tried something very close to that but left _x in the array brackets and had group in different location lol
I'll give it a whirl and let you know :)

 

Many thanks again ( you've been awesome! )

 

Rory

Share this post


Link to post
Share on other sites

Edited the example above, since I took over your bracket error and the second forEach command from your previous example.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Works like a charm sir :)

I noticed the double forEach too, saved me a job.

 

thanks again Grunmpy, you rock!

 

Regards

Rory

Share this post


Link to post
Share on other sites

Hey folks,

 

thx for creating this useful code! 

 

I do need some assistance though because... being a coding retard?:f:

 

I tried to put that code in init.sqf but didn't see it work on units that are set to be playable.  If I want to use this code in SP and MP missions with the goal that playable slots join if either two of them meet while player occupied OR while one is player occupied and the other AI occupied.  Is this possible with the above code? If so,  where exactly do I put it?

 

THX in advance for any help

 

tourist

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

×