Jump to content
Sign in to follow this  
demonized

Single Player - respawn [script]

Recommended Posts

Respawn function for Single Player v 1.3.

For AI and Player.

v1.3 updated 9th july 2011

Requires Arma 2 OA or CO (A2 + OA).

This grew from a few lines in a eventhandler to a big project, feel free to wish/request other options/features into this thread.

Credits:

A-SUICIDAL - first and foremost for giving me the inspiration to go on with this project.

BI forums and its members for all your wisdom shared.

Notes:

* names(added auto)

* custom weapons and backpacks with custom content(added manual option)

* group leadership(added auto + option)

* does not collect module/trigger synch atm.

Future Upgrades:

* add working respawn with first aid modules, already have solution, just need som testing before final implemetion, expected version 1.3.

* add vehicle respawn function.

* ACE working custom loadouts, just a matter of extracting it from my preset loadouts script.

* add killed by camera as posted by Twirly in another thread.

* any other requests by Forum Users.

* add demo mission.

* add indebth comments in script for learning purposes.

* more...

Changelog v 1.3:

* group and leaders are collected correctly and reapplied on respawn.

* teamswitch when dead in group for player. optional.

* life count. optional.

* using editor placed position as spawn point. optional.

* added "SPR_forall" command, to run script auto on all units in group. optional.

* added init line option, to execute something of choise on respawn. optional.

* + several more optionals, all can be combined or used seperately, look in top of script for list and examples.

* reworked death camera.

* tweaks.

v 1.2

* New option - AI and player can respawn with custom equipment, backpacks and custom backpack content included (parts of my Preset Loadouts script added).

* option to use one or several random markers in respawn.

* group command not fully returned, workaround, player is always selected as leader if player in group, will be updated after sleep :)

* changes in code.

v 1.1

* names of unit is now applied to new unit.

* also works for AI units.

* uses center text for timer instead of hint.

v 1.0

* initial release.

place marker called SPR_respawn wherever you want to respawn at.

1: place this in player unit OR AI unit init line:

there are also extra options to apply if desired, info in top of script with examples.

_null = ["SPR_start",this] execVM "SP_respawn.sqf";

2: save the script as SP_respawn.sqf

3: adjust the options in top of script to your liking.

_timer = 10;  // timer until respawn, default is 10 seconds.
_delete = 0;  // timer until delete of old dead unit, 0 = never.
//    + more options.

4: place script in your mission folder, done.

SP_respawn.sqf

