Neviothr 102 Posted October 31, 2015 Thought someone else might need something like this. Basically, after the player dies a unit spawns and is instantly made playable, has a 60-second cooldown. Enjoy :) init.sqf: null = [] execVM "playable.sqf"; playable.sqf: while {true} do { waitUntil { not alive player; }; "B_Soldier_F" createUnit [getMarkerPos "respawn", group player, "newUnit = this"]; addSwitchableUnit newUnit; sleep 60; hint "You many now respawn again."; }; Share this post Link to post Share on other sites
dakaodo 52 Posted April 23, 2016 This was a very handy little script for my SP purposes. Thank you so much for the concept! Does it work exactly as-is for you? My game hung up, but the task manager showed the arma3.exe was still very active. So I added a line after addSwitchableUnit newUnit;teamswitch; to open the player unit switch selection window. It showed me the game was generating an infinite number of new unit clones, all being added onto the bottom of my teamswitch selection list. Not sure if I missed something in copying it. :P But I solved it by forcing the player to directly switch into the spawned new player unit, as edited below. Also, after two test suicides in a row (using player setDamage 1;), the BIS_DeathBlur didn't go away, so I added in two lines courtesy of KillzoneKid to reset those PP effects. I staged a Heaven's Gate style mass auto-suicide, and the tenth one got stuck with DeathBlur, but the next respawn immediately fixed it. The cutText was an idea from someone else on a forum post that I can't find again, great little detail to mask the abrupt respawn which feels like Edge of Tomorrow or Groundhog Day. Instead of a single defined marker, I defined an global array of respawn markers in my init.sqf, which I can then pushBack or deleteAt to add or remove marker elements from the array. As the scenario progresses, the player will gain or lose ground, changing which spawn points will be available for random respawn. This is the selectRandom command. I'm not script-brave or savvy enough yet to tackle reimplementing the teamswitch dialogue in order to give the player an actual choice out of the remaining player-group playable AI units, or to give the player a choice as to which respawn point. :D So they'll just have to take their chances and deal with it -- it's war, after all! Not that one tiny little while loop will break the game, but I am practicing ways to optimize, so as a habit I'm using for _i step 0 loops instead of while loops (I don't know if there are ever cases where the regular old while loop is better), so don't mind that change. Overall, thanks again! This was a huge research timesaver, as I would have never thought to hijack the teamswitch like this for SP respawn. for "_i" from 0 to 1 step 0 do { waitUntil { !alive player; }; cutText ["Redeploying to a new unit","BLACK IN", 1]; "CUP_B_BAF_Soldier_SL_DDPM" createUnit [getMarkerPos (selectRandom respawn_array), group player, "newUnit = this"]; addSwitchableUnit newUnit; //teamswitch; selectPlayer newUnit; if ("ACE_Flashlight_XL50" in items player) then {} else {player addItem "ACE_Flashlight_XL50"}; if (backpack player == "") then {player addBackpack "CUP_B_Bergen_BAF"} else {}; BIS_DeathBlur ppEffectAdjust [0.0]; BIS_DeathBlur ppEffectCommit 0.0; }; 1 Share this post Link to post Share on other sites
Neviothr 102 Posted April 23, 2016 (edited) Come to think of it, with the knowledge I've gained since I could probably write something more efficient... Add a 'killed' event handler to the player on mission start, have it call a script when it fires, which will create a playable unit with a 'killed' event handler to call the same script... thus continuing the respawn loop. Here it is, might be better dunno :P Init.sqf player addEventHandler ["killed", {execVM "JIP.sqf"}]; JIP.sqf: "B_Soldier_F" createUnit [getMarkerPos "respawn", group player, "newUnit = this"]; newUnit addEventHandler ["killed", {execVM "JIP.sqf"}]; addSwitchableUnit newUnit; Edited April 23, 2016 by cx64 1 1 Share this post Link to post Share on other sites
jshock 513 Posted April 23, 2016 If you use the "createUnit array" it returns the created unit so you don't have to use a global variable: https://community.bistudio.com/wiki/createUnit_array _newUnit = group player createUnit [typeOf player,getMarkerPos "respawn",[],0,"NONE"];I also used "typeOf player" to generalize your code a bit more that way people don't have to hard code the classname of the player entity, simply just see what it is (that way it works easily with mods that may not readily make available classnames).It may also be safer to pass in the killed entity into the script as well, in case "player" doesn't exist for whatever reason when the JIP script executes: ... addEH ["Killed", {[(_this select 0)] execVM "JIP.sqf";}]; //JIP.sqf params ["_oldUnit"]; _newUnit = group _oldUnit createUnit [typeOf _oldUnit...]; .... 2 Share this post Link to post Share on other sites
dakaodo 52 Posted April 23, 2016 jshock, thank you for weighing in with your refinements; at one point I had the global variable = nil at the end of the script to kill it off after each use -- not elegant at all. cx64, I actually tried to turn it into an eventhandler previously, but I'm still shaky on syntax for referring to variables and objects from ingame and the init when used in separate scripts. jshock's example really cleared it up for me, and the new script works great (tested via more mass suicides) including the teamswitch without that infinite respawned player unit (I must definitely have been doing something wrong before). Here it is in its final form from you guys: //JIP.sqf params ["_oldUnit"]; _newUnit = group _oldUnit createUnit [typeOf _oldUnit,getMarkerPos "respawn",[],0,"NONE"]; _newUnit addEventHandler ["Killed", {[(_this select 0)] execVM "scripts\JIP.sqf";}]; addSwitchableUnit _newUnit; BIS_DeathBlur ppEffectAdjust [0.0]; BIS_DeathBlur ppEffectCommit 0.0; //init.sqf player addEventHandler ["Killed", {[(_this select 0)] execVM "scripts\JIP.sqf";}]; 1 Share this post Link to post Share on other sites
easyeb 137 Posted July 11, 2016 Is it possible to get this script to remember custom soldiers? I'd like for me and my AI units to respawn as they died. Share this post Link to post Share on other sites
kylania 568 Posted July 11, 2016 https://forums.bistudio.com/topic/139848-getset-loadout-saves-and-loads-pretty-much-everything/page-11#entry3035606 Share this post Link to post Share on other sites
dakaodo 52 Posted July 19, 2016 Didn't work. I believe that's b/c the way to get a unit's loadout has changed. However, the OnPlayerKilled.sqf and OnPlayerRespawn.sqf will still do their job. So you can figure out how to get their loadouts on death, then assign loadout on respawn. Share this post Link to post Share on other sites
eigenfield 0 Posted December 16, 2023 The above snippets, indeed contains incantations to respawn a player. But how do we make the other units follow the commands ordered by the respawned one? Share this post Link to post Share on other sites