Jump to content
Sign in to follow this  
colinm9991

DeleteUnit - As opposed to CreateUnit?

Recommended Posts

I'm creating a survival mission and in one of these scripts which spawns the zombies, I have this

_grp = createGroup resistance;
_pos = getpos player;
_unit1 = _grp createUnit ["CHN_UNDEAD_Doctor", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Policeman", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Rocker2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_HouseWife5", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Damsel4", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Citizen3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Priest", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Profiteer4", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Hooker2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Secretary3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Functionary2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Madam3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_USMC_Soldier_Base", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Doctor", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Policeman", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Rocker2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Rocker3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Worker4", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Citizen3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Priest", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Profiteer4", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Villager2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Villager3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Functionary2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Worker1", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_USMC_Soldier_Base", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Doctor", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Policeman", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Rocker2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_HouseWife5", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Damsel4", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Citizen3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Priest", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Profiteer4", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Hooker2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Secretary3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Functionary2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_Madam3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_UNDEAD_USMC_Soldier_Base", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Doctor", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Policeman", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Rocker2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Rocker3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Worker4", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Citizen3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Priest", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Profiteer4", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Villager2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Villager3", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Functionary2", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_Worker1", _pos, [], 100, "FORM"];
_unit1 = _grp createUnit ["CHN_ZOMBIE_USMC_Soldier_Base", _pos, [], 100, "FORM"];

Then in the triggers OnAct field I have

nul0 = [] execVM "spawn.sqf"

What script would I need or use for OnDea that could remove the zombies once the player is out of that trigger?

Or how it be done so that it deletes the closest spawned zombies from the player.

Edited by ColinM9991

Share this post


Link to post
Share on other sites

I had that in mind, but now I realize that even doing that will delete zombies who are chasing the player.

Is it possible to delete zombies further away from any players?

Let's say two players are playing, whom are 500 meters apart, there is a 200 meter radius set around both/all players to keep the zombies within 200 meters alive, thus continuing chasing the players.

All zombies outside that 200 meter radius that are not engaging are considered rubbish and deleted.

Share this post


Link to post
Share on other sites
Distance will help :)

Thanks for the step forward :)

What sort of coding would I be looking at for this?

Something like this?

_meters=[1,2,3] distance player
{
//Do Nothing
}
else
{
deleteVehicle unit1;
}

Share this post


Link to post
Share on other sites

My untested proposition: leave onDeAct empty, and as Act-executed code use something like:


_classArray = 
[
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base",
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base"
];

_HQ = createCenter resistance;//if there is no any unit of resistance side placed on map in editor 
_grp = createGroup resistance;
_pos = position player;

{
_u1 = _grp createUnit [_x, _pos, [], 100, "FORM"]
}
foreach _classArray;

{
[_x] spawn
	{
	_zombie = _this select 0;

	_triggerRadius = 200;//only example value of course

	_toDelete = false;

	waitUntil 
		{
		sleep 5;
		_nE = _zombie findNearestEnemy _zombie;
		if (isNull _nE) then 
			{
			_toDelete = true
			} 
		else
			{
			if ((_nE distance _zombie) > 500) then 
				{
				_toDelete = true
				}
			};

		(((player distance trigger1) > _triggerRadius) and (_toDelete))
		};

	deleteVehicle _zombie
	}

}
foreach (units _grp);

