Jump to content
Sign in to follow this  
Landa

spawn/despawn AI with triggers

Recommended Posts

Hello,

 

I'm working on a mission that will have alot of AI. So i have been trying to make it so AI despawn when you are > 1km away from the town they are in. I got a marker in the center of the town, and some markers around the town, so the AI got something to spawn on. This is how i tried to do it: (was going to screenshots the triggers, but don't arma on this pc i'm on, so this will do i hope :))

 

spawn ai trigger:

		expCond="(player distance getMarkerPos ""delf_zone"") < 40;";
		expActiv="null = [""Delfinaki""] execVM ""spawnai.sqf"";"; 

spawnai.sqf:

_town = _this select 0;
switch (_town) do {
	case "Delfinaki": {
		_delfgrp = createGroup east;
		delf_rifleman1 = "O_SOLDIER_F" createUnit [getMarkerPos "delf_rifleman1", _delfgrp, "", 0.75, "private"];
		
		delf_rifleman2 = "O_SOLDIER_F" createUnit [getMarkerPos "delf_rifleman2", _delfgrp, "", 0.75, "private"];
		
		delf_rifleman3 = "O_SOLDIER_F" createUnit [getMarkerPos "delf_rifleman3", _delfgrp, "", 0.75, "private"];
		
		delf_rifleman4 = "O_SOLDIER_F" createUnit [getMarkerPos "delf_rifleman4", _delfgrp, "", 0.75, "private"];

		delf_commander = "O_SOLDIER_F" createUnit [getMarkerPos "delf_commander", _delfgrp, "", 0.85, "captain"];

	};
};
 

despaw nai trigger:

		expCond="(player distance getMarkerPos ""delf_zone"") > 40;";
		expActiv="null = [""Delfinaki""] execVM ""despawnai.sqf"";"; 

despawnai.sqf:

_town = _this select 0;

switch (_town) do {
	case "Delfinaki": {
		deleteVehicle delf_rifleman1;
		deleteVehicle delf_rifleman2;
		deleteVehicle delf_rifleman3;
		deleteVehicle delf_rifleman4;
		deleteVehicle delf_commander;
	};
};

it spawns the ai when i get close to the town, but it doesn't despawn the ai when i get away from the town. Have been trying a few different things, but none of them worked. Any idea how i can do it? Don't need someone to send all the scripts (i hope), but just a point to the right direction. Thanks :)

 

Edit: Also in a bit of a hurry, so i might not have explained it fully.

Share this post


Link to post
Share on other sites

I have kind of a same problem. I'm trying to spawn units when the trigger is activated and despawn them when trigger is deactivated. The idea is to create civilian units in town when player is near but despawn them when player leaves. Spawning works fine, but it won't despawn the unit.

Here is the code, what did I do wrong:

 

03XQ9tzm.jpg

 

If i create a unit in editor, despawning works fine but it won't delete spawned units.

 

And another thing. I'm trying to spawn a unit facing a specific direction (looking at 180 degrees in example above) but when spawned, unit automatically turns to 0 degrees. Is there any way for a unit to remain facing the specific direction?

Share this post


Link to post
Share on other sites

Hello,

 

I'm working on a mission that will have alot of AI. So i have been trying to make it so AI despawn when you are > 1km away from the town they are in. I got a marker in the center of the town, and some markers around the town, so the AI got something to spawn on. This is how i tried to do it: (was going to screenshots the triggers, but don't arma on this pc i'm on, so this will do i hope :))

 

spawn ai trigger:

		expCond="(player distance getMarkerPos ""delf_zone"") < 40;";
		expActiv="null = [""Delfinaki""] execVM ""spawnai.sqf"";"; 

spawnai.sqf:

_town = _this select 0;
switch (_town) do {
	case "Delfinaki": {
		_delfgrp = createGroup east;
		delf_rifleman1 = "O_SOLDIER_F" createUnit [getMarkerPos "delf_rifleman1", _delfgrp, "", 0.75, "private"];
		
		delf_rifleman2 = "O_SOLDIER_F" createUnit [getMarkerPos "delf_rifleman2", _delfgrp, "", 0.75, "private"];
		
		delf_rifleman3 = "O_SOLDIER_F" createUnit [getMarkerPos "delf_rifleman3", _delfgrp, "", 0.75, "private"];
		
		delf_rifleman4 = "O_SOLDIER_F" createUnit [getMarkerPos "delf_rifleman4", _delfgrp, "", 0.75, "private"];

		delf_commander = "O_SOLDIER_F" createUnit [getMarkerPos "delf_commander", _delfgrp, "", 0.85, "captain"];

	};
};
 

