Jump to content
Sign in to follow this  
edathome1982

AI Squad respawn problem.

Recommended Posts

I am currently trying to make an ALiVE mission. I want my fallen team members to respawn at a preset location.

I have searched hundreds or respawn and AI spawn codes but cannot find what I am looking for.

I have John, James, Jo, Fred, Ted and Tommy in my squad. Each is a specific class, Ted is a Combat Medic for example.

I want a script that would either on radio or within a FOB area call and check if John, James, Jo, Fred, Ted and Tommy are alive. If they are not replace the units that are not there, as the class they were originally. So Ted dies and respawns as a Combat Medic, Jo the machine Gunner respawns as a Machine Gunner.

Would also like if the script could drop them to my location via helo insertion.

As I said I have looked in numerous places, but can't find specifically what I need. I know roughly how to get Ted to respawn at a marker and then join group, but if I have 3 squad members down, I'm lost. Scripting not really my strong point lmao.:j:

Share this post


Link to post
Share on other sites

Give each unit a Killed Event Handler that either calls or contains the scripting needed to respawn the unit, with the arguements passed by the EH you should easily be able to get the unit's class type.

Share this post


Link to post
Share on other sites

I just made this account because I want to ask a question somewhere else in this board but for whatever reason apparently I have to make several replies in order to do it.

That's pretty damn annoying, if you ask me.

Share this post


Link to post
Share on other sites
... I want a script that would either on radio or within a FOB area call and check if John, James, Jo, Fred, Ted and Tommy are alive. If they are not replace the units that are not there, as the class they were originally. So Ted dies and respawns as a Combat Medic, Jo the machine Gunner respawns as a Machine Gunner...

init.sqf

grpArray = [];

{
grpArray pushBack [ _x, ( typeOf _x ) ];
} forEach units myGrp;

player addAction ["Group Check", "grpCheck.sqf" ]; // Or radio trigger >> 0 = execVM "grpCheck.sqf"

grpCheck.sqf

{
if ( ! ( alive ( _x select 0 ) ) ) then {
	_unit = ( myGrp ) createUnit [ ( _x select 1 ), getPosATL myPos, [], 0, "NONE"];
};
} forEach grpArray;

grpArray = [];

{
grpArray pushBack [ _x, ( typeOf _x ) ];
} forEach units myGrp;

// - - Helo stuff

Where myGrp is the name of the group and myPos is the name of an object (empty helper object). Cheers.

Note: For automatic respawn you could simply host the mission, make the units playable, and setup a simple respawn marker. They will respawn automatically.

---------- Post added at 16:28 ---------- Previous post was at 16:19 ----------

Updated to reset the array.

Edited by Iceman77

Share this post


Link to post
Share on other sites

Thanks Iceman, will have a look at this in the morning. If I stay here trying to sort this out now, I'm going wake up with keyboard imprint on my face lol.

I assume For the array I name each unit then grpArray = ["John","James","Jo","Fred","Ted","Tommy"]; sorry brain = hurting right now..

Share this post


Link to post
Share on other sites

It's already making the team / group member array for you. All you've to do is name the group (myGrp). And name an object (myPos) and place it where you would like the units to spawn at.

Share this post


Link to post
Share on other sites

init.sqf

grpArray = [];

{
grpArray pushBack [ _x, ( typeOf _x ) ];
} forEach units ALPHA

player addAction ["Group Check", "grpCheck.sqf" ]; // Or radio trigger >> 0 = execVM "grpCheck.sqf"

groupCheck.sqf

{
   if ( ! ( alive ( _x select 0 ) ) ) then {
       _unit = ( ALPHA ) createUnit [ ( _x select 1 ), getPosATL Mk1, [], 0, "NONE"];
   };
} forEach grpArray;

grpArray = [];

{
   grpArray pushBack [ _x, ( typeOf _x ) ];
} forEach units ALPHA;

// - - Helo stuff 

I have tried to get this to work, my brain is seriously not wanting to work. I have created a marker named MK1 and ALPHA = group this; in my players init field.

I get the addaction when I preview the mission. Kill a squad member and nothing happens. I have tried using radio trigger and the add action. I get nothing.....

I cannot help but feel like I am missing something here

Share this post


Link to post
Share on other sites

Why are there html (php?) color tags all over the scripts? I tested what I wrote. So I know it works =)

Edited by Iceman77

Share this post


Link to post
Share on other sites

They gone now lol, I was trying to hi-light what I had changed, then decided to put it in PHP and forgot to remove them. lol

Share this post


Link to post
Share on other sites

If you're using a marker instead of an object for the position use:

getMarkerPos "Mk1"

Also, nothing happens when you kill the team member. It's when you use the action or radio (afterwords) that the code will evaluate the group members.

Share this post


Link to post
Share on other sites

That's what I meant by I have tried using the radio and the add action. Sorry if I wasn't clear there.

Share this post


Link to post
Share on other sites

I have had time to play and get this to work. I must have fudged something up when I changed the Marker names and group name.