In this example deleted will be each zombie, that do not know about any enemy (player) or is farer than 500 meters, but only when distance between player and trigger named here trigger1 is bigger than 200 meters (conditions checked every 5 seconds, if this is for MP, "player" command shouldn't be used and so distance condition will look different, also because there will be more, than one player).

Edited by Rydygier

Share this post


Link to post
Share on other sites
My untested proposition: leave onDeAct empty, and as Act-executed code use something like:


_classArray = 
[
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base",
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base"
];

_HQ = createCenter resistance;//if there is no any unit of resistance side placed on map in editor 
_grp = createGroup resistance;
_pos = position player;

{
_u1 = _grp createUnit [_x, _pos, [], 100, "FORM"]
}
foreach _classArray;

{
[_x] spawn
	{
	_zombie = _this select 0;

	_triggerRadius = 200;//only example value of course

	_toDelete = false;

	waitUntil 
		{
		sleep 5;
		_nE = _zombie findNearestEnemy _zombie;
		if (isNull _nE) then 
			{
			_toDelete = true
			} 
		else
			{
			if ((_nE distance _zombie) > 500) then 
				{
				_toDelete = true
				}
			};

		(((player distance trigger1) > _triggerRadius) and (_toDelete))
		};

	deleteVehicle _zombie
	}

}
foreach (units _grp);

In this example deleted will be each zombie, that do not know about any enemy (player) or is farer than 500 meters, but only when distance between player and trigger named here trigger1 is bigger than 200 meters (conditions checked every 5 seconds, if this is for MP, "player" command shouldn't be used and so distance condition will look different, also because there will be more, than one player).

Works a treat :)

How would I use this and add them all to their own individual unit, or at least disable that "% Is Dead" quote that AI say when one man is down?

Share this post


Link to post
Share on other sites

As for MP scripting - lets better someone else will help here, I not know much about "how to make script MP compatibile". If you will be able to prepare an array containing all player's (playable) characters, eg as CLN_playable_units global array, you can do this distance check for every of them:

_trigger = _this select 0;
_triggerRadius = _this select 1;

_classArray = 
[
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base",
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base"
];

_HQ = createCenter resistance;//if there is no any unit of resistance side placed on map in editor 
_grp = createGroup resistance;
_pos = position player;

{
_u1 = _grp createUnit [_x, _pos, [], 100, "FORM"]
}
foreach _classArray;

{
[_x,_trigger,_triggerRadius] spawn
	{
	_zombie = _this select 0;
	_trigger = _this select 1;
	_triggerRadius = _this select 2;

	_toDelete = false;

	waitUntil 
		{
		sleep 5;
		_nE = _zombie findNearestEnemy _zombie;
		if (isNull _nE) then 
			{
			_toDelete = true
			} 
		else
			{
			if ((_nE distance _zombie) > 500) then 
				{
				_toDelete = true
				}
			};

		_tooClose = false;

			{
			if ((_x distance _trigger) < _triggerRadius) exitwith {_tooClose = true}
			}
		foreach CLN_playable_units;

		(not (_tooClose) and (_toDelete))
		};

	deleteVehicle _zombie
	}

}
foreach (units _grp);

Note some other changes. Now code is more universal - can be used for any trigger, and should be executed such or similar way:

nul = [NameOfThisTrigger,RadiusOfThisTrigger] execVM "spawn.sqf";

If this is only for MP, probably manually defined at init CLN_playable_units array can be replaced by simply playableUnits command in spawn.sqf.

If you plan to use such code many times with many triggers (trying to make own DayZ, eh? :) ) then you may consider to initially preprocess and compile this code, and then only spawn it for better performance. Same array of zombie classes can be defined only once, on init, as global. If so, then yours init code will contain something like:

CLN_ZombieClassArray = 
[
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base",
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base"
];

ZombiesEverywhere = compile preprocessFile "spawn.sqf";

_HQ = createCenter resistance;//if there is no any unit of resistance side placed on map in editor

spawn.sqf then:

_trigger = _this select 0;
_triggerRadius = _this select 1;

_grp = createGroup resistance;
_pos = position player;

{
_u1 = _grp createUnit [_x, _pos, [], 100, "FORM"]
}
foreach CLN_ZombieClassArray;

{
[_x,_trigger,_triggerRadius] spawn
	{
	_zombie = _this select 0;
	_trigger = _this select 1;
	_triggerRadius = _this select 2;

	_toDelete = false;

	waitUntil 
		{
		sleep 5;
		_nE = _zombie findNearestEnemy _zombie;
		if (isNull _nE) then 
			{
			_toDelete = true
			} 
		else
			{
			if ((_nE distance _zombie) > 500) then 
				{
				_toDelete = true
				}
			};

		_tooClose = false;

			{
			if ((_x distance _trigger) < _triggerRadius) exitwith {_tooClose = true}
			}
		foreach CLN_playable_units;

		(not (_tooClose) and (_toDelete))
		};

	deleteVehicle _zombie
	}

}
foreach (units _grp);

and trigger's Act execution:

nul = [NameOfThisTrigger,RadiusOfThisTrigger] spawn ZombiesEverywhere;

As for second part - no time for tests now, if some here is appropriate but you may try:

enableSentences

enableRadio

fadeRadio

Not sure, if this fit here, but via Description.ext file you can also mess with disabling certain chat channels:

disableChannels

EDIT:

Oh, if you want to silence only zombies, then you can make each of them a separate group. This will need some changes in spawn.sqf, eg, for last mentioned version:

_trigger = _this select 0;
_triggerRadius = _this select 1;

_pos = position player;