/*
Single Player Respawn v1.3
for player and AI.

by Demonized.

Script collects name, custom loadouts, vanilla backpacks with content, and optional respawn markers for player or AI, pluss much more.
and then respawns unit or player as desired, look below for more info.

1: place a marker named SPR_respawn in editor, this is default respawn point if the optionals is not used.

2: place in unit initline: extra options are described below. this is used when placed directly in unit init line, or replace it with unitname.
_null = ["SPR_start",this] execVM "SP_respawn.sqf";

3: save this file as SP_respawn.sqf and place in your mission folder.

DONE!

optional:
* all optionals can be place in after "SPR_start",this in any order or place, as long as its after "SPR_start",this/unitname,place here.
* they can all be randomly placed, no order needed, exept for the 2 first "SPR_start",this/unitname, they can also be combined in any way.
* ALL THE OPTIONS HAVE SPR_ IN FRONT OF THEM, TO MAKE SURE THAT THE OPTIONS ARE NOT CONFUSED WITH OPTIONAL MARKER OPTIONS, SEVERAL CAN BE MANUALLY SET BELOW THIS INFO.

	* use "SPR_forall" in init line after "SPR_start",this/unitname to run the script for all iunits in group with same parameters.
	_null = ["SPR_start",this,"SPR_forall"] execVM "SP_respawn.sqf";  // all in group will respawn.
	_null = ["SPR_start",this,"SPR_forall","SPR_lives",15] execVM "SP_respawn.sqf";  // all in group will respawn and have 15 lives/respawns total available for unit.

	* set amount of lives for this specific unit only, default is not used, 0 is unlimited. add "SPR_lives",x after this where x is amount of lives total.
	_null = ["SPR_start",this,"SPR_lives",15] execVM "SP_respawn.sqf";  // 15 lives/respawns total available for unit.

	* set respawn timer for this specific unit only. add "SPR_timer",x after this, where x is respawn time in seconds.
	_null = ["SPR_start",this,"SPR_timer",15] execVM "SP_respawn.sqf";  // 15 seconds until respawns for this unit.

	* set delete timer for this specific unit only, 0 is never. add "SPR_delete",x after this, where x is delete time in seconds after death.
	_null = ["SPR_start",this,"SPR_delete",15] execVM "SP_respawn.sqf";  // 15 seconds until delete for this unit after death.

	* another marker or multiple random markers to respawn at. add any amount of "markername" after this somewhere, default marker will not be used if this.
	_null = ["SPR_start",this,"west_marker"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"east_marker1","east_marker2"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"someMarker","someothermarker"] execVM "SP_respawn.sqf";

	* instead of using markers to respawn at, use position unit is starting the script at and direction set then. add "SPR_pos" after this.
	_null = ["SPR_start",this,"SPR_pos"] execVM "SP_respawn.sqf";

	* custom loadouts with respawn. add "SPR_load" after this somewhere.
	_null = ["SPR_start",this,"SPR_load"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"someMarker","SPR_load"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"SPR_load","someMarker","someothermarker"] execVM "SP_respawn.sqf";

	* add init for the specific unit. add array with init inside after this as shown below. important, use ""double"" or 'single' inside the outer set of "qoutes"
	_null = ["SPR_start",this,["this allowDammage false"]] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,["this allowDammage false"],"SPR_load"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,["_null = this execVM ""scriptname.sqf"""]] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"SPR_load",["_null = this execVM 'scriptname.sqf'"],"somemarker","anothermarker"] execVM "SP_respawn.sqf";

	* group respawn. add "SPR_group" after this. Ai will only resapwn once whole group is dead. and group will respawn together at same marker if using random markers.
	_null = ["SPR_start",this,"SPR_group"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"SPR_load","SPR_group"] execVM "SP_respawn.sqf";

	* group will resume waypoints from waypoint nr 1 upon respawn. add "SPR_wp" after this same effect as "SPR_group" option, but with restart of the initial waypoints..
	_null = ["SPR_start",this,"SPR_wp"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"vehicle","SPR_wp"] execVM "SP_respawn.sqf";

	* group delete, delete units after timer after all units in group is dead. add "SPR_groupdelete" after this.
	_null = ["SPR_start",this,"SPR_groupdelete"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"SPR_load","SPR_groupdelete"] execVM "SP_respawn.sqf";

	* player switch to next alive unit in group. add "SPR_switch" after this, once all is dead in group including player, whole group will respawn same as with "SPR_group" option.
	_null = ["SPR_start",this,"SPR_switch"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"SPR_switch","SPR_load"] execVM "SP_respawn.sqf";

	* add init for the specific unit. add array with init inside after this as shown below. important, use ""double"" or 'single' inside the outer set of "qoutes"
	_null = ["SPR_start",this,["this allowDammage false"]] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,["this allowDammage false"],"SPR_load"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,["_null = this execVM ""scriptname.sqf"""]] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"SPR_wp","vehicle",["_null = this execVM 'scriptname.sqf'"],"somemarker","anothermarker"] execVM "SP_respawn.sqf";

	not yet implemented.
	* vehicle respawn. AI or player will respawn with same vehicle and same crew they died in. add "vehicle" after this.
	_null = ["SPR_start",this,"vehicle"] execVM "SP_respawn.sqf";
	_null = ["SPR_start",this,"SPR_group","vehicle"] execVM "SP_respawn.sqf";


save this as SP_respawn.sqf
*/


_timer = 10;  			// timer until respawn, default is 10 seconds.
_lives = 3;  			// total amount of lives / number of respawns a unit has. 0 means unlimited.
_delete = 360;  			// timer until delete of old dead unit, 0 = never.
_deathCam = true;  		// show camera view of dying player only. true/false = on/off == camera/black screen.
_spawnPos = "SPR_respawn";  	// default respawn marker, if not the optional is used.

// these are some options that can be activated by all instead of using the various "optionals" above. true/false = on/off.

_grpDel = false;			// default false, delete dead units after x time when all in units group is dead.
_group = false;			// default false, respawn only when all in units group is dead, collective respawn.
_wp = false;			// default false, same as _group with added start on first waypoint on respawn instead of continuing on last.
_switch = false;			// default false, for player only, if player should teamswitch upon death if there is someone alive in player group.
_unLim = false;			// default false,  unlimited lives/respawns, same as setting _lives to 0.
_alwLead = false;			// default false, for player only, if player always should be team leader when teamswitcing if _switch option is enabled.

// DO NOT EDIT PAST THIS LINE //


