Jump to content
Sign in to follow this  
majorpain1588

Scripting Help - Respawning AI units

Recommended Posts

ok guys I've been working with this all night and could use some help.

I am trying to make a script that works like this:

1. All members of AI infantry group die

2. after a short delay a new AI infantry group spawns at a marker

3. the new group follows waypoints back to the battle.

I've had it work where individual soldiers die and respawn by themselves, but I would like groups to respawn. The big thing is knowing when all group members are dead and then spawning the group. This is where I am at right now, but it doesn't work...

In squad leaders init field:

nul = [this, 3, 10, "east_spawn"]execVM "AI_respawn\AI_respawn_init.sqf"; 

Script file:

if (!isServer) exitWith {};

_unit 			= _this select 0;
_lives			= _this select 1;
_delay 			= _this select 2;
_respawn_point	= _this select 3;

_name = call compile format ["%1", _unit];
_type 			= typeOf _name;
_group 			= group _name;
_weapons 		= weapons _name;
_mags 			= magazines _name;

waitUntil ({alive _x} count units _group < 1);

if (_lives == 0) exitWith {};

_lives = _lives - 1;

_wait = Time + _delay;
waitUntil {Time > _wait};

_randA = random 50;
_randB = random 50;

_posA = getMarkerPos _respawn_point;
_posB = [(_posA select 0) + (_randA), (_posA  select 1) + (_randB)]; 

_skill = [0.3, 0.5];
_side = EAST;
_units = ["RU_Soldier_SL", "RU_Soldier_TL", "RU_Soldier_AR", "RU_Soldier_MG", "RU_Soldier_LAT", "RU_Soldier_GL", "RU_Soldier", "RU_Soldier"];

_newGroup = [_pos, _side, _units, [], [], _skill] call BIS_fnc_spawnGroup;

sleep 1;

_newGroup addwaypoint[getmarkerpos"East_WP1",0]
[_newGroup,1] setwaypointtype"Move"; 
_newGroup addwaypoint[getmarkerpos"East_WP2",1]
[_newGroup,1] setwaypointtype"Move"; 


if (true) exitWith {};

Maybe that code can be fixed or maybe there is something way easier. I am new to this.

Thanks

Share this post


Link to post
Share on other sites

This feature was in the first lot of scripts I posted the link to in your thread yesterday: http://www.norrin.org/downloads/misc_scripts/ai_ups_051108d.intro.rar

The difference between the two scripts is that this one uses Kronzky's UPS script to move the units after they have respawned (You can also respawn vehicles with this script).

I can add it to the scripts you are currently using but not sure when I'll get a chance to do this, maybe tonight when I get home from work.

What you need to do to is check whether the respawned unit is the group leader and if it is then add the waypoints.

So you need to add something like this to the end of the respawn script AI respawn and move to map position script.

_name disableAI "MOVE";
waitUntil {(leader _group) distance (getMarkerPos _respawn_point) < 50 || isNull  (leader _group)};
_name enableAI "MOVE";
sleep 2;
if (_name == leader _group || isNull  (leader _group)) then
{ 	
[_name] execVM _move_script;
};

PS: Possibly would have been a good idea to keep this in the same thread as your previous question as its all related, that way if someone has a similar question all the info is in one thread.

Edited by norrin

Share this post


Link to post
Share on other sites

AI respawn as group and move to WP script

© JULY 2009 - norrin

Description

Creates a respawning group of non-playable AI that moves to waypoints. The units will only respawn when the whole group is dead and then will move off as a group.

Download

http://norrin.org/downloads/ArmA2/AI_respawn/AI_respawn_WP_grp.utes.rar

To implement:

1. Copy the AI_respawn folder to your mission directory

2. Create a group of AI units that will respawn in the editor

3. in the init line of the leader of the AI group put:

nul = [this, 3, 10, "east_spawn","East_WP.sqf"] execVM "AI_respawn\AI_respawn_init.sqf";

where:

3 - is the number of times you want the AI unit to respawn;

10 - is the delay in seconds after the unit dies that you want it to respawn in

"east_spawn" - is the marker postion wher you want the AI units to respawn

