Jump to content
Sign in to follow this  
Militant1006

Spawning on other players in your Squad

Recommended Posts

Hey guys, another complex question, has anyone used a script or knows a link that shows how to spawn on other players in your squad? I'm making a coop that requires being able to spawn on other players in your squad while deep behind enemy lines, there will be no AI in the Players' squad, so I need a script that allows spawning on other people in the game after 1 minute of being dead.

Cheers.

Share this post


Link to post
Share on other sites

This is not complex :)

Init.sqf

RAM = execVM "RespawnAtMate.sqf";

RespawnAtMate.sqf

if (!(local player)) exitWith {};

while {true} do {

// --- Wait until dead and respawned
waitUntil {!(alive player)};
WaitUntil {(alive player)};

// --- Lookup which teammate is alive
if (!(isNil "Mate1") && (alive Mate1)) then {
	_AliveMate = Mate1;
};
if (!(isNil "Mate2") && (alive Mate2)) then {
	_AliveMate = Mate2;
};
if (!(isNil "Mate3") && (alive Mate3)) then {
	_AliveMate = Mate3;
};

// --- Move to alive mate 
player setPos [(getPos _AliveMate select 0)-2*sin(random 359),(getPos _AliveMate select 1)-2*cos(random 359)];
};

Mate1, Mate2, etc. are the unit names set in the editor.

Edited by sxp2high

Share this post


Link to post
Share on other sites

Thanks man!, I will have to test it out, I tried to do group respawn but failed miserably, although the mission we did went well, no one died, thanks to contact drills. ;)

Share this post


Link to post
Share on other sites

sxp2high, hi. (Hi, all.)

I'm going to check this out in the near future, to see if I can get it working right.

BTW, what's with the fake tittied breasted girl in your sig? :p Heh. I guess just because she is saluting?

EDIT: HEY! She disappeared! :)

Edited by CyOp

Share this post


Link to post
Share on other sites

init.sqf

if (not isdedicated) then {
waituntil {not isnull player};

player addeventhandler ["respawn", {
	{
		if (alive _x) exitwith {player setpos (_x modeltoworld [0,-2,0]);};
	} foreach (units player);
}];
};

Respawns player BEHIND the first team mate (numerically, ie unit '1' will be first checked).

There is no safeguards against vehicles, or players flying, or players in water.

All easily added however, just change the if condition statement to:

( (alive _x) && !(surfaceIsWater (getpos _x)) && (vehicle _x == _x) && (speed _x < 20) )

You could also add a ability to spawn in the squad vehicle if available, this may require a more elaborate handle of the situation, see below:

init.sqf

if (not isdedicated) then {
waituntil {not isnull player};

player addeventhandler ["respawn", {
	{
		if ( (alive _x) && !(surfaceIsWater (getpos _x)) && (speed _x < 20) ) then {
			if (vehicle _x == _x) then {
				player setpos (_x modeltoworld [0,-2,0]);
				_rsp = true;
			} else {
				player moveincargo (vehicle _x);
				if (vehicle player != player) then {
					_rsp = true;
				};
			};
		};
		if (_rsp) exitwith {};
	} foreach (units player);
}];
};

Share this post


Link to post
Share on other sites

thanks romm, sounds good, personally I don't need to worry about spawning in the air or out of vehicles, as it is infantry combat only.

EDIT: Small question, do I leave the respawn type in the description.ext as "BASE"?

Edited by Militantsausage

Share this post


Link to post
Share on other sites

Yes, leave the respawn as base, as we are handling this ourselves, the BIS "team" respawn provided is not what you have asked for.

Share this post


Link to post
Share on other sites

Rommel, for some reason it didn't work, the regular spawning worked, but when wootin died he respawned at base and then had to run 2.5Km :)

I did what you said and copy/paste the first thing into my init.sqf, but for some reason it didn't work.

EDIT: Also tried yours sxp2high, for some reason it was spawning people out at grid 0000,0000.

Edited by Militantsausage

Share this post


Link to post
Share on other sites

Hey guys,,, just tried out your group respawn in a mission rommel and it worked perfectly, but only once. So the first person to die respawned on a random group member but anyone else who died afterwoods just respawned at the marker "respawn_west"

Cheers.

Share this post


Link to post
Share on other sites

That doesn't really make sense, assuming the player has inherited the event handler properly.

Maybe put in a

player globalchat "ran script"

In the event code (ie before the foreach).

That way you know if the script runs, and we can determine if its a problem with the code I gave you, or something on your end (ie you haven't set the respawn to BASE, or BIS aren't inheriting some of the newer EHs...

Share this post


Link to post
Share on other sites

The respawn code works everytime for me.

team_fnc_respawn = {
_rsp = false;
{
	if ( (alive _x) && !(surfaceIsWater (getpos _x)) && (speed _x < 20) ) then {
		if (vehicle _x == _x) then {
			player setpos (_x modeltoworld [0,-2,0]);
			_rsp = true;
		} else {
			player moveincargo (vehicle _x);
			if (vehicle player != player) then {
				_rsp = true;
			};
		};
	};
	if (_rsp) exitwith {};
} foreach (units player);
};

player addeventhandler ["respawn", team_fnc_respawn];

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  

×