Jump to content
Sign in to follow this  

Spawning units, deleting when player is far, and respawning when back

Recommended Posts

hi fellow modders

i'm working on a script that spawns units when player is near some kind of building, de-spawns when player is far and spawns again if player is near same kind of building again. here is my code :

_groups_nato = [];

x = true;

fn_find_base = 
	_list = nearestObjects [player, _bases, 1000];
	_base = _list call bis_fnc_selectrandom;
	_return = getpos _base;

fn_spawn_nato = 
	if (count _groups_nato < 5) then 
		_pos = [] call fn_find_base;
		_grp = creategroup west;
		for "_i" from 1 to 3 do {"B_Soldier_F" createUnit [_pos, _grp];};
		nul = [_grp, _pos] call BIS_fnc_taskdefend;
		_return = _grp;

while {x} do 
	_grp = [] call fn_spawn_nato;
	_groups_nato = _groups_nato + [_grp];
	_ldr = leader _grp;
	if ((_ldr) distance player > 1000) then 
		{deletevehicle _x} foreach units _grp;
		_groups_nato = _groups_nato - [_grp];
	hint str _groups_nato;

the spawning and de-spawning part of the script works, but it fails to spawn again when player is near same kind of buildings. any help will be 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