"East_WP.sqf" - is the name of the script that will give the AI units their waypoints.

In the test mission I have put the waypoint script in the mission directory it is called

"East_WP.sqf"

It commands the units to move to WPs created at markers. In the test mission the WP markers for AI units are called:"East_WP1" and "East_WP2" and the code looks like this:

_unit = _this select 0;
_group = group _unit;

_waypoint0 = _group addwaypoint[getmarkerpos"East_WP1",0];
_waypoint0 setwaypointtype"Move"; 

_waypoint1 = _group addwaypoint[getmarkerpos"East_WP2",0];
_waypoint1 setwaypointtype"Move"; 

Adapt this script to your own purposes. For instance you can add additional WP markers or you could have several of these scripts in the mission so different units moveTo different positions.

Note the respawning AI units are created as the same type, with the same loadout as they started the mission with and their skill is set to the same level as set in the editor

@Major - there's a few syntax errors in your code mate that may explain why it isn't working, for instance the code that you have as this

waitUntil ({alive _x} count units _group < 1);

possibly should look like this

waitUntil {{!alive _x} forEach (units _group)};

(untested). You're also missing some semi-colons from the ends of some lines and added the waypoints incorrectly (see code above for guide).

Share this post


Link to post
Share on other sites

So....

...Any way to spice it up with a bit o' the good ol' UPS?

Share this post


Link to post
Share on other sites
So....

...Any way to spice it up with a bit o' the good ol' UPS?

AI respawn with UPS (both soldiers and manned vehicles):

http://www.norrin.org/downloads/misc_scripts/ai_ups_051108d.intro.rar

I haven't had a chance to try these scripts in ArmA2 yet but they should work. Comprehensive notes for implementing the scripts are contained in the rar file. Also you'll need to replace the UPS in the download with Kronzky's latest (see: http://kronzky.info/ups/index.htm )

Share this post


Link to post
Share on other sites

Norrin, as sual your scripts are top notch!

It works great for infantry .. any chance of similar vehicle respawn scripts for tanks/plans?

Thanks for great scripts!

Share this post


Link to post
Share on other sites

Norrin, Thanks for the scripts and code tips. All I know is basic c++, so this scripting syntax has some elements that are new.

Share this post


Link to post
Share on other sites

@MP - NPs, if you've got a background in C++ once you get your head around the syntax you'll be scripting in no time mate :)

@CaptainBravo, the AI respawn UPS script linked to a couple of posts back allows for respawning of AI ground vehicles that use UPS to patrol an area. Its a little more complicated as you have to respawn the vehicle then the crew separately. When I get a chance I'll update the UPS/AI respawn scripts so there's an ArmA2 example you can try. When I do this I'll also make a more simple AI vehicle respawn script that just moves the vehicle to some fixed waypoints.

Share this post


Link to post
Share on other sites

Thanks norrin. Would by any chance those vehicle scripts work for planes/halos as well? or is that a totally different animal?

Thanks.

Share this post


Link to post
Share on other sites

AI respawn as group and patrol an area using Kronzky's UPS script

This is an updated version of the ArmA script for foot soldiers. I'll start work on updated scripts for respawning AI ground vehicles and planes shortly.

Download

http://norrin.org/downloads/ArmA2/AI_respawn/aiRespawnUPS.Chernarus.rar

To implement:

1. Copy Kronzky's UPS script and the AI_respawn_UPS folder to your mission directory

2. Create a group of AI units that will respawn in the editor

3. in the init line of the leader of the AI group put:

nul = [this, 3, 10, "ES1","East_WP1"] execVM "AI_respawn_UPS\AI_respawn_UPS_init.sqf";

where:

3 - is the number of times you want the AI unit to respawn;

10 - is the delay in seconds after the unit dies that you want it to respawn in

"east_spawn" - is the marker postion where you want the AI units to respawn

"East_WP1" - is the name of the marker that the units will patrol using Kronzky's UPs script.

Note the respawning AI units are created as the same type, with the same loadout as they started the mission with and their skill is set to the same level as set in the editor. Also in the test mission the player is setCaptive true so the enemy units will not shoot him.

