Jump to content
Cillo

Spawn Units on Trigger in a Loop

Recommended Posts

Full disclosure: I'm very new to scripting - I know I'm probably not doing things the most efficient way, so any tips will be warmly welcomed!

 

I'm making an Exile WWII zombie server using Ravage zombies. The built-in ambient spawner for Ravage works okay, but I wanted to add greater variety in uniforms, loot, etc, so tried to write something myself. As disclosed above, this isn't my strong suit at all. 

 

I want the script to trigger at certain locations. I'd got in mind that I'd create an array (called _trgPos) that would hold the positions and radii of each trigger then create each trigger in a loop. This is what I've got so far: 

_trgpos =  [ 
    [[7365.57,2201.88,0],200], // A
    [[6422.59,2424.74,0],200]  // B
   ]; 

{ 
 pos = _x select 0; 
 _rad = _x select 1; 
 _trg = createTrigger ["EmptyDetector", pos, true]; 
 systemChat format["Creating trigger at %1",pos];
 _trg setTriggerArea [_rad, _rad, 0, false, _rad]; 
 _trg setTriggerActivation ["GUER", "PRESENT", true]; 
 _trg setTriggerStatements ["this", "null = [pos] execVM 'zombiespawner.sqf'; systemChat format['Spawning zombies at %1',pos];", ""]; 
} forEach _trgpos;

It's meant to pass pos to the script, which then causes the zombies to spawn when an Exile player enters the area. 


What actually happens is both triggers are created at their correct location, but when either A or B trigger is activated, the zombies spawn at the location of B. I've seen it works like this in 3DEN or when executed on the server. 

 

It seems that B's location is being passed to the script on both triggers. 

 

Have I missed something basic? Any insight anyone could offer would be fantastic! 

 

(Including zombiespawner.sqf in case it's useful):

Spoiler

_location = _this select 0;

// Uniforms, headgear, loot, etc. omitted.

_group0 = createGroup civilian; 

_walkers = 10;
_runners = 5;
_bolters = 5;
_zeds = [];

while {_walkers > 0} do
{
	pos = [_location,0,150,1] call BIS_fnc_findSafePos;
	//systemChat format["Passing %1 to spawner...",pos];
	_unit1 = _group0 createUnit ["zombie_walker",pos,[],0,"FORM"]; 
	_unit1 setVariable ["BIS_enableRandomization", false]; 
	//_unit1 switchMove "Babe_climbOnHer_pst";   
	//uisleep 2.5;  
	removeUniform _unit1;   
	_unit1 forceAddUniform selectRandom _uniforms;   
	if (random 1 > 0.5) then   
	{   
		_unit1 addVest selectRandom _headgear;    
	}   
	else
	{
		if (random 1 > 0.98) then
		{
			_unit1 setFace "rvg_no_face";
		};
	};
	_unit1 addVest selectRandom _vests;   
	_unit1 addItemToVest selectRandom _randItems;
	if (random 1 > 0.95) then
	{
		_unit1 addBackpack selectRandom _backpacks;
		_unit1 addItemToBackpack selectRandom _randItems;
	};
	_unit1 setVariable["ExileMoney",round(random 20),true]; 
	_zeds pushBack _unit1;
	_walkers = _walkers - 1;
};

while {_runners > 0} do
{
	pos = [_location,0,150,1] call BIS_fnc_findSafePos;
	_unit1 = _group0 createUnit ["zombie_runner",pos,[],0,"FORM"]; 
	_unit1 setVariable ["BIS_enableRandomization", false]; 
	//_unit1 switchMove "Babe_climbOnHer_pst";   
	//uisleep 2.5;  
	removeUniform _unit1;   
	_unit1 forceAddUniform selectRandom _uniforms;   
	if (random 1 > 0.5) then   
	{   
		_unit1 addVest selectRandom _headgear;    
	}   
	else
	{
		if (random 1 > 0.98) then
		{
			_unit1 setFace "rvg_no_face";
		};
	};
	_unit1 addVest selectRandom _vests;   
	_unit1 addItemToVest selectRandom _randItems;
	if (random 1 > 0.95) then
	{
		_unit1 addBackpack selectRandom _backpacks;
		_unit1 addItemToBackpack selectRandom _randItems;
	};
	_unit1 setVariable["ExileMoney",round(random 20),true]; 
	_zeds pushBack _unit1;
	_runners = _runners - 1;
};

while {_bolters > 0} do
{
	pos = [_location,0,150,1] call BIS_fnc_findSafePos;
	_unit1 = _group0 createUnit ["zombie_bolter",pos,[],0,"FORM"]; 
	_unit1 setVariable ["BIS_enableRandomization", false]; 
	//_unit1 switchMove "Babe_climbOnHer_pst";   
	//uisleep 2.5;  
	removeUniform _unit1;   
	_unit1 forceAddUniform selectRandom _uniforms;   
	if (random 1 > 0.5) then   
	{   
		_unit1 addVest selectRandom _headgear;    
	}
	else
	{
		if (random 1 > 0.98) then
		{
			_unit1 setFace "rvg_no_face";
		};
	};
	_unit1 addVest selectRandom _vests;   
	_unit1 addItemToVest selectRandom _randItems;
	if (random 1 > 0.95) then
	{
		_unit1 addBackpack selectRandom _backpacks;
		_unit1 addItemToBackpack selectRandom _randItems;
	};
	
	_unit1 setVariable["ExileMoney",round(random 20),true]; 
	_zeds pushBack _unit1;
	_bolters = _bolters - 1;
};

while {count _zeds > 0} do
{
	{
		_distance = position _x distance position player;
		_zed = _x;
		if ({_x distance _zed > 450} count allPlayers > 0) then
		{
			if (alive _zed) then
			{
				deleteVehicle _x;
			};
		};
		if (!alive _x) then
		{
			_zeds = _zeds - [_x];
		};
		sleep 1;
	} forEach _zeds;
};

 

 

Share this post


Link to post
Share on other sites

That's normal because your overwrite your first position with the second one, using the same global variable;

Use getpos thisTrigger instead of pos

  • Thanks 1

Share this post


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

That's normal because your overwrite your first position with the second one, using the same global variable;

Use getpos thisTrigger instead of pos

@pierremgi You beautiful person. I can't believe how much head-scratching I've done over this. 

 

Thank you so much! 

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

×