if ("SPR_start" in _this) then {
sleep 0.1;  		// make sure unit is up and running.
_unit = _this select 1;

// if running line on all units in group.
if ("SPR_forall" in _this) then {
	_var1 = _this - ["SPR_start",_unit,"SPR_forall"];
	{
		if (_x != _unit) then {
			_var2 = ["SPR_start",_x] + _var1;
			_null = _var2 execVM "SP_respawn.sqf";
		};
	} foreach units group _unit;
};

// collect info on unit.
_side = side _unit;
_grp = group _unit;
_player = false;
if (_unit == player) then {_player = true};
if ("SPR_lives" in _this) then {
	_sel = _this find "SPR_lives";
	_lives = _this select (_sel + 1);
};
if ("SPR_timer" in _this) then {
	_sel = _this find "SPR_timer";
	_timer = _this select (_sel + 1);
};
if ("SPR_delete" in _this) then {
	_sel = _this find "SPR_delete";
	_delete = _this select (_sel + 1);
};
_startPos = [];
if ("SPR_pos" in _this) then {_startPos = [(getPos _unit),(getDir _unit)]};
if ("SPR_groupdelete" in _this) then {_grpDel = true};
if ("SPR_group" in _this) then {_group = true};
if ("SPR_wp" in _this) then {_wp = true; _group = true};
if ("SPR_switch" in _this AND _unit == player) then {_switch = true};
if (_lives == 0) then {_unLim = true};
_load = [];
if ("SPR_load" in _this) then {
	_wep = weapons _unit;
	_mag = magazines _unit;
	_load = [_wep,_mag];
	if (!isNull (unitBackpack _unit)) then {
		_bag = (typeOf (unitBackpack _unit));
		_bagW = getWeaponCargo (unitBackpack _unit);
		_bagM = getMagazineCargo (unitBackpack _unit);
		_load = _load + [_bag,_bagW,_bagM];
	};
};
_mark = [];
_init = [];
{
	if ((typeName _x) == "ARRAY") then {_init = _x};
	if ((typeName _x) == "STRING" AND !(_x in ["SPR_start","SPR_load","SPR_switch","SPR_groupdelete","SPR_pos","SPR_group","SPR_wp","SPR_lives","SPR_timer","SPR_delete","SPR_forall"])) then {_mark = _mark + [_x]};
} foreach _this;
_lead = false;
if ((leader (group _unit)) == _unit) then {_lead = true};

_unit setVariable ["DMZ_SPR_respawn", [_load,_mark,_lead,_player,_side,_grp,(_lives - 1),_unLim,_switch,_startPos,_group,_wp,_init,_timer,_delete,_alwLead], true];
_unit addEventHandler ["killed", {_null = _this execVM "SP_respawn.sqf";}];
} else {
_dead = _this select 0;
_ret = (_dead getVariable ["DMZ_SPR_respawn", ["none"]]);
_type = typeOf _dead;
_pos = getPos _dead;
_vName = vehicleVarName _dead;
_orgV = cameraView;

// if player create a unit imediatly to avoid end menu.
_fastUnit = {
	// _temp = [_side,_type,_dead] call _fastUnit;
	if (isNil ("DMZ_SPR_All_Dead_grp")) then {DMZ_SPR_All_Dead_grp = createGroup (_this select 0)};
	_temp = DMZ_SPR_All_Dead_grp createUnit [(_this select 1), (getPos (_this select 2)), [], 0, "NONE"];
	_temp allowDammage false;
	hideObject _temp;
	addSwitchableUnit _temp;
	selectPlayer _temp;

	// delete the new unit after player is in control of team unit with switch.
	_null = [_temp,(_this select 2)] spawn {
		_temp = _this select 0;
		_dead = _this select 1;
		_temp enableSimulation false;
		_temp setCaptive true;
		_temp setPos (getPos _dead);
		waitUntil {sleep 2; _temp != player};
		removeSwitchableUnit _temp;
		waitUntil {sleep 1; !(_temp in switchableUnits)};
		deleteVehicle _temp;
		waitUntil {sleep 1; isNull _temp};
		_temp = nil;
	};
	_temp
};

_load = _ret select 0;
_mark = _ret select 1;
_lead = _ret select 2;
_player = _ret select 3;
_side = _ret select 4;
_grp = _ret select 5;
_lives = _ret select 6;
_unLim = _ret select 7;
_switch = _ret select 8;
_startPos = _ret select 9;
_group = _ret select 10;
_wp = _ret select 11;
_init = _ret select 12;
_timer = _ret select 13;
_delete = _ret select 14;
_alwLead = _ret select 15;

//variable to set on respawn   [_load,_mark,_lead,_player,_side,_grp,_lives,_unLim,_switch,_startPos,_group,_wp,_init,_timer,_delete,_alwLead]

// show timer.
_showTimer = {
	//_showT = [_timer,_deathCam,_lives] spawn _showTimer;
	_timer = _this select 0;
	_type = "PLAIN";
	if (!(_this select 1)) then {_type = "BLACK FADED"};
	while {_timer != 0} do {
		_text = "";
		if ("ts" in _this) then {
			_text = format["TEAM SWITCH IN %1",_timer];
		} else {
			_text = format["RESPAWN IN %1 \n \n LIVES LEFT IS %2",_timer,((_this select 2)-1)];
		};
		cutText [_text,_type,0];
		_timer = _timer - 1;
		sleep 1;
	};
	if ("ts" in _this) then {
		titlecut ["TEAM SWITCHING NOW","black in",3];
	} else {
		titlecut ["RESPAWNING NOW","black in",3];
	};
};

// create a temp unit for player only.
if (_player) then {
	_temp = [_side,_type,_dead] call _fastUnit;
	waitUntil {alive _temp AND _temp == player};
};

_cameraFunction = {
	//_cam = [_timer,_dead,_unit,_orgV] spawn _cameraFunction;
	_timer = _this select 0;
	_dead = _this select 1;
	_unit = _this select 2;
	_orgV = _this select 3;

	if ("group" in _this) then {titlecut ["Waiting for rest of team to die - group spawn activated","PLAIN",5]};

	// internal cam movement function.
	_camMove = {
		_cam = _this select 0;
		_cam camSetTarget vehicle (_this select 1);
		_cam camSetRelPos (_this select 2);
		_cam camSetFOV (_this select 3);
		_cam camCommit (_this select 4);
		waituntil {(camCommitted _cam)};
	};

	_camTime = _timer/2;

	// camera initialisation
	_camera = "camera" camCreate getpos _dead;
	_camera cameraEffect ["internal","back"];

	_runLoop = true;
	while {_runLoop} do {
		if ("group" in _this) then {
			{if (alive _x) then {_unit = _x}} foreach units (_this select 4);
		};
		// camera look at player
		_cam = [_camera,_dead,[0.2,0.4,2],0.143,0] spawn _camMove;
		waitUntil {scriptDone _cam};

		// camera zooms out over 5 seconds
		_cam = [_camera,_dead,[0,8,3.5],0.7,_camTime] spawn _camMove;
		waitUntil {scriptDone _cam};

		// quick fade-in on internal point of view of the next unit
		_camera camSetTarget _unit;

		// set camera above new unit.
		_cam = [_camera,_unit,[0,8,3.5],0.7,0] spawn _camMove;
		waitUntil {scriptDone _cam};

		// camera zooms in over 5 seconds
		_cam = [_camera,_unit,[0.2,0.4,2],0.7,_camTime] spawn _camMove;
		waitUntil {scriptDone _cam};

		if ("group" in _this) then {
			if (player getVariable ["DMZ_SPR_respawn_group", false]) then {_runLoop = false};
		} else {
			_runLoop = false;
		};
	};

	// end camera part.
	_unit cameraEffect ["terminate","back"];

	// destroy camera.
	camDestroy _camera;

	// wait until unit is in player control then switxh camera back to org view (1st / 3rd person) on death.
	if (!("group" in _this)) then {
		_null = [_unit,_orgV] spawn {
			_unit = _this select 0;
			waitUntil {!alive _unit OR player == _unit};
			if (alive _unit) then {
				vehicle player switchCamera (_this select 1);
			};
		};
	};
};

// show the timer.
if (_player) then {
	if (_switch AND ({alive _x} count units _grp) != 0) then {
		_showT = [_timer,_deathCam,"ts"] spawn _showTimer;
	} else {
		if (!_group) then {
			_showT = [_timer,_deathCam,_lives] spawn _showTimer;
		};
	};
};

// join the dead unit to a holder group incase of switch option.
if (_switch) then {
	if (isNil ("DMZ_SPR_All_Dead_grp")) then {DMZ_SPR_All_Dead_grp = createGroup _side};
	removeSwitchableUnit _dead;
	_null = [_dead,_grp] spawn {
		_dead = _this select 0;
		waitUntil {sleep 1; ({alive _x} count units (_this select 1)) != 0 OR isNull _dead};
		if (!isNull _dead) then {[_dead] joinSilent DMZ_SPR_All_Dead_grp};
	};
};

// delete the dead unit if selected.
if (_delete != 0 OR _grpDel) then {
	_null = [_dead,_delete,_grpDel,_grp] spawn {
		if ((_this select 2)) then {
			waitUntil {({alive _x} count units (_this select 3)) == 0};
		};
		sleep (_this select 1);
		deleteVehicle (_this select 0);
	};
};

_mDir = 0;
_spawn = [];
// if default marker is selected.
if (_spawnPos != "") then {
	_spawn = getMarkerPos _spawnPos;
	_mDir = markerDir _spawnPos;
};

// if random marker/s option is used.
if ((count _mark) != 0) then {
	_spawnPos = _mark select (floor (random (count _mark)));
	_spawn = getMarkerPos _spawnPos;
	_mDir = markerDir _spawnPos;
};

if ((count _startPos) != 0) then {
	_spawn = _startPos select 0;
	_mDir = _startPos select 1;
};

if (_switch) then {
	_switchedUnit = player;
	_switchedDead = _dead;
	_switchActive = true;
	while {({alive _x} count units _grp) != 0 AND _switchActive} do {
		{
			if (alive _x) then {_switchedUnit = _x};
		} foreach units _grp;

		_showT = [_timer,_deathCam,"ts"] spawn _showTimer;
		if (_deathCam) then {
			_cam = [_timer,_switchedDead,_switchedUnit,_orgV] spawn _cameraFunction;
			waitUntil {scriptDone _cam};
			//vehicle player switchCamera _orgV;
		} else {
			sleep _timer;
		};

		if (alive _switchedUnit AND (group _switchedUnit) == _grp) then {
			addSwitchableUnit _switchedUnit;
			selectPlayer _switchedUnit;
			waitUntil {_switchedUnit == player};

			// if always leader option is selected.
			if (_alwLead) then {
				_null = _switchedUnit spawn {
					_grp = group _this;
					while {alive _this} do {
						waitUntil {sleep 1; !alive _this OR (leader _grp) != player};
						if (alive _this) then {_grp selectLeader _this};
					};
				};
			};

			// wait for player to die again before new switch if any available in group.
			waitUntil {!alive _switchedUnit};
			_orgV = cameraView;
			_null = [_switchedUnit,_grp] spawn {
				_unit = _this select 0;
				_grp = _this select 1;
				waitUntil {_unit != player};
				removeSwitchableUnit _unit;
				waitUntil {sleep 1; ({alive _x} count units _grp) != 0 OR isNull _unit};
				if (!isNull _unit) then {
					[_switchedUnit] joinSilent DMZ_SPR_All_Dead_grp;
				};
			};
			_temp = [_side,_type,_switchedUnit] call _fastUnit;
			_switchedDead = _switchedUnit;
			waitUntil {_temp == player};
		} else {
			titlecut ["TEAM MEMBER DEAD","PLAIN",3];
		};
		if (({alive _x} count units _grp) == 0) then {
			_switchActive = false;
			player setVariable ["DMZ_SPR_nomore_group", true, true];
			titlecut ["ALL UNITS IN GROUP ARE DEAD","BLACK FADED",3];
			_dead = _switchedUnit;
			if (!_group) then {sleep 3};
			if (_lives == 0 AND !_unLim) then {
				titlecut ["NO MORE LIVES \n \n END GAME","black out",3];
				sleep 3;
				player setDammage 1;
			};
		};
	};
};

// group option.
_form = "NONE";
if (_group OR _wp) then {
	if (_player) then {
		_null = _grp spawn {
			waitUntil {({alive _x} count units _this) == 0};
			player setVariable ["DMZ_SPR_respawn_group", true, true];
		};
		_cam = [_timer,_dead,_dead,_orgV,_grp,"group"] spawn _cameraFunction;
	};
	if (_player) then {
		waitUntil {sleep 1; ({alive _x} count units _grp) == 0 OR (player getVariable ["DMZ_SPR_nomore_group", false])};
	} else {
		waitUntil {sleep 1; ({alive _x} count units _grp) == 0};
	};
	if (_wp AND _lead) then {
		_null = _grp spawn {
			waitUntil {({alive _x} count units _this) != 0};
			_this setCurrentWaypoint [_this, 0];
		};
	};
	if (!_lead) then {
		waitUntil {({alive _x} count units _grp) != 0};
		if ((count _startPos) == 0) then {_form = "FORM"};
	};
};

if (!_player) then {sleep _timer};
_unit = _grp createUnit [_type, _spawn, [], 0, _form];

// set init.
if ((count _init) != 0) then {
	_unit setVehicleInit (_init select 0);
	processInitCommands;
};

if (_player) then {
	if (_timer != 0) then {
		// show timer.
		_showT = [_timer,_deathCam,_lives] spawn _showTimer;

		// if on death camera.
		if (_deathCam) then {_cam = [_timer,_dead,_unit,_orgV] spawn _cameraFunction};
	};

	addSwitchableUnit _unit;
	selectPlayer _unit;
	waitUntil {_unit == player};
	vehicle _unit switchCamera _orgV;
};

if (!_switch) then {
	if (isNil ("DMZ_SPR_All_Dead_grp")) then {DMZ_SPR_All_Dead_grp = createGroup _side};
	[_dead] joinSilent DMZ_SPR_All_Dead_grp;
	if (_dead in switchAbleUnits) then {removeSwitchableUnit _dead};
};

if (_vName != "") then {
	_rName = "DMZ_SPR_Dead_unit";
	_dead SetVehicleVarName _rName;
	_dead Call Compile Format ["%1=_This ; PublicVariable ""%1""",_rName];
	waitUntil {(vehicleVarName _dead) == _rName};
	_unit SetVehicleVarName _vName;
	_unit Call Compile Format ["%1=_This ; PublicVariable ""%1""",_vName];
};

if (_unLim) then {_lives = 1} else {_lives = _lives - 1};
if (_lives != 0) then {
	_unit setVariable ["DMZ_SPR_respawn", [_load,_mark,_lead,_player,_side,_grp,_lives,_unLim,_switch,_startPos,_group,_wp,_init,_timer,_delete,_alwLead], true];
	_idx = _unit addEventHandler ["killed", {_null = _this execVM "SP_respawn.sqf";}];
};

_unit setPos _spawn;
_unit setDir _mDir;

// if custom loadouts.
if ((count _load) != 0) then {
	_null = [_unit,_load] spawn {
		_unit = _this select 0;
		_load = _this select 1;

		waitUntil {alive _unit};
		removeAllWeapons _unit;
		{if (_unit hasWeapon _x) then {_unit removeWeapon _x}} foreach (weapons _unit);
		{_unit addMagazine _x} foreach (_load select 1);
		{_unit addweapon _x} foreach (_load select 0);
		if ((count _load) > 2) then {
			_unit addBackpack _back;
			_backPack = unitBackpack _unit;
			_bpWepArr = _load select 3;
			_bpMagArr = _load select 4;

			// clear backpack of any content.
			clearMagazineCargo _backPack;
			clearWeaponCargo _backPack;

			// add all pre selected items.
			_sel = 0;
			_bpWep = _bpWepArr select 0;
			_wepCnt = _bpWepArr select 1;
			while {_sel != (count _bpWep)} do {
				_wep = _bpWep select _sel;
				_cnt = _wepCnt select _sel;
				_backPack addWeaponCargo [_wep,_cnt];
				_sel = _sel + 1;
			};
			_sel = 0;
			_bpMag = _bpMagArr select 0;
			_magCnt = _bpMagArr select 1;
			while {_sel != (count _bpMag)} do {
				_mag = _bpMag select _sel;
				_cnt = _magCnt select _sel;
				_backPack addMagazineCargo [_mag,_cnt];
				_sel = _sel + 1;
			};
		};
		_unit selectWeapon (primaryWeapon _unit);
	};
};

//if (player in (units _grp)) then {_grp selectLeader player};
if (_lead) then {
	_grp selectLeader _unit;
	if (!_player) then {
		_pos = getPos _unit;
		_unit doMove [(_pos select 0) + 1,(_pos select 1) + 1,0];
	};
};

// add here any custom scripts to be run at unit after resapwning, if you dont want to use the init option.
// _null = _unit execVM "example_custom_script.sqf";
// _unit addAction ["Switch on generator", "activate_generator.sqs"];
};