Share this post


Link to post
Share on other sites

Nice script. But how about.. get in the vehicle after new respawn? If there is no vehicle, move to the next waypoint. Or respawn in the vehicle/on the ship (LHD). In a certain altitude with parachute? For ArmA II.

Share this post


Link to post
Share on other sites

This is a cheeky add on to this discussion as no answers to my thread regarding this issue.

Its along similar lines to the previous discussion, except I do not want to use the respawn option, I want to call external scripted reinforcements on the conditions of a trigger until the trigger is deactivated by the destruction of a radio antenna.

Problem is the unit is called in but does not then go to patrol using the ups.

Also because I expect of my poor scripting, the reinforcement script does not trigger as I would expect.

I have a Marker set up call Kom

Within this market I have 3 groups deployed via the editor and given the following init line

nul=[this,"Kom"] execVM "ups.sqf"

These correctly patrol using the UPS script :yay:

I have a second marker called RKom placed some distance behind the village

I have a trigger that Switches on the Not Present of OPFOR with an On Act of

[] exec "Reinf0.sqf"

In the mission folder I have a Reinf0.sqf file as shown below

GroupAlpha1 = CreateGroup East;

_unit = GroupAlpha1 createUnit ["RU_Soldier_SL", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

leader=1;

rank="LIEUTENANT";

skill=0.59999996;

nul=[this,"Kom"] execVM "ups.sqf";

_unit = GroupAlpha1 createUnit ["RU_Soldier_MG", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="SERGEANT";

skill=0.46666664;

_unit = GroupAlpha1 createUnit ["RU_Soldier_AT", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="rank="SERGEANT";

skill=0.46666664;

_unit = GroupAlpha1 createUnit ["RU_Soldier_LAT", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="CORPORAL";

skill=0.33333331;

_unit = GroupAlpha1 createUnit ["RU_Soldier_Marksman", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="CORPORAL";

skill=0.33333331;

_unit = GroupAlpha1 createUnit ["RU_Soldier_MG", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="CORPORAL";

skill=0.33333331;

_unit = GroupAlpha1 createUnit ["RU_Soldier_LAT", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="CORPORAL";

skill=0.33333331;

_unit = GroupAlpha1 createUnit ["RU_Soldier_AR", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="CORPORAL";

skill=0.33333331;

_unit = GroupAlpha1 createUnit ["RU_Soldier_AR", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="CORPORAL";

skill=0.33333331;

_unit = GroupAlpha1 createUnit ["RU_Soldier_GL", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="CORPORAL";

skill=0.33333331;

_unit = GroupAlpha1 createUnit ["RU_Soldier_GL", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="CORPORAL";

skill=0.33333331;

_unit = GroupAlpha1 createUnit ["RU_Soldier_AR", [(getMarkerPos "RKom") select 0,(getMarkerPos "RKom") select 1,0], [], 3, "FORM"];

rank="CORPORAL";

skill=0.33333331;

I have an OPFOR Player character start inside the trigger, stopping it from activating.

When I move outside the trigger, the Squad shown above spawns BUT it faisl to respond to the init call to the UPS. Also I just try using waypoints they also fail to respond. :mad:

Please can someone show me how to put the UPD init into the Reinf0.sqf above :o

Also I would appreciate help on cleaning up the Reinf0.sqf file above, I expect its not a very clean way to create the troops :D

Share this post


Link to post
Share on other sites

Respawning AI vehicles that patrols an area using Kronzky's UPS script

JULY 2009 - norrin

Kronzky's fabulous UPS script is available here: http://kronzky.info/ups/index.htm

Download

http://www.norrin.org/downloads/ArmA2/AI_respawn/AIvclRespawn_UPS.utes.rar

To implement:

1. Copy Kronzky's UPS script and the AIvcl_respawn_UPS folder to your mission directory

2. Create a manned AI vehicle that will respawn in the editor

3. in the init line of the vehicle put:

nul = [this, 3, 10, "WS1","WM1"] execVM "AIvcl_respawn_UPS\AIvcl_respawn_UPS_init.sqf";

where:

3 - is the number of times you want the AI unit to respawn;

10 - is the delay in seconds after the unit dies that you want it to respawn in

"WS1" - is the marker postion where you want the AI units to respawn

"WM1" - is the name of the marker that the units will patrol using Kronzky's UPs script.

Note

* Each respawning AI vehicle needs to have the above code put in its init line.

* The respawning AI vehicles are created as the same type and their skill is set to the same level as set in the editor

Also in the test mission the player is setCaptive true so the enemy units will not shoot him.

Finally, before someone asks yes this does work for choppers and planes (see TEST mission).

@Starlight, once you have spawned your squad, ie. at the end of the code, put this

_leader = leader  GroupAlpha1;
[_leader,"Kom"] execVM "ups.sqf";

Share this post


Link to post
Share on other sites

Thanks a lot Norrin, I still had problems, but tried a much cleaner set of createUnit scripts and its works :yay:

My next Question :D

I have a trigger defined as below:

{

position[]={3849.4863,6.7362819,2562.5608};

a=20;

b=20;

activationBy="EAST";

activationType="NOT PRESENT";

repeating=1;

timeoutMin=5;

timeoutMid=10;

timeoutMax=15;

age="UNKNOWN";

name="Trig2";

expCond="this && alive Ant0";

expActiv="[] exec ""ReinfT.sqs""";

class Effects

{

};

The hope if for the Trigger to keep firing off reinforcements between every 3 and 15 seconds when there are no OPFOR inside the trigger area until the Antenna "Ant0" is destroyed.

At the moment it only triggers when an OPFOR leaves the area, and then comes back inside and leaves again :confused:

Any help appreciated :D

Share this post


Link to post
Share on other sites

The code is great :) But is there any way to spawn jets in air , because after first crash A10`s for example starting spawn on the ground ,and this makes alot of problems for me , for AI south airfield is to short to get a10 off the ground ,so just by trying getting off they smashes into the trees etc etc . :(

Share this post


Link to post
Share on other sites

Is there any way/value to let ai respawn infinite number of times ,instead of setting enormous number of spawns?I got some problems after,i`ve setted the numer of respawns for Ah1Z/mi-24 and Mi-8 choppers to 2000 and delay to 1600 seconds ,after 10 - 20 respawns ai don`t wanna spawn anymore so i need a value to put in init wich will make them spawn infinite.Help plz :)

P.S. i found the enemy choppers on their spawn point on the base , they were just standing there on the ground ,but without a crew.What could be the problem?

Also i found that after spawning enemy /friendly bmp3 ,and if i destroy it ,bmp3 spawns correctly with all the crew near it(commander,driver,gunner,2 guys for in cargo) ,but only 3 of them getting inside and 2 guys are not getting in to the cargo , i saw it in the script that script commands to get in into a vechicle only to a gunner,commander and driver, have tried to fix it buy adding "_guys moveInCargo [_vec,1]" but it doesn`t work.Any ideas?

---------- Post added at 02:35 AM ---------- Previous post was at 01:27 AM ----------

I found some of the pilots on the map,that have ejected on the long distances from the place i`ve shot them down(plane,heli)after several times of respawn they are running all over the map and this could be the course of failure to spawn near choppers/vehicles.looks like thier count getting to the max , so to let them respawn you need to search a whole map and kill all of them to let them respawn again.

Edited by Oleg-Russia

Share this post


Link to post
Share on other sites

I am trying to modify the group spawn script to make the spawnpoint random. I have modified it as follows:

_unit 			= _this select 0;
_lives			= _this select 1;
_delay 			= _this select 2;
_markerarray = ["marker1", "marker2", "marker3", "marker4", "marker5", "marker6", "marker7", "marker8"];
_respawn_point	= _markerarray select (floor(random(count _markerarray)));
_move_script	= _this select 3;
_unitsGroup 	= units (group _unit);
_side 			= side _unit; 

etc... (the rest is the same)

did a similar thing with the respawn sqf

Doesn't work - the unit just spawns where I place him on the map rather than randomly, moves to his waypoint and does not respawn after dying.

Can someone push me in the right direction please.

Share this post


Link to post
Share on other sites

This doesn't seem to work any more! I had it working no problem, but today it won't. The only thing I've changed is installing 1.03 patch, I've tried downloading again from the link posted by norrin but its not happening :386: anyone else getting this, or answers anybody?

:banghead: also this doesn't work any more

 _leader = leader  GroupAlpha1;
[_leader,"Kom"] execVM "ups.sqf";

when I spawn a squad with a script!

Share this post


Link to post
Share on other sites

I can confirm that the original scripts provided by norrin still function as intended. Although I am currently running the latest beta, I did not notice anything different in 1.03 while working on a couple missions that use the script.

:suspicious:

Edited by [S8S] Vapor
Poor Grammer

Share this post


Link to post
Share on other sites

Well this is weird, they won't patrol any more with norrin's UPS respawn script, they respawn but won't patrol. UPS is working on its own as normal......wait one.....:icon_rolleyes: its the norrin POW script :scratchchin: why does that conflict.

Tried calling the POW script many different ways there would seem to be some sort of conflict going on, I don't have the brain to understand what, but when its called it stops the UPS. I'll ask norrin about it. Unless anyone else has an answer to it.

Edited by Padjur
Removal of unnecessary info.

Share this post


Link to post
Share on other sites

Norrin about your AI respawn as group and move to WP script.

Can I (or can it be done?) set the units behavior like normal waypoints do in the editor.

I have got the script to set their speed, but the behavior is not working. Also I'm working with your AI respawn as group and move to WP script.

Here is what I've done to the East_WP.sqf so far;

speed worked, but behavior did not.

_unit = _this select 0;

_group = group _unit;

_waypoint0 = _group addwaypoint[getmarkerpos"EST_SD0",0];

_waypoint0 setwaypointtype"Move";

_waypoint0 setwaypointspeed"LIMITED";

_waypoint0 setwaypointcombat"STEALTH";

_waypoint1 = _group addwaypoint[getmarkerpos"EST_SD1",0];

_waypoint1 setwaypointtype"Move";

_waypoint1 setwaypointspeed"LIMITED";

_waypoint1 setwaypointcombat"STEALTH";

_waypoint2 = _group addwaypoint[getmarkerpos"EST_SD2",0];

_waypoint2 setwaypointtype"Cycle";

_waypoint2 setwaypointspeed"LIMITED";

_waypoint2 setwaypointcombat"STEALTH";

For the scripts, they work very good!

And you always give good read me s, Thank you for your time!

Edited by adamant

Share this post


Link to post
Share on other sites

I use these scripts a lot, and like them, but...

Has anyone been able to edit the scripts so that if the vehicle is abandoned, not destroyed, then the vehicle will be destroyed by a spawned munition or something. The AI will sometimes damage the vehicle so much (by running into walls or trees) that they abandon the vehicle on the battlefield thus disallowing the vehicle to respawn.

Share this post


Link to post
Share on other sites
I use these scripts a lot, and like them, but...

Has anyone been able to edit the scripts so that if the vehicle is abandoned, not destroyed, then the vehicle will be destroyed by a spawned munition or something. The AI will sometimes damage the vehicle so much (by running into walls or trees) that they abandon the vehicle on the battlefield thus disallowing the vehicle to respawn.

You got a problem with this though: What happens if the AI abandons a vehicle, then a player enter it? Technically its been abandoned and should be destroyed but I dont think the player would appreciate exploding ;)

Either way, it should be easy to add via a getOut eventhandler if need be.

Share this post


Link to post
Share on other sites

Does any one know if Rommel s RMM Reducer will be effected by AI respawning? Looked for his thread, but did not find it...

Share this post


Link to post
Share on other sites

Hi,

i use the your "AI vehicle respawn move via waypoints" Script as Reinforcement Tank Script.

The units will only respawn when the whole group is dead
This is the same for Vehicle Script or only single Veh. respawning ?

I need the same like AI Units respawn for the Vehicles. Can you help me please ?

THX Greetings Thunder

and another Noob Question: is it possible to respawn the AI Units with the same given Name ?

I cant get them after respawn under HC control :(.

Edited by [J4F] Thunder666

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  

×