{
_grp = createGroup resistance;
_u1 = _grp createUnit [_x, _pos, [], 100, "FORM"];

[_u1,_trigger,_triggerRadius] spawn
	{
	_zombie = _this select 0;
	_trigger = _this select 1;
	_triggerRadius = _this select 2;

	_toDelete = false;

	waitUntil 
		{
		sleep 5;
		_nE = _zombie findNearestEnemy _zombie;
		if (isNull _nE) then 
			{
			_toDelete = true
			} 
		else
			{
			if ((_nE distance _zombie) > 500) then 
				{
				_toDelete = true
				}
			};

		_tooClose = false;

			{
			if ((_x distance _trigger) < _triggerRadius) exitwith {_tooClose = true}
			}
		foreach CLN_playable_units;

		(not (_tooClose) and (_toDelete))
		};

	deleteVehicle _zombie
	}
}
foreach CLN_ZombieClassArray;

Edited by Rydygier

Share this post


Link to post
Share on other sites
Works a treat :)

How would I use this and add them all to their own individual unit, or at least disable that "% Is Dead" quote that AI say when one man is down?

I would suggest to constantly monitor the trigger's detected array (thisList) [called here YOURTRIGGERARRAY] in a script and simply check for

if (!(player in YOURTRIGGERARRAY)) then 
{
{
if ((_x getvariable "CHN_UNDEAD_INFECTED") and (_x distance player > 200)) then {deletevehicle _x}
} foreach YOURTRIGGERARRAY;
}; 

You would have to put something like YOURTRIGGERARRAY= thisList into the trigger itself.

Hope that helps.

Share this post


Link to post
Share on other sites
If this is only for MP, probably manually defined at init CLN_playable_units array can be replaced by simply playableUnits command in spawn.sqf.

If you plan to use such code many times with many triggers (trying to make own DayZ, eh? :) ) then you may consider to initially preprocess and compile this code, and then only spawn it for better performance. Same array of zombie classes can be defined only once, on init, as global. If so, then yours init code will contain something like:

CLN_ZombieClassArray = 
[
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base",
"CHN_UNDEAD_Doctor",
"CHN_UNDEAD_Policeman",
"CHN_UNDEAD_Rocker2",
"CHN_UNDEAD_HouseWife5",
"CHN_UNDEAD_Damsel4",
"CHN_UNDEAD_Citizen3",
"CHN_UNDEAD_Priest",
"CHN_UNDEAD_Profiteer4",
"CHN_UNDEAD_Hooker2",
"CHN_UNDEAD_Secretary3",
"CHN_UNDEAD_Functionary2",
"CHN_UNDEAD_Madam3",
"CHN_UNDEAD_USMC_Soldier_Base",
"CHN_ZOMBIE_Doctor",
"CHN_ZOMBIE_Policeman",
"CHN_ZOMBIE_Rocker2",
"CHN_ZOMBIE_Rocker3",
"CHN_ZOMBIE_Worker4",
"CHN_ZOMBIE_Citizen3",
"CHN_ZOMBIE_Priest",
"CHN_ZOMBIE_Profiteer4",
"CHN_ZOMBIE_Villager2",
"CHN_ZOMBIE_Villager3",
"CHN_ZOMBIE_Functionary2",
"CHN_ZOMBIE_Worker1",
"CHN_ZOMBIE_USMC_Soldier_Base"
];

ZombiesEverywhere = compile preprocessFile "spawn.sqf";

_HQ = createCenter resistance;//if there is no any unit of resistance side placed on map in editor

spawn.sqf then:

_trigger = _this select 0;
_triggerRadius = _this select 1;

_grp = createGroup resistance;
_pos = position player;

{
_u1 = _grp createUnit [_x, _pos, [], 100, "FORM"]
}
foreach CLN_ZombieClassArray;

{
[_x,_trigger,_triggerRadius] spawn
	{
	_zombie = _this select 0;
	_trigger = _this select 1;
	_triggerRadius = _this select 2;

	_toDelete = false;

	waitUntil 
		{
		sleep 5;
		_nE = _zombie findNearestEnemy _zombie;
		if (isNull _nE) then 
			{
			_toDelete = true
			} 
		else
			{
			if ((_nE distance _zombie) > 500) then 
				{
				_toDelete = true
				}
			};

		_tooClose = false;

			{
			if ((_x distance _trigger) < _triggerRadius) exitwith {_tooClose = true}
			}
		foreach CLN_playable_units;

		(not (_tooClose) and (_toDelete))
		};

	deleteVehicle _zombie
	}

}
foreach (units _grp);