Optional: at bottom of script you can run a custom code on the respawned unit, for example adding custom weapons, or doing something else with it, for example run a vehicle script on it or waypoints. or you can use the init line option for specific units.

Edited by Demonized
added note, OA or CO required.

Share this post


Link to post
Share on other sites

When an AI on my team gets killed, it causes me to die instantly, lol. So I guess it wont work for them.

---------- Post added at 11:27 PM ---------- Previous post was at 11:20 PM ----------

Edit, lol. You script changed. Works now. This is awesome.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites
When an AI on my team gets killed, it causes me to die instantly, lol. So I guess it wont work for them.

---------- Post added at 11:27 PM ---------- Previous post was at 11:20 PM ----------

But we both did respawn. There are only 3 AI on my team, would it be possible for me to create 4 separate scripts for units s1, s2, s3 and s4 and where the script referes to "player" maybe use their name instead?

hey, i am almost ready with the next update, it includes AI and names and custom loadouts, no need for several scripts.

ironing out a few details now and adding in the custom loadouts option and multiple optional spawn markers option.

will post update soon.

Share this post


Link to post
Share on other sites

I'm trying to get these other 3 AI on my team to hop back into their planes when they respawn. It was working when I tested in MP with AI enabled - before your SP_respawn script, but in this single player version I'm making, it doesn't seem to be working. For instance assigning AI named "s3" to plane "p3" and ordering him to get in and head towards our only waypoint. Maybe I should tell them all to head towards a marker. The main player/me is "s4" and lowest in chain of command, but when I tested as player "s1" I lost command when I respawned. I'll keep trying to figure it out. As usually I'm probably doing something wrong. This idea for singleplayer respawn could be the beginning of a new era of awesome single player missions. Your the man!

