Jump to content
Sign in to follow this  
R3dBuLL

random spawn position near player

Recommended Posts

Hi there

This is my first attempt to make a script in ArmA2 and I have trouble with it.

My idea was to let some enemy units spawn continuous near the players. This is what I got:

While {true} do

{
waituntil {!isnil "bis_fnc_init"};

_pos = If (!alive Player1) Then
{
	If (!alive Player2) Then
	{
		If (!alive Player3) Then
		{
			If (!alive Player4) Then
			{
				If (!alive Player5) Then
				{
					getPos Player6;
				}
				Else
				{
					getPos Player5;
				};
			}
			Else
			{
				getPos Player4;	
			};
		}
		Else
		{
			getPos Player3;
		};
	}
	Else
	{
		getPos Player2;
	};
}
Else
{
	getPos Player1;
};

_skill = [0.3,0.4,0.5];
_side = East;
_units = (6 + random 6);
_spos = [((_pos select 0) 100 + random 100),((_pos select 1) 100 + random 100),(_pos select 2)]

hint "Here they come!";

_grp = [_spos, _side, _units, [], [], _skill] call BIS_fnc_spawnGroup;

Sleep 60
};

It checks if the Players are alive to avoid spawning the enemies near a dead player. It works good if I use "_grp = [_pos, _side, _units, [], [], _skill] call BIS_fnc_spawnGroup;" but then the enemies spawn on the players position.

How to let them spawn around the player in a range of 100-200?

I tried to make an array (_spos) based on the player position and add some random values to let them spawn nearby.

Edited by R3dBuLL

Share this post


Link to post
Share on other sites

SHK_pos.sqf

SHK_pos = compile preprocessfile "SHK_pos.sqf";
_spos = [_pos,random 360,[100,200]] call SHK_pos;

Btw, you can replace the If-Else monster with something like this:

{
 if (alive _x) exitwith { _pos = getpos _x };
} foreach [player1,player2,player3,player4,player5,player6];

Share this post


Link to post
Share on other sites

Nice, thank you. It's working as expected.

I knew there must be a simpler way for the nested-if. Thank you for that as well.

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
Sign in to follow this  

×