and trigger's Act execution:

nul = [NameOfThisTrigger,RadiusOfThisTrigger] spawn ZombiesEverywhere;

After trying via that way, zombies no longer spawn.

I put the first code in Init.sqf,then I moved it out to a file Zombie.sqf and executed that from the init

Share this post


Link to post
Share on other sites

I don't know, why. This version is working for me. Units are spawned and removed, when should be. See this demo:

http://www45.zippyshare.com/v/15747832/file.html

(go forward into trigger area)

Used NAPA units - haven't zombies.

One thing: there is "position player" used. Not acceptable for MP. Maybe position _trigger instead will be sufficient? Or better closest to trigger (or any/random/first) element of mentioned trigger's thislist array (containing all, what makes it currently active). See also:

list

EDIT: eg instead of _pos = position player use:

_actArr = list _trigger;

_pos = position (_actArr select (floor (random (count _actArr))));

So center position for zombie spawn will be a position of randomly selected BLUFOR unit inside trigger area (if condition set on "BLUFOR present"). Tested with above demo, works. I suggest also to add some sleep, eg 30 seconds, before waitUntil, so zombie will be not in any circumstance removed just after spawning, but at least 30+5 seconds later:

_trigger = _this select 0;
_triggerRadius = _this select 1;

_grp = createGroup resistance;

_actArr = list _trigger;

_pos = position (_actArr select (floor (random (count _actArr))));

{
_u1 = _grp createUnit [_x, _pos, [], 100, "FORM"]
}
foreach CLN_ZombieClassArray;

{
[_x,_trigger,_triggerRadius] spawn
	{
	_zombie = _this select 0;
	_trigger = _this select 1;
	_triggerRadius = _this select 2;

	_toDelete = false;

	sleep 30;

	waitUntil 
		{
		sleep 5;
		_nE = _zombie findNearestEnemy _zombie;
		if (isNull _nE) then 
			{
			_toDelete = true
			} 
		else
			{
			if ((_nE distance _zombie) > 500) then 
				{
				_toDelete = true
				}
			};

	_tooClose = false;

		{
		if ((_x distance _trigger) < _triggerRadius) exitwith {_tooClose = true}
		}
	foreach CLN_playable_units;

	(not (_tooClose) and (_toDelete))
	};

	deleteVehicle _zombie
	}
}
foreach (units _grp);  

Edited by Rydygier

Share this post


Link to post
Share on other sites
I don't know, why. This version is working for me. Units are spawned and removed, when should be. See this demo:

http://www45.zippyshare.com/v/15747832/file.html

(go forward into trigger area)

Used NAPA units - haven't zombies.

One thing: there is "position player" used. Not acceptable for MP. Maybe position _trigger instead will be sufficient? Or better closest to trigger (or any/random/first) element of mentioned trigger's thislist array (containing all, what makes it currently active). See also:

list

EDIT: eg instead of _pos = position player use:

_actArr = list _trigger;

_pos = position (_actArr select (floor (random (count _actArr))));

So center position for zombie spawn will be a position of randomly selected BLUFOR unit inside trigger area (if condition set on "BLUFOR present"). Tested with above demo, works. I suggest also to add some sleep, eg 30 seconds, before waitUntil, so zombie will be not in any circumstance removed just after spawning, but at least 30+5 seconds later:

_trigger = _this select 0;
_triggerRadius = _this select 1;

_grp = createGroup resistance;

_actArr = list _trigger;

_pos = position (_actArr select (floor (random (count _actArr))));

{
_u1 = _grp createUnit [_x, _pos, [], 100, "FORM"]
}
foreach CLN_ZombieClassArray;

{
[_x,_trigger,_triggerRadius] spawn
	{
	_zombie = _this select 0;
	_trigger = _this select 1;
	_triggerRadius = _this select 2;

	_toDelete = false;

	sleep 30;

	waitUntil 
		{
		sleep 5;
		_nE = _zombie findNearestEnemy _zombie;
		if (isNull _nE) then 
			{
			_toDelete = true
			} 
		else
			{
			if ((_nE distance _zombie) > 500) then 
				{
				_toDelete = true
				}
			};

	_tooClose = false;

		{
		if ((_x distance _trigger) < _triggerRadius) exitwith {_tooClose = true}
		}
	foreach CLN_playable_units;

	(not (_tooClose) and (_toDelete))
	};

	deleteVehicle _zombie
	}
}
foreach (units _grp);  