Share this post


Link to post
Share on other sites

Updated to v 1.2, check changelog.

@A-SUICIDAL

at the bottom of the script in v 1.2 add this:

_null = _unit execVM "yourscriptname.sqf";

in yourscriptname.sqf have this:

_plane = "";
if (_this == s1) then {_plane = p1};
if (_this == s2) then {_plane = p2};
if (_this == s3) then {_plane = p3};

waitUntil {(getDammage _plane) == 0};
_this assignAsDriver _plane;
[_this] orderGetin true;
waitUntil {(driver _plane) == _this};
_this commandFollow (leader (group _this));

well, you see now, when he respawnes, he runs towards the plane linked to his name, then enters it and when in he moves back into formation, (following the leader until given other orders.

thats just one way of doing things, ill add a automatic option later on for this type of thing.

Edited by Demonized
shortened code, added wait for plane repaired/respawned.

Share this post


Link to post
Share on other sites

Ok, got everything working perfect except for 1 thing, but that belongs in the other thread.

---------- Post added at 01:17 AM ---------- Previous post was at 01:16 AM ----------

damn, I just refreshed, typed 1 sentence, and already you replied before I could, lol.

---------- Post added at 01:18 AM ---------- Previous post was at 01:17 AM ----------

That looks better than my method of 8 triggers that check for when each of the 4 players are alive and when the 4 planes are alive and exec the script to make them get back in.

Share this post


Link to post
Share on other sites

you should maybe add in a check if the vehicle is respawned, im guessing it will be destroyed when ai resapwns so just do this before assignasdriver line:

waitUntil {(getDammage _plane) == 0};

Share this post


Link to post
Share on other sites
It gave me errors. hmm

i asumed you used a vehicle respawn script like tophes vehicle respawn or something similar?

if it was for the v 1.2 of my respawn script:

check if you start it right, as i edited instrcutions after the post, i forgot to change the instruction saying add eventhandler to execVM the script instead. instructions part 1.

Share this post


Link to post
Share on other sites

I keep checking to see the new changes, so the errors I'm getting are probably just me making mistakes again. Damn AI pilots eject the moment their Falcon has a tiny scratch. I'm trying to check if they are not in the plane and over 200m away from the respawn area, then wait enough time for them to parachute to the ground so it looks cool, then setpos them back the the start, and setDamage them to 0. But I need to get the get in plane after respawn stuff working first.

---------- Post added at 02:14 AM ---------- Previous post was at 02:11 AM ----------

yeah I have a vehicle_respawn script. but it's just for if the plane is abandoned and if it's destroyed to respawn it immediately at base so the getIn commands work.

---------- Post added at 02:30 AM ---------- Previous post was at 02:14 AM ----------

The getIn stuff seems to be working better now. I started the mission, blew myself up with a pipebomb, respawned and the vehicle was still assigned to me, but he never told me to get in a second time and there was no mount symbol on the plane, but at least it wasn't locked like it was before, lol. I have it on default, because if I set it to be unlocked and a friends plays my mission and gets in the wrong plane, it will screw the AI up.

Share this post


Link to post
Share on other sites

Well, here's a movie I made of my "single player mission with respawn" thanks to Demonized. It's much easier to play it when I'm not recording, since recording lags me a little. Even my 3 AI teammates respawn and get back into their F-16's and continue to do battle against SU-33's. Anyway, check it out. Give it time to load.

http://www.xfire.com/video/49e49a/

Share this post


Link to post
Share on other sites
Well, here's a movie I made of my "single player mission with respawn" thanks to Demonized. It's much easier to play it when I'm not recording, since recording lags me a little. Even my 3 AI teammates respawn and get back into their F-16's and continue to do battle against SU-33's. Anyway, check it out. Give it time to load.

http://www.xfire.com/video/49e49a/

Oh man, that was some impressive flying there.

that was just a perfect advert for flying in Arma2, who said they dont have to much focus on air combat.

looked great.

loved the low flying parts.

are you using joystick and track ir?

new version almost ready to release, with more options like group respawn, teamswitch for player, etc etc. still have to iron out a few details.

it was very fun to get back to SP scripting, doesnt have to think about the locality issues of MP.

hopefully ill have it ready sometime tonight.

Share this post


Link to post
Share on other sites

I just use keyboard and I freelook with mouse the entire time. All my keys are remapped. I use the 6 keys above the arrow keys for my movement. Basically I fly using only 3 fingers, lol, except for when I occasionally tap my "next target", "toggle weapons" & "gear up".

Here's a chopper mission I made for SP and MP where I use 100% freelook while flying.

http://www.xfire.com/video/47a2db/

I'm going to put the respawn in the SP version and release both as a CO download. The music is trigger in the mission for both the movies.

---------- Post added at 08:05 AM ---------- Previous post was at 07:42 AM ----------

That chopper movie is old, the latest version has enemy tanks and troops and stuff at each waypoint, but I also have a simple patrol version like in the movie, where you simply take out trucks and a few soldiers here and there. It's the mission I use when I help friends learn to fly and gun. I've also played the same mission where I was the gunner and the AI would do the flying, and wow, they are really good at flying low and lining up shots for me. Very impressive, but I prefer to fly. Another SP version where there are two choppers, one follows the other, and lots of placed enemy tanks, trucks and Troops and other stuff at each objective, Civilians, Animals, and Ambient Combat module.

Share this post


Link to post
Share on other sites

i fly by mouse and keyboard myself, but use alt to freelook when needed, and then use mouse to fly more fluidly generally, probably because my keyboard is old and sux, my PC is also not top performance gaming PC either.

it gets jerky sometimes with only my keyboard for movement.

i use W,A,S,D for movement, Q, E for up and down / or speed up and down.

TAB for targeting, shift for turbo when available.

ALT for freelook.

and i have assigned Z,X for trim (slightly turn left/right).

I have been thinking of getting myself a proper joystick and maybe some track ir, but never got around to it as the keyboard mouse works just fine.

cool videos man.

going to work on next version of SP resapwn now.

Share this post


Link to post
Share on other sites

Somebody asked me earlier how I got my XFire ingame to work for Arma 2 CO. I don't get xfire ingame. I use ventrilo to talk to friends, chat in the game with sidechat, or minimize quick to read an xfire message, but to record movies and upload to xfire, this is what you do...

record with Fraps and make Fraps to save the movies to "C:\ProgramData\Xfire\videos"

Once your are done recording, go "C:\Program Files\Xfire" and launch "xfencoder.exe" and the browse to the Fraps movie that you recorded and then hit the "Go!" button and it will convert it. Once it is done converting, you can then see the movie on your XFire list of movies that are ready to be uploaded. The best part about this method is... it allows you to upload movies much longer than 10 minutes in length. Normally xfire never lets you upload anything over 10 minutes long. I make good movies. When uploading the movie, choose either "Unknown" game as the title, or add Arrowhead to your list of games in XFire manually by browsing to the Arma 2 exe root directory.

Then go ahead and upload your movie to XFire.

For best result, record using Frap in "Full size" not half size, but set your game to 1024x768 at highest. This will lag you less when recording and give you decent quality.

Or - install and use "Wegame". www.wegame.com. Good site. Record with wegame and upload to their site, but if you are not a paid member, you can only upload half size movies, which is fine, because the quality is video quality is great. Here's a wegame sample movie of me playing my Ghost Recon Advanced Warfighter 2 Mod using new weapons, unsuppressed and flashlight attachments. It's a good movie. http://www.wegame.com/watch/graw2-operation-herrera-hardcore/

Share this post


Link to post
Share on other sites

In my single player mission, if pilot ejects and is stranded I use norrins chopper extraction/taxi script. It gives me the action to call for an extraction chopper at missions start, but when I die and respawn it doesn't give me back the action. I've tried a zillion different ways to try to get it working correctly, but either I give up and just set it so if player abandons his vehicle, that 20 seconds later it destroys the plane and if plane is destroyed, it then destroys the player. For the 3 AI teammates, I already have it set this way, but for the player, I really wanted this chopper extract thing to work.

Here's the link for Norrin's taxi script:

http://www.armaholic.com/page.php?id=12141

If you know what I need to add to the bottom of the "SP_respawn.sqf" to get it to give me back the action to "Call for helicopter extraction" after I respawn, it would be greatly appreciated. It's the only thing left in the mission that I need to get working, then I'm done. Or I might just write my own script that spawns a chopper and crew and moves them to my position, lands etc. It would be much easier to get norrins script to work in this mission instead.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

from what i can see, for now just add this at the end where specified.

player setVariable ["NORRN_taxiHeli", [b]slick1[/b], true];

where slick1 is the name of the taxi vehicle.

Share this post


Link to post
Share on other sites

updated to v 1.3, tested most of the various combinations of optionals, but let me know of any bugs and ill hunt them down.

also its still in a single file, im considering splitting it up in several smaller (faster) scripts.

but need feedback on how it works for you guys.

Enjoy

Share this post


Link to post
Share on other sites

Your new version of you script works great. I love it, especially all the new options. You thought of everything. Amazing work. Your a genius dude.

I started on a new mission design, and everything is working great with the latest version of your script. I also have an older version of your SP_respawn working in a another mission I made and I wanted to update it, so I made a back up of my mission, then went ahead and tried updating the mission with the newer version of your script. I updated the SP_respawn.sqf file, the player init and also updated the marker to "SPR_respawn" and tried testing and it gave me this: arma2oa_pic1.jpg

There must be something in my mission that is conflicting somehow, if only I knew what. Well, like I said, I have an older version of your respawn script working in a backup mission, so I'll probably just leave it as is and use the your newer version of your script in future mission creations.

I really liked how you added the ability to set an amount of respawns. It would be cool if there was a tiny counter in the corner of the screen someplace that kept track of total kills/total deaths. And after x amount of kills, you earn an extra life. Woohoo! And maybe after x amount of kills - the mission creator could execute a script, which could be something like... a script that executes and unlocks a better vehicle, or even better... a script gets executed that creates new marker where even more enemy respawn from - making it even more difficult to survive. Singleplayer always needed score keeper. Yeah, I know it's a military sim game, but there is now reason why we can't have a little bit of arcade action with it. lol.

Oh, I was going to try a setFace command on respawn to see if I could force my face to stay the same each time I respawn, since I usually respawn as a different face each time. It's actually funny in a way.

I was very busy creating and testing my new single player mission, but now every time I try to test it, I wind up playing it for hours and hours and just having fun instead, all because of your awesome script that allows players to respawn. After 3 hours, I finally stopped playing and started working, and the same thing happened again.

---------- Post added at 04:46 AM ---------- Previous post was at 04:29 AM ----------

I'm going to add a script on respawn that creates a new marker and spawns more enemy - and creates a trigger that detects when the player has died - and when the player dies activates another script that creates more enemy again and adds a new friendly player to my team as well. If only I could figure out how to get a score keeper that shows total kills someplace in the corner of the screen.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

loop with

hint format ["west dead is %1",westDead];

make westdead a global variable placed in a killed eventhandler on all west units with the hint in the eventhandler.

ill pop something similar in, also im working on getting the vehicles to function with all kinds of custom, wich proved harder than just creating the vehicle again.

should have new version up soon.

with the conflict, not sure whats wrong, maybe you should try to rapply the respawn script from scratch insted of converting from the old one, i did not think about or care to much of the old version when i made the new.

so could be significant changes, well there is changes so..

if all else fails, send me a link to the mission and ill check it for you if its not to big a mission or mess :D

Share this post


Link to post
Share on other sites

1: place a marker named SPR_respawn in editor, this is default respawn point if the optionals is not used.

2: place in unit initline: extra options are described below. this is used when placed directly in unit init line, or replace it with unitname.

_null = ["SPR_start",this] execVM "SP_respawn.sqf";

3: save this file as SP_respawn.sqf and place in your mission folder.

DONE!

//codes

I followed the steps above but no respawn. :(

Are there anything else I'm missing to use this script?

Share this post


Link to post
Share on other sites

here is a simple demo mission of it working, bluefor player with marker respawn, and outside gates, a opfor with position respawn.

Share this post


Link to post
Share on other sites
here is a simple demo mission of it working, bluefor player with marker respawn, and outside gates, a opfor with position respawn.

I don't have operation arrowhead, only arma 2.

Do I need OA for this script?

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  

×