Jump to content
dragonflyfan

Player & AI Re-Spawn

Recommended Posts

Hi all, Merry Christmas. 🙂

 

I'm on leave so get to spend some time deep diving into my mission. At the moment I'm having trouble with respawning, both players and AI, I'm hoping I can get some assistance.

 

Players - I have the Support module and the respawn module sync'd and then sync'd to 'playable' characters. However when I run the game in Eden Editor or in an MP hosted LAN/internet game when a player dies there is no respawn. In fact if any player dies then the mission is considered a success and we all get a 'your side has won' notification.

 

AI - I have 3x gunners that are AI that are set to join my squad and move to a particular position on the Littlebird when the trigger is activated. This all works great however when they die there's nothing more I can do. I was hoping there would be a module or a script that would enable them to respawn in the same positions they started, similar to a vehicle spawn. I have trawled Gunter's thread but can't find anything that suits.

 

Can anyone direct me to what I need to change to get  either / both or these to work please?

 

Thanks,

 

Jas

 

 Spawn.png

 

Spawn-1.png

Share this post


Link to post
Share on other sites

Hey man, Merry Christmas! 🙂
 

Your first problem sounds like you didn't set up your multiplayer settings correctly. When in the editor, go to the multiplayer settings (top of the screen), there are some conditions you might have to check/uncheck, e.g. ending the mission if all players are dead.

 

For the second, I came up with a basic AI revive script a few weeks ago, which should work in your case. Just put this in the init field of the AI you wish to respawn.

private _unit = this;
private _unitType = typeOf this;
private _spawnPosition = getPos this;
private _group = group this;

_unit setVariable ["AIrespawnData",[_unitType, _spawnPosition, _group]]; // Save data to the unit so it can be used for respawn

_unit addEventHandler ["Killed",
{
	params ["_unit", "_killer", "_instigator", "_useEffects"];

	private _respawn =
	{
		private _unit = _this select 0;
		private _unitType = _unit getVariable ["AIrespawnData",[]] select 0;
		private _spawnPosition = _unit getVariable ["AIrespawnData",[]] select 1;
		private _group = _unit getVariable ["AIrespawnData",[]] select 2;

		sleep 60; // Respawn delay in seconds

		if (isNull _group) then {_group = createGroup [west, true]}; // west = Bluefor --> see here: https://community.bistudio.com/wiki/Side

		_group createUnit [_unitType, _spawnPosition, [], 0, "NONE"];
	};

	[_unit] spawn _respawn;
}];

Hope this works for you, I haven't tested exactly this. I'm using a slightly more complicated version of these lines in my scripts and it works fine.
You can adjust the respawn time as you wish with the "sleep" command and you might have to change the side from "west" to something else if the respawning unit is not Bluefor.

Cheers!

Share this post


Link to post
Share on other sites

Thanks for your reply iSassafras.

 

I placed your script into the init of my AI gunner and the respawn worked great thanks, it's just what I was after.

 

Is it possible to make a few tweaks to it please, see below;

 

- Can the respawn keep the 'variable name'? I have a trigger linked to it to make the AI join the players group and move to a specific position in the helicopter. If the script is run and the AI respawns it does not see to activate the trigger again

 

- I have a custom loadout on my AI, can the script remember the loadout when it respawns?

 

Thanks again mate, I really appreciate your help on this one.

 

Jas   

 

ReSpawn.png

  • Like 1

Share this post


Link to post
Share on other sites

Hey man,

 

glad I could help! 🙂

 

Keeping the loadout is not a problem, I'm a little insecure about the varname but I think this should solve both your problems:

private _unit = this;
private _unitType = typeOf this;
private _spawnPosition = getPos this;
private _group = group this;
private _varName = vehicleVarName this;
private _loadout = getUnitLoadout this;

_unit setVariable ["AIrespawnData",[_unitType, _spawnPosition, _group, _varName, _loadout]]; // Save data to the unit so it can be used for respawn

_unit addEventHandler ["Killed",
{
	params ["_unit", "_killer", "_instigator", "_useEffects"];

	private _respawn =
	{
		private _unit = _this select 0;
		private _unitType = _unit getVariable ["AIrespawnData",[]] select 0;
		private _spawnPosition = _unit getVariable ["AIrespawnData",[]] select 1;
		private _group = _unit getVariable ["AIrespawnData",[]] select 2;
		private _varName = _unit getVariable ["AIrespawnData",[]] select 3;
		private _loadout = _unit getVariable ["AIrespawnData",[]] select 4;

		sleep 60; // Respawn delay in seconds

		if (isNull _group) then {_group = createGroup [west, true]}; // west = Bluefor --> see here: https://community.bistudio.com/wiki/Side

		_unit = _group createUnit [_unitType, _spawnPosition, [], 0, "NONE"];
		_unit setUnitLoadout _loadout;
		[_unit, _varName] remoteExec ["setVehicleVarName",0];
		missionNamespace setVariable [_varName, _unit, true];
	};

	[_unit] spawn _respawn;
}];

Hope it works! Cheers.

Share this post


Link to post
Share on other sites

Hi iSassafras, sorry for my late reply, lots of family commitments. 🙂

 

This is just what I was needing, thanks very much for all your help mate.

 

Cheers,

 

Jas

  • Like 1

Share this post


Link to post
Share on other sites

Hello, maybe I'm joining the topic late, but I read your dialogues and I'm looking for help with my problem. Actually, I don't have a problem with Respawning, but with the fact that the bots are respawning without equipment and weapons, which was at the beginning. I tried your script, as well as many others, but the desired result of them respawning with a weapon is not achieved. Did you have such an option, a setting option or a script and how to deal with this?

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

×