I loaded your mission into the editor, for some reason that doesn't seem to spawn units either once I'm in the trigger area.

Share this post


Link to post
Share on other sites

So this is working for me and not working for you. Really strange. Haven't idea, what may be a cause here. Are there any errors reported in yours RPT file? Any addons/mods active?

Share this post


Link to post
Share on other sites

rpt file

CLN_playable_units = [unit1];

ZombiesEverywhere = compile pre>
 Error position: <unit1];

ZombiesEverywhere = compile pre>
 Error Undefined variable in expression: unit1
File C:\Users\ColinM\Documents\ArmA 2\missions\ZombieTest.Desert_E\init.sqf, line 12
Error in expression <UE_Soldier_1"
];

CLN_playable_units = [unit1];

ZombiesEverywhere = compile pre>
 Error position: <unit1];

ZombiesEverywhere = compile pre>
 Error Undefined variable in expression: unit1
File C:\Users\ColinM\Documents\ArmA 2\missions\ZombieTest.Desert_E\init.sqf, line 12
Error in expression <UE_Soldier_1"
];

CLN_playable_units = [unit1];

ZombiesEverywhere = compile pre>
 Error position: <unit1];

ZombiesEverywhere = compile pre>
 Error Undefined variable in expression: unit1
File C:\Users\ColinM\Documents\ArmA 2\missions\ZombieTest.Desert_E\init.sqf, line 12

Mods

cd C:\Program Files (x86)\Bohemia Interactive\ArmA 2
start E:\ArmA\Mods\expansion\beta\arma2oa.exe -window -nosplash -winxp -noFilePatching -skipIntro "-mod=E:\ArmA\Mods\expansion\beta;E:\ArmA\Mods\expansion\beta\expansion;E:\ArmA\Mods\@Undead;E:\ArmA\Mods\ACR;E:\ArmA\Mods\PMC;E:\ArmA\Mods\BAF"

Share this post


Link to post
Share on other sites

OK. So we now something. I have empty RPT. Such error I can reproduce only, when change name of player unit placed on map, but even then units are spawned. Except official DLCs the only important difference is undead mod. Maybe this mod changes somehow for some reason name of player unit or use name unit1 for something else (re-define it and makes it nil then)? My suggestions:

1. Try my demo without undead mod (helped? yes/no);

2. Try with undead, but change in line 12 of init.sqf and player's unit name in editor from unit1 to SomeVeryUniqueName1254 :) (yes/no);

3. Try with undead, but change in line 12 of init.sqf unit1 to player (yes/no);

If none will help, there are other ways to define CLN_playable_units array, without using their names in code, eg by synchronizing such units with some logic and usage of:

CLN_playable_units = synchronizedObjects SomeLogicName;

Share this post


Link to post
Share on other sites
OK. So we now something. I have empty RPT. Such error I can reproduce only, when change name of player unit placed on map, but even then units are spawned. Except official DLCs the only important difference is undead mod. Maybe this mod changes somehow for some reason name of player unit or use name unit1 for something else (re-define it and makes it nil then)? My suggestions:

1. Try my demo without undead mod (helped? yes/no);

2. Try with undead, but change in line 12 of init.sqf and player's unit name in editor from unit1 to SomeVeryUniqueName1254 :) (yes/no);

3. Try with undead, but change in line 12 of init.sqf unit1 to player (yes/no);

If none will help, there are other ways to define CLN_playable_units array, without using their names in code, eg by synchronizing such units with some logic and usage of:

CLN_playable_units = synchronizedObjects SomeLogicName;

Still not working on Vanilla and after changing init.sqf code.

Share this post


Link to post
Share on other sites

Hrmm... So I'm forced to give up. Haven't idea, why yours Arma has problem with 12 line of init.sqf, when mine haven't. Wondering, if someone else will have such problems too. I assume, that RPT reports are similar?

Share this post


Link to post
Share on other sites
Hrmm... So I'm forced to give up. Haven't idea, why yours Arma has problem with 12 line of init.sqf, when mine haven't. Wondering, if someone else will have such problems too. I assume, that RPT reports are similar?

Fixed the rpt error by editing line 12 from

CLN_playable_units = [unit1];

to

CLN_playable_units = ["unit1"];

Still no units spawning.

Share this post


Link to post
Share on other sites

I'm glad then.

Do I sync the game logic to all playable players?

Yep.

Share this post


Link to post
Share on other sites
I'm glad then.

Yep.

Thanks for the help, It's been greatly appreciated :)

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  

×