despaw nai trigger:

		expCond="(player distance getMarkerPos ""delf_zone"") > 40;";
		expActiv="null = [""Delfinaki""] execVM ""despawnai.sqf"";"; 

despawnai.sqf:

_town = _this select 0;

switch (_town) do {
	case "Delfinaki": {
		deleteVehicle delf_rifleman1;
		deleteVehicle delf_rifleman2;
		deleteVehicle delf_rifleman3;
		deleteVehicle delf_rifleman4;
		deleteVehicle delf_commander;
	};
};

it spawns the ai when i get close to the town, but it doesn't despawn the ai when i get away from the town. Have been trying a few different things, but none of them worked. Any idea how i can do it? Don't need someone to send all the scripts (i hope), but just a point to the right direction. Thanks :)

 

Edit: Also in a bit of a hurry, so i might not have explained it fully.

 

Why don't  you place units somewhere on the other side of the map, then when you get into the trigger simply use setPos command? It works fine, and doesn't cause any performance errors. You can also hide units via commands this hideobject true; and this enablesimulation false; At deactivation trigger, you can use deleteVehicle this; command.

Share this post


Link to post
Share on other sites

The problem is, at least for me, that deleteVehicle command doesn't work for spawned unit on trigger deactivation.

Share this post


Link to post
Share on other sites

Also I tried witout underscore:

 

Zmy7C0Am.jpg

 

but it doesn't work. it gives me this error:

 

OUHAXWBm.jpg

Share this post


Link to post
Share on other sites

trigger settings:

 

bluefor

present

repeatable

 

 

on activation:

grp1 = [(position thistrigger), 3] call 
{
   _grp = creategroup east; 

   for "_i" from 1 to (_this select 1) do 
   {
      _unit = "O_SOLDIER_F" createUnit [_this select 0, _grp, "", 0.75, "private"];
   }; 
   _grp
};

on deactivation

{deleteVehicle _x} foreach (units grp1)

make sure "grp1" is unique for each trigger.

 

i personally would not use triggers and spawn a loop for checking instead to be able to use a less aggressive delay like 5-10 secs but this should work. haven't tested though.

Share this post


Link to post
Share on other sites

thx. I tested it and it works except it isn't repeatable. units spawn on activation, despawn on deactivation, but they do not spawn on reactivation. I checked repeatable option.

 

ok, let me explain exactly what I would like to do. Bear in mind that I'm new to scripting and don't really know the sytax very well. All I know is from examples I found.

My idea was to put markers all over the town on which civilians would spawn when players approach and despawn when players leave, all for better performance and to avoid 144 groups limit. Also I would like each of them to face a specific direction (in azimuth degrees) and some of them to do an animation if possible so it would look more realistic.

can you give me an example for just one guy, I'll figure out the rest.

 

for example i created marker named "marker_1" and spawned a unit with your code via trigger:

 

on activation

civ1 = [(getMarkerPos "marker_1"),1] call   
{  
   _grp = creategroup civilian;   
  
   for "_i" from 1 to (_this select 1) do   
   {  
      _unit = "C_man_1" createUnit [_this select 0, _grp, "", 0.5, "private"];  
   };   
   _grp  
}; 

on deactivation

{deleteVehicle _x} foreach (units civ1); 

How would I make him face, let's say 180 degrees (looking south) and for example make him sit low?

 

Is there maybe a simpler way to do all of this?

Share this post


Link to post
Share on other sites

 

thx. I tested it and it works except it isn't repeatable. units spawn on activation, despawn on deactivation, but they do not spawn on reactivation. I checked repeatable option.

 

you are doing it wrong then. i just tested my code and it works just fine endlessly looping.

 

here's the trigger:

 

http://images.akamai.steamusercontent.com/ugc/267221800536150997/7AFC5AD5B8A4D6D4E920F73ECB619E0B63599071/

 

 

also be aware that triggers will run their code on every machine in MP. so make sure to wrap it all inside an isServer check. no worries about SP. isServer should be true in SP iirc.

 

 

if (isServer) then

{

   stuff here

};

Share this post


Link to post
Share on other sites

Yeah I fugured why it didn't loop. I had 143 groups already in the mission so it spawned unit once and reached the limit of 144 units. but when the unit despawned it obviously didn't delete the group unit was in. So on reactivating the trigger it didn't spawn the unit because of the 144 groups limit and that is exactly what I would like to avoid.

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  

×