My next problem is..... what variable do I need to use to get the re-spawned unit into a Helo?

wp1 = _unit addWaypoint [getmarkerpos "marker1", 0];
wp1 setWaypointType "load";

Helo is sat on pad in FOB waiting unit to load then drop to my position.

If I used name of unit from editor would that carry over to the spawned unit? I could perhaps use that to load the Helo?

Share this post


Link to post
Share on other sites

It depends. Are these events taking place where player(s) can see and you want the units to run up to the helo and get in? Or are these events out of site to players where you could simply move the unit(s) into the vehicle?

Share this post


Link to post
Share on other sites

Its a single player mission.

I am playing on large map so I have a few FOB where I want the AI to spawn at my location (as the script is written).

Trigger will be attached to an item or proximity.

but...

Its an insurgency style mission. So if I'm not near a FOB I wanted the AI to spawn in a Helo then be inserted at my location. Hence the radio trigger in my original idea.

Share this post


Link to post
Share on other sites

If its easier yeah. That way I could just have the helo land where ever I am. Limiting it all to 1 script.

Share this post


Link to post
Share on other sites

It's easier but looks terrible. ie; the units spawning and getting teleported into the vehicle rather than running and getting in. Why I was wondering how you would like to do it.

Share this post


Link to post
Share on other sites

OK lets go with running and getting in. I am much appreciative of this too. Rest of the mission so far has been quite easy. lol

Share this post


Link to post
Share on other sites

Example Mission:

new_logo_shmodel-vfl9sSGTp.png

grpCheck.sqf

// SET LOCAL VARIABLES SCOPE
private ["_helo","_unit","_hPad","_heloWp"];

// CREATE THE HELO AND HPAD.
_helo = [getMarkerPos "Mk1", markerDir "Mk1", "B_Heli_Transport_01_F", WEST] call bis_fnc_spawnVehicle;
_hPad = "Land_HelipadEmpty_F" createVehicle ( position player );

// CHECK THE GROUP AND REPLACE DEAD UNITS. MOVE THEM INTO THE HELO'S CARGO
{
   if ( ! ( alive ( _x select 0 ) ) ) then {
       _unit = ( ALPHA ) createUnit [ ( _x select 1 ), getMarkerPos "Mk1", [], 0, "NONE" ];
	_unit moveInCargo ( _helo select 0 );
   };
} forEach grpArray;

// RESET THE ARRAY
grpArray = [];

{
grpArray pushBack [ _x, ( typeOf _x ) ];
} forEach units ALPHA;

// GIVE THE HELO A WAYPOINT AT THE HPAD'S POSITION (PLAYER POS)
_heloWp = ( _helo select 2 ) addWaypoint [_hPad, 0];
_heloWp setWaypointType "MOVE";
_heloWp setWaypointBehaviour "CARELESS";
_heloWp setWaypointCombatMode "BLUE";
_heloWp setWaypointSpeed "FULL";
_heloWp setWaypointStatements ["true", "(vehicle this) LAND 'LAND';"];

// WAIT UNTIL THE HELO IS TOUCHING THE GROUND OR CAN'T MOVE (SHOT DOWN / WRECK) ANDD EJECT THE UNITS
waitUntil {isTouchingGround (_helo select 0) || { !( canMove ( _helo select 0 ) ) } };

{
unAssignVehicle _x; 
_x action ["eject", ( vehicle _x )]; 
sleep 1;
} forEach units ALPHA; 

//WAITUNTIL THERE'S NO ALIVE GROUP MEMBERS IN THE HELO AND GIVE THE HELO A NEW WAYPOINT WHERE IT WILL BE DESTROYED
waitUntil { { !( alive _x ) || { !( _x in ( _helo select 0 ) ) } } count ( units ALPHA ) == count ( units ALPHA ) };

_heloWp = ( _helo select 2 ) addWaypoint [[0,0,0], 0];
_heloWp setWaypointType "MOVE";
_heloWp setWaypointBehaviour "AWARE";
_heloWp setWaypointCombatMode "RED";
_heloWp setWaypointSpeed "FULL";
_heloWp setWaypointStatements ["true", "{deleteVehicle _x;} forEach crew (vehicle this) + [vehicle this];"]; 

// DELETE THE EMPTY H-PAD
deleteVehicle _hPad;

---------- Post added at 18:03 ---------- Previous post was at 16:15 ----------

Updated. Used your variables. Using a marker instead of an object ( I forgot ). Included an example mission with radio trigger. Should be plug n' go.

Edited by Iceman77

Share this post


Link to post
Share on other sites

Sorry to dig up and old post. I put this script into an ALiVE mission I'm making, and it works great, right up until I put it on my TADST server. Then for some reason there are 2 helicopters spawned on top of each other, and they crash. The same thing happens with included sample mission. 

 

Could this be attributed to that for some reason I have 2 TADST servers on my LAN that show up since the last update? I can't figure out why there are duplicate servers either. 

 

Thanks

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  

×