Jump to content
TURCO_AR

Delete enemy team far away from the player

Recommended Posts

Hi. I have some problem to make this script run on Dedi Server.

I want to spawn a group and hunt the player/team that activate the trigger.

 

The spawn is correct and they are directed to the position of the one that activated the trigger. The update of the player's position also works correctly.

The problem is that the _BadGuys are not deleted if the one that activated the trigger moves away more than 700 meters.

 

I placed a trigger, with OnAct:

null = [thistrigger,thislist] execvm "hunter_on foot.sqf";

and the script:

_posTrigger = _this select 0;
_TeamActTrigger = _this select 1;
_1stManTeamActTrigger = _TeamActTrigger select 0;

if (isserver) then {
if (count allunits < 90) then {             //verify that there are no more than 90 units on the map before spawn group
		_spawn = position _posTrigger ;

		_BadGuys = createGroup EAST;
		_BadGuys = [_spawn, EAST, ["O_G_Soldier_SL_F","O_G_Soldier_lite_F"],[],[],[],[],[],260] call BIS_fnc_spawnGroup;

		_chief = leader _BadGuys; 
		_chief move (position _1stManTeamActTrigger);
		_BadGuys setCombatMode "RED"; 
		_BadGuys setBehaviour "AWARE";
		_BadGuys allowFleeing 0;

///////////////////////////////////////////
//Original Script below: anthonyfromtheuk//
///////////////////////////////////////////

//If the distance with the player is greater than 700 the team is deleted
0 = _BadGuys spawn {
while {true} do {
       sleep 3; 
       if ((_1stManTeamActTrigger distance (leader _this)) > 700) exitWith { 
           {deleteVehicle _x} forEach units _BadGuys;
       }; 
   }; 
}; 

//UPDATE the player's position and start moving to the new position
while {true} do {
   _chief = leader _BadGuys; 
   if ((unitReady _chief) && {(alive _chief)}) then { 
       sleep 5; 
       if (({ alive _x} count (units _BadGuys)) != 0) then { 
			_chief = leader _BadGuys; 
			_chief move (position _1stManTeamActTrigger); 
			_BadGuys setCombatMode "RED"; 
			_BadGuys setBehaviour "AWARE";
			_BadGuys allowFleeing 0;		   
       }; 
   }; 
};
							};

				};

Any clues?

Thanks!

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, TURCO_AR said:

{deleteVehicle _x} forEach units _BadGuys;

 

problem is with this line.

It should be:

{deleteVehicle _x} forEach units _this;

because _BadGuys doesnt exist in the spawned code

Share this post


Link to post
Share on other sites
8 hours ago, gc8 said:

problem is with this line.

It should be:


{deleteVehicle _x} forEach units _this;

because _BadGuys doesnt exist in the spawned code

 

Thank you for your reply.

I changed that line and nothing ... It still not working :down:

0 = _chicos1 spawn {
while {true} do {
       sleep 3; 
       if ((_objetivo distance (leader _this)) > 700) exitWith { 
           {deleteVehicle _x} forEach units _this;
       }; 
   }; 
}; 

 

Share this post


Link to post
Share on other sites

Here now, it's _objectivo which is not defined.

Each time you want to spawn a code, write all parameters in array, and inside like this:

 

[_para1,_para2,_para3,..._paraN] spawn {     // you have to pass _local variable only. Global ones are defined on every scripts running on the PC.

  params ["_para1","_para2","_para3",..."_paraN"];

  <code> // btw, will fail if you are using some _parN+1

};

 

This way, you don't bother with extra name for variables, or _this, and it's easy to do.

  • Like 2

Share this post


Link to post
Share on other sites

what pierremgi says:)

 

im the latter part it seems that _1stManTeamActTrigger is not defined as it has not been passed as parameter from the code earlier (as you are creating a separate namespace below, that is separated from above code. above local variables are not "known" here.)

 

my proposal would be to change this:

......

//If the distance with the player is greater than 700 the team is deleted 

 

0 = ["_BadGuys","_1stManTeamActTrigger"] spawn { while {true} do {

params ["_BadGuys","_1stManTeamActTrigger"];

 

sleep 3; 

if ((_1stManTeamActTrigger distance (leader _BadGuys)) > 700) exitWith { {deleteVehicle _x} forEach units _BadGuys; }; }; };

 

also, i beliefe _this should refer to the _BadGuys right? i am not 100% if that works above, i would change it to _BadGuys.

 

written on my handheld, hence my apologies for not putting the code in format and spoilers (no idea how to do this on mobile:()

 

check it with syntax highlighter, but i hope that gives you an idea what the issue might be.

 

check my dynamic spawn script pack here on the forums. in the downloadable file there is a file called VD_NR_Spawner.sqf that is a similar AI hunting script, also with a distance check after player position check.

 

not sure which code is the latest one, the _chicos1 or the _BadGuys version, just apply to whichever it is:)

 

cheers

vd

 

 

  • Like 1

Share this post


Link to post
Share on other sites

0 = [_BadGuys,_1stManTeamActTrigger] spawn { while {true} do {

params ["_BadGuys","_1stManTeamActTrigger"];

 

You see the difference? You pass local variables (no quote "")  you declare params (quoted). Then, of course you use variables (not quoted).

And no, _this refers to the whole params array... But it"s useless if you take time to add the params inside the spawned code. Just use _badGuys.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Hello there Guys !

 

# It's NOT to Show off ,

just a little bit of tease and another code in the BI forum for Everyone

 

 

  • ________________ GF Auto Population Script - Mod ________________
  • Not Yet published
  • This will be my next release so more new here :

 

 

 

Helicopters.sqf  - some part

Spoiler






//________________  Author : GEORGE FLOROS [GR] ___________	22.01.19	_____________

/*
________________ GF Auto Population Script - Mod ________________

Not Yet published

Please keep the Credits or add them to your Diary

https://community.bistudio.com/wiki/SQF_syntax
Don't try to open this with the simple notepad.
For everything that is with comment  //  in front  or between /*
means that it is disabled , so there is no need to delete the extra lines.

You can open this ex:
with notepad++
https://notepad-plus-plus.org/

and also use the extra pluggins
(this way will be better , it will give also some certain colors to be able to detect ex. problems )
http://www.armaholic.com/page.php?id=8680

or use any other program for editing .

For the Compilation List of my GF Scripts , you can search in:
https://forums.bohemia.net/forums/topic/215850-compilation-list-of-my-gf-scripts/
*/


/*
//________________	add this to use	________________
//________________	Helicopters_Transport_	________________
[] spawn GF_AP_Spawn_Helicopters_Patrol;
[] spawn GF_AP_Spawn_Helicopters_Defend;
[] spawn GF_AP_Spawn_Helicopters_Attack;
*/


//________________	GF_AP_Spawn_Helicopters_Patrol	________________

GF_AP_Spawn_Helicopters_Patrol = {

_Pos = GF_AP_Pos;
_Pos_Spawn = _Pos getPos [250,random 360];
_Spawn_Height = 1000;
_Group = createGroup GF_AP_Enemy_Side;
_Group_Crew = createGroup GF_AP_Enemy_Side;

_Helicopter = selectRandom GF_AP_Pool_Helicopters; 
_Spawned_Helicopter = createVehicle [_Helicopter,_Pos_Spawn, [], 0, "FLY"];
_Spawned_Helicopter setPosATL [getPosATL _Spawned_Helicopter select 0, getPosATL _Spawned_Helicopter select 1, _Spawn_Height];
_Spawned_Helicopter engineOn true;


//________________	Count all available seats including cargo slots	________________

_Seats_Number = [_Helicopter,true] call BIS_fnc_crewCount;	

if (GF_AP_Systemchat_info) then {
	systemchat format ['Vehicle: %1		seats:	%2', _Helicopter , _Seats_Number];
};


//________________	 Counts all available seats excluding cargo slots	________________

_Seats_Number_Crew = [_Helicopter,false] call BIS_fnc_crewCount;


//________________	 Spawn Crew	________________

for "_x" from 1 to _Seats_Number_Crew do {

	_unit_Crew = _Group_Crew createunit [selectrandom GF_AP_Pool_Infantry_Helicopters,_Pos_Spawn,[],0,"None"];
	[_unit_Crew] JoinSilent _Group_Crew;
	_unit_Crew moveInAny _Spawned_Helicopter;
	(leader _Group_Crew) setSkill GF_AP_set_AiSkill + floor random GF_AP_set_AiSkill_random;

if (GF_AP_Change_Equipment) then {	
_unit_Crew spawn GF_SCL_GF_AP;
};

	removeBackpack _unit_Crew;
	_unit_Crew addBackPack "B_parachute";
	
};


//________________	 Counts all cargo slots	________________

_Seats_Number_Cargo = _Seats_Number - _Seats_Number_Crew;	

//________________	 Spawn units in Cargo	________________

for "_x" from 1 to _Seats_Number_Cargo do {

	_unit = _Group createunit [selectrandom GF_AP_Pool_Infantry,_Pos_Spawn,[],0,"None"];
	[_unit] JoinSilent _Group;
	_unit moveInAny _Spawned_Helicopter;
	(leader _Group) setSkill GF_AP_set_AiSkill + floor random GF_AP_set_AiSkill_random;
			
if (GF_AP_Change_Equipment) then {	
_unit spawn GF_SCL_GF_AP;
};

	private _data = [backpack _unit,backpackitems _unit];
    removeBackpack _unit;
	_unit addBackPack "B_parachute";	
		  
	[_unit,_data] spawn {
	private ["_unit","_data"];
	_unit = _this select 0;
	_data = _this select 1;
	waitUntil { isTouchingGround _unit || (position _unit select 2) < 1 };
	sleep 1;
	removeBackpack _unit;
	_unit addbackpack (_data select 0);
	{_unit additemtobackpack _x;} foreach (_data select 1);
	};
	
};


[_Group_Crew,_Pos,GF_AP_Air_Patrol_distance + floor random GF_AP_Air_Patrol_distance_random] call BIS_fnc_taskPatrol;
[_Group,_Pos,GF_AP_Air_Patrol_distance + floor random GF_AP_Air_Patrol_distance_random] call BIS_fnc_taskPatrol;

while {(alive _Spawned_Helicopter)} do {
	_Spawned_Helicopter flyInHeight (50 + (random 2000));
	_getPosATL = getPosATL _Spawned_Helicopter;
	_nearEntities = _getPosATL nearEntities 2000;
	{_Group_Crew reveal [_x,4];} count _nearEntities;
	sleep 50;
	};
};

 

 

GF_Auto_Population_Remover.sqf

Spoiler

//________________  Author : GEORGE FLOROS [GR] ___________	22.01.19	_____________

/*
________________ GF Auto Population Script - Mod ________________

Not Yet published

Please keep the Credits or add them to your Diary

https://community.bistudio.com/wiki/SQF_syntax
Don't try to open this with the simple notepad.
For everything that is with comment  //  in front  or between /*
means that it is disabled , so there is no need to delete the extra lines.

You can open this ex:
with notepad++
https://notepad-plus-plus.org/

and also use the extra pluggins
(this way will be better , it will give also some certain colors to be able to detect ex. problems )
http://www.armaholic.com/page.php?id=8680

or use any other program for editing .

For the Compilation List of my GF Scripts , you can search in:
https://forums.bohemia.net/forums/topic/215850-compilation-list-of-my-gf-scripts/
*/


if (GF_AP_Systemchat_info) then {
systemchat "GF_Auto_Population_Remover Initializing";
};


if (GF_AP_Diag_Log_info) then {
diag_log "//________________	GF_Auto_Population_Remover.sqf	_____________";
diag_log "//________________ GF_Auto_Population_Remover Initializing _____________";
};


[]spawn	{
	while {true} do {

		uisleep GF_AP_Remover_Loop;
		_list = GF_AP_centerPosition nearEntities [["Man", "Air", "Car", "Ship", "Tank"], worldSize];	
							
		_Exclude_List = [
		"examle_classname..."
		]; 
		
		{	
		_Entity = _x;
		if (
	
			(isNull(attachedTo _Entity)) 
			&& (alive _x)
			&& (!((typeOf _x) in _Exclude_List))  
			&& (_x getVariable ["Var_GF_AP_Spawn",true])
			&& {(({((_x distance _Entity) < GF_AP_Remover_Distance)}count GF_AP_allPlayers)isEqualTo 0)} 
			
		) then {
		_list = _list - [_x];
		deleteVehicle _x};
		}forEach _list;
				
		if (GF_AP_Systemchat_info) then {
		systemchat "GF_AP_Remover_Loop";
		};
		
	};	
};


if (GF_AP_Systemchat_info) then {
systemchat "GF_Auto_Population_Remover Initialized";
};


if (GF_AP_Diag_Log_info) then {
diag_log "//________________ GF_Auto_Population_Remover Initialized _____________";
};

 

 

Info:

You can set a Variable to your spawned unit and see the remover code up ,

in order not everything to get deleted.

 

  • Like 1

Share this post


Link to post
Share on other sites
46 minutes ago, pierremgi said:

You see the difference?

 

ups! yes that was sloppy:) thanks!

Share this post


Link to post
Share on other sites
16 hours ago, TURCO_AR said:

Thanks!

 

Welcome also to BI forum TURCO_AR !

#happy editing !!!  :f:

  • Like 1

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

×