-=/Respawn in Singleplayer\=- by Rydygier & Gunter Severloh   Description When your playing a mission in single-player, either a subscribed or a mission you created yourself, and when you get killed, did you ever wonder if it were possible if you could just keep playing somehow without relying on saves?      If you could just respawn like you can in multiplayer? ... Well now you can!   This is a code written by Rydydgier that will allow you to respawn in singelplayer, either through preview in the editor, or in a mission in scenarios. All you need to do is define a marker where you want to respawn, or a vehicle name you want to respawn at for a mobile respawn, and then add the ini.sqf in the scenario folder. See the features below for more details!   Features - Respawn anywhere by defining where you want to respawn at via marker like a base respawn. - Make your scenario dynamic and replayable by setting up a random respawn by defining where you want to respawn via multiple markers. - Setup a mobile respawn by giving a vehicle a name and you will respawn wherever that vehicle is. - Use the code from an external script and not directly from the init.sqf if you want too. - Save your loadout on respawn of the placed unit in the editor, or respawn with the added loadout setup through arsenal that was applied to the unit. - Set how many times you want to respawn, either use a set number or set it to -1 for unlimited respawns. - Remove your dead body apon death, automatic corpse removal, every time you die in your mission your player character's body will be deleted by sinking into the ground. - Respawn screen. - Respawn timer.   Installation and Setup Setup - Script 1. Create a notepad/notepad++ document and copy and paste the following code into it: 2. Save and name the document:  init.sqf and put it into your scenario folder. //single player respawn script RYD_SPR_RespawnPositions = [myCar_1];//one will be chosen at random, markers, objects or arrays including coordintes and direction, for example: RYD_SPR_RespawnPositions = ["marker1","OtherMarker_2",someObject_1,[[100,200,0],120]]; RYD_SPR_Respawns = -1;//amount of respawns. If set with negative value - unlimited respawns RYD_SPR_ChangedLoadout = true;//if true, new unit will get old unit's loadout as it was at death, otherwise new unit will get default loadout. RYD_SPR_DelayParameters = [10,false,true,{}];//[delay in seconds, black courtain, external view, optional code to be executed in the middle of countdown where _this equals new unit] RYD_SPR_TextColor = "3a96d4";//RESPAWN IN: color. //all above arrays can be re-defined on the fly. RYD_SPR_atKilled = { params ["_killed"]; if not (RYD_SPR_Respawns == 0) then { _delay = RYD_SPR_DelayParameters select 0; _blackout = RYD_SPR_DelayParameters select 1; _mode2 = "PLAIN"; _mode3 = "PLAIN"; _mode = if (_blackout) then { _mode2 = "BLACK FADED"; _mode3 = "BLACK IN"; 0.55 fadeSound 0.1; "BLACK OUT" } else { (5 min (_delay + 1)) fadeSound 0.1; "PLAIN" }; "RYD_SPR_RespawnCurtain" cutText ["",_mode,0.55]; enableRadio false; clearRadio; if (RYD_SPR_Respawns > 0) then { RYD_SPR_Respawns = RYD_SPR_Respawns - 1; }; _respawnPos0 = selectRandom RYD_SPR_RespawnPositions; _respawnDir = 0; _respawnPos = switch (typeName _respawnPos0) do { case ("STRING") : { _respawnDir = markerDir _respawnPos0; (getMarkerPos _respawnPos0) }; case ("OBJECT") : { _respawnDir = getDir _respawnPos0; (getPosATL _respawnPos0) }; default { _respawnDir = _respawnPos0 select 1; (_respawnPos0 select 0); }; }; _newUnit = (group _killed) createUnit [(typeOf _killed),_respawnPos,[],0,"NONE"]; _newUnit allowDamage false; _newUnit setCaptive true; _newUnit enableSimulation false; _newUnit hideObject true; _newUnit setDir _respawnDir; //_newUnit setPosATL _respawnPos; _newUnit addEventHandler ["Killed",RYD_SPR_atKilled]; if (RYD_SPR_ChangedLoadout) then { _newUnit setUnitLoadout (missionNameSpace getVariable ["RYD_SPR_customLoadout",(getUnitLoadout _killed)]); }; _killedPos = getPosATL _killed; hideBody _killed; addSwitchableUnit _newUnit; [_newUnit,_mode2,_mode3,_killedPos] spawn { params ["_newUnit","_mode2","_mode3","_killedPos"]; _delay = RYD_SPR_DelayParameters select 0; _blackout = RYD_SPR_DelayParameters select 1; _externalView = RYD_SPR_DelayParameters select 2; _code = RYD_SPR_DelayParameters select 3; _camera = objNull; if (_externalView) then { _camPos = _killedPos getPos [2,(random 360)]; _camPos set [2,6]; _camera = ("camera" camCreate _camPos); camUseNVG (sunOrMoon < 0.5); _camera camSetTarget _killedPos; showCinemaBorder false; _camera cameraEffect ["internal", "BACK"]; _camera camCommit 0; _camPos = _killedPos getPos [((((_delay + 1) max 1)* 2) min 200),(random 360)]; _camPos set [2,((((_delay + 1) max 1) * 6) min 600)]; _camera camSetPos _camPos; _camera camCommit (_delay + 1); }; RYD_SPR_ppChrom = ppEffectCreate ["chromAberration", 1499]; RYD_SPR_ppChrom ppEffectAdjust [0.005,0.005,true]; RYD_SPR_ppCCor = ppEffectCreate ["ColorCorrections",1500]; RYD_SPR_ppCCor ppEffectAdjust [1, 0.4, 0, [0, 0, 0, 0], [1, 1, 1, 0], [1, 1, 1, 0]]; RYD_SPR_ppBlur = ppEffectCreate ["DynamicBlur", 1501]; RYD_SPR_ppBlur ppEffectAdjust [0.08]; RYD_SPR_ppGrain = ppEffectCreate ["FilmGrain", 1502]; RYD_SPR_ppGrain ppEffectAdjust [0.5, 2, 1, 1, 1, 0]; sleep 1; selectPlayer _newUnit; _newUnit call _code; BIS_DeathBlur ppEffectAdjust [0]; BIS_DeathBlur ppEffectCommit 0; RYD_SPR_ppCCor ppEffectEnable true; RYD_SPR_ppCCor ppEffectCommit (5 min (_delay + 1)); RYD_SPR_ppGrain ppEffectEnable true; RYD_SPR_ppGrain ppEffectCommit (5 min (_delay + 1)); RYD_SPR_ppBlur ppEffectEnable true; RYD_SPR_ppBlur ppEffectCommit (5 min (_delay + 1)); RYD_SPR_ppChrom ppEffectEnable true; RYD_SPR_ppChrom ppEffectCommit (5 min (_delay + 1)); _time = time; waitUntil { sleep 0.05; _countdown = ((_delay - (time - _time)) max 0) toFixed 1; "RYD_SPR_RespawnCurtain" cutText [(format ["<t color='#%2' size='1.75' align='left' shadow='1'>RESPAWN IN: %1</t>",_countdown,RYD_SPR_TextColor]),_mode2,0.01,true,true]; ((time - _time) > _delay) }; _camera cameraEffect ["terminate", "BACK"]; camDestroy _camera; camUseNVG false; ppEffectDestroy RYD_SPR_ppGrain; ppEffectDestroy RYD_SPR_ppBlur; ppEffectDestroy RYD_SPR_ppChrom; ppEffectDestroy RYD_SPR_ppCCor; 0.55 fadeSound 1; enableRadio true; _newUnit allowDamage true; _newUnit setCaptive false; _newUnit enableSimulation true; _newUnit hideObject false; "RYD_SPR_RespawnCurtain" cutText ["",_mode3,0.55]; }; } else { enableEndDialog; }; }; waitUntil { sleep 0.1; (alive player) }; missionNameSpace setVariable ["RYD_SPR_customLoadout",(getUnitLoadout player)]; player addEventHandler ["Killed",RYD_SPR_atKilled]; Setup - editor (base respawn) For a normal base respawn, in the editor place a marker and name it what you want and then add the name of the marker in quotes to this parameter like in the code below:   RYD_SPR_RespawnPositions = ["m1"]; //one will be chosen at random, markers, objects or arrays including coordinates and direction, for example: RYD_SPR_RespawnPositions = ["marker1","OtherMarker_2",someObject_1,[[100,200,0],120]];   Setup - editor (mobile respawn) To setup a mobile respawn in the editor place a vehicle and name it what you want and then add the name of the vehicle without quotes to this parameter like in the code below:   RYD_SPR_RespawnPositions = [myCar_1]; //one will be chosen at random, markers, objects or arrays including coordinates and direction, for example: RYD_SPR_RespawnPositions = ["marker1","OtherMarker_2",someObject_1,[[100,200,0],120]];   Setup - External Script Instead of using the init.sqf for the code, you can setup an external script that can be used:   1. Create a notepad/notepad++ document and copy and paste the code from above into it: 2. Save and name the document:  RYD_RSP.sqf and put it into your scenario folder. 3. Create a notepad/notepad++ document and add the following code to it:  execVM "RYD_RSP.sqf"; 4. Add both RYD_RSP.sqf and the init.sqf to your scenario folder where the mission.sqm is located.   Parameters There are 5 parameters you can adjust based on what you want to do in your scenario:   RYD_SPR_RespawnPositions = ["m1"];  "m1" is an example name of a marker, it will be chosen at random, markers, objects or arrays including coordinates and direction, for example: RYD_SPR_RespawnPositions = ["marker1","OtherMarker_2",someObject_1,[[100,200,0],120]]; If only one marker name is defined then you will only respawn at that marker, if more are defined then you will respawn randomly at one of the markers defined in the array.
RYD_SPR_Respawns = 3; 3 is the amount of respawns you want, it can be any number. If set with negative value  like -1 you will have unlimited respawns.
RYD_SPR_ChangedLoadout = true; If set to true, new unit will get old unit's loadout as it was at death, otherwise new unit will get default loadout of placed editor unit.   RYD_SPR_DelayParameters = [10,false,true,{}]; //[delay in seconds, black curtain, external view, optional code to be executed in the middle of countdown where _this equals new unit]
RYD_SPR_TextColor = "3a96d4"; //RESPAWN IN: color.   Credits Rydygier wrote the code. Both Gunter's and Rydygier's ideas.