thy_raven 0 Posted March 30, 2008 Hello all, I have been searching the forum for how to make it so when a squad member dies they will re spawn close to a surviving member of their squad, but only if there are members of that squad left alive. An example is a leader, MG and 3 riflemen Leader and Mg are killed, but riflemen survive, after a designated 30 or so seconds, the Leader and the Mg would spawn in to rejoin the 3 riflemen that were left. I know something like this is possible using the GROUP re spawn option, but i wanted something where you would re spawn with the squad not just take over another squad member. is it also possible to add that if all the squad members were killed, then noone would re spawn. I'm afraid i'm not the most proficient person with scripting and editing so please keep any advice idiot proof for me. Any help anyone could offer me on this would be greatly appreciated, and if there is a way to also make it so that people will only re spawn when there are no enemies nearby then that would be even better, although i think maybe alot harder. Cheers, Raven Share this post Link to post Share on other sites
dachevs 1 Posted March 30, 2008 ok I'm not quite sure if this will work but you could try it. place a marker in the editor and leave everything blank open a new text document and put this in it-- <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> Spawn { "Respawn" setmarkertype "pick-Up" }; if group (!alive)) : goto "respawn" #respawn player setPos [(getMarkerPos "respawn") select 0, (getMarkerPos "respawn") select 1, 0] save it as respawn.sqs, make sure the file type is set to all files. then in the editor place-- this exec "respawn.sqs" under where it says Initialization. I am not sure if this will work at all. I'm not the greatest at scripting, but I know how to do some stuff, just not sure it will work because it is mixing many different kinds of scripts. Share this post Link to post Share on other sites
thy_raven 0 Posted March 30, 2008 i understand the 1st bit, about creating the .sqs file, but how do i get it under Initialization? I know how to do normal re spawns by putting the description.ext in the file with a user mission then exporting it to MP, is it that kinda thing? Share this post Link to post Share on other sites
loyalguard 15 Posted March 30, 2008 There is a scripting solution available but first I want to make sure you are aware of the "instant" respawn option. What instant respawn does is respawn the unit exactly where it died. Contrary to the title, it is not instantly though. The unit will respawn after the delay you set in the Description.ext expires. So, this might be your easiest solution but it also assumes that the rest of the squad is still near where the unit died. If this doesn't work for your purposes I can propose a scripting solution but it is a little more involved by using respawn markers, triggers, and the setPos command. Let us know. Regarding the second part of your question, is there more than one squad in your mission? If so it is a little more difficult to disallow respawns. If there is only one squad then you can simply end the mission with an end mission trigger with this in the condition line: {alive _x} count units groupname == 0; Substitute the name of your group for groupname. It is also a little more difficult to only allow respawns if there are no enemy nearby so I will have to address that later after I noodle a few things. I think it is possible but it is alittle more complicated. Share this post Link to post Share on other sites
thy_raven 0 Posted March 31, 2008 I only wanted the re spawn to work within a single squad, which might make life easier. I was aware of the Instant re spawn option, but was hoping to be able to get the New re spawned in player close to his buddies as if he was left behind to die or had to eject and died then he'd just be re spawning by himself. I suppose the best way to explain what i want is Like Battlefield 2's Squad re spawn system, where as long as there are some squad members alive then their mates can spawn off them like mobile spawn locations, but if everyone is dead the mission is over and you Fail. Share this post Link to post Share on other sites
thy_raven 0 Posted April 1, 2008 thank you for the trigger, that combined with the Instant re spawn is nearly what i was looking for, the only part that is missing is having the new member re spawn close to his mates. is there a way of getting the player to insta re spawn on another living player instead of their corpse? Share this post Link to post Share on other sites
loyalguard 15 Posted April 1, 2008 The easiest solution would be to immediately setPos them after respawn to a the position of someone else in his group. It would be easiest with the unit's leader. You'd probably have to do it in conjunction with a "Killed" event handler. This is untested so excuse any errors. Put this in the unit's init line: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addEventHandler ["killed", {_this execVM "respawn.sqf"}]; And create this script: respawn.sqf <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _unit = _this select 0; // Unit passed from killed event handler. waitUntil {alive _unit}; // Pause script until unit has respawned. _unit setPos (getPos leader _unit); // Move unit to his leader's position. If you don't want to limit the respawn to the unit's leader it is possible but more involved in that you have to create an array of other unit's in the respawning unit's group. Share this post Link to post Share on other sites
thy_raven 0 Posted April 2, 2008 I placed the event handler in the leaders initialization Box, and created a txt file and wrote the script in it and renamed it respawn.sqf and put it in the same folder as the Mission, then opened the Mission in editor and exported it as a MP mission. but the units just continue to respawn where they died, have i done something wrong? If it would be possible to make the players spawn on any alive member of the squad that would be preferable, would the scripting be extremely more complex? Share this post Link to post Share on other sites
loyalguard 15 Posted April 3, 2008 Sorry for the delay in the response...I have been pondering a few things. Let me see if I can come up with a working example and then post it if you can give me a day or so. p.s. Also, you need to put the init code into the init line of every unit in the group, not just the leader. Share this post Link to post Share on other sites
loyalguard 15 Posted April 4, 2008 Okay, I have just successfully tested this so hopefully it should work for you as well. Do the following: 1) Put the following code into the init line in the editor of every unit you want to respawn on their leader's position: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addEventHandler ["killed", {_this execVM "respawn.sqf"}]; 2) Create the following script named respawn.sqf and put it in your mission folder: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private ["_unit"]; // Introduce one or more local variables in the innermost scope. _unit = _this select 0; // Unit passed from killed event handler. if (player != _unit) exitWith{}; // If player is not the respawning unit then exit. waitUntil {alive player}; // Pause script until player has respawned. player setPos (getPos leader player); // Move player to his leader's position. Good luck! Share this post Link to post Share on other sites
thy_raven 0 Posted April 4, 2008 ok, i have it a try but the squad still keeps respawning on their corpses. Here is what i did, hopefully this might show where i'm going wrong Created a folder called description.ext and write; respawn = 2; respawnDelay = 30; then created another file called respawn.sqf and wrote; private ["_unit"]; // Introduce one or more local variables in the innermost scope. _unit = _this select 0; // Unit passed from killed event handler. if (player != _unit) exitWith{}; // If player is not the respawning unit then exit. waitUntil {alive player}; // Pause script until player has respawned. player setPos (getPos leader player); // Move player to his leader's position. i then put both these files in the mission folder and opened the editor, placed down a squad, made everyone in the squad playable and the leader set as player. then went in and placed the line; this addEventHandler ["killed", {_this execVM "respawn.sqf"}]; in each squad members initialization box. then saved it as a user mission, then exported it as a multiplayer mission and launched it as a MP map. to test to see if it worked, i made myself leader and show some of my squad mates to see where they re spawned, which they did on their corpses. Hopefully this might help show where i'm going wrong, have a missed something out or done something wrong?? Share this post Link to post Share on other sites
loyalguard 15 Posted April 4, 2008 to test to see if it worked, i made myself leader and show some of my squad mates to see where they re spawned, which they did on their corpses.Hopefully this might help show where i'm going wrong, have a missed something out or done something wrong?? Ok, I assume this means you were playing with AI squadmates. Is that correct or were your squadmates human? If you were playing with humans then please ignore this, but if you weren't then that is the source of at least part of the problem. The organic respawn system built into ArmA only works with human players. When AI die they do not respawn unless you create a special script that creates a new unit to replace the one that died. That would require completely different code. For my testing I created a mission with an AI leader and me as a unit in the AI leader's group and it worked fine. Everything else you described I did as well so it looks fine. Share this post Link to post Share on other sites
thy_raven 0 Posted April 4, 2008 just gave it a try and it worked wonderfully, the problem was i was playing as the leader. the only final question i have is, is it possible to make it so that the player will respawn on any remaining player (not AI) squad member left alive? instead of just the leader? possibly making every player a leader class or something? Share this post Link to post Share on other sites
loyalguard 15 Posted April 4, 2008 the only final question i have is, is it possible to make it so that the player will respawn on any remaining player (not AI) squad member left alive? instead of just the leader? possibly making every player a leader class or something? I'm glad you got it to work . Regarding the latest questions I am not mistaken, when a group leader dies in ArmA doesn't the next highest ranking unit take over as leader? If so, there is no need to write special code as a group will always have a leader even if down to one unit. If this is not the case we can re-address it. The code I have given you will always re-spawn the player on the current leader's position. Share this post Link to post Share on other sites
thy_raven 0 Posted April 4, 2008 thank you greatly my friend If the leader thing is the case then this script is everything i wanted. only other thing is can i make it so that if the entire squad dies, then they respawn somewhere else? I was thinking something like the trigger line from above, but instead of having the event being mission ends, it is possible to link it to another description.ext like file where i can put in the script that makes the player spawn like a base respawn? Share this post Link to post Share on other sites
loyalguard 15 Posted April 4, 2008 I was thinking something like the trigger line from above, but instead of having the event being mission ends, it is possible to link it to another description.ext like file where i can put in the script that makes the player spawn like a base respawn? Unfortunately you can't mix spawn types, but, you can still achieve something like you are looking for. First, instead of making your mission instant respawn, make it base respawn. Make sure you place a marker called respawn_west or as appropriate described here: Respawn Options. Then make the following changes to the script (untested but should work): <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_unit"]; _unit = _this select 0; if (player != _unit) exitWith{}; waitUntil {alive player}; if ({alive _x} count units group player > 0) then { player setPos (getPos leader player); }; What this does is when the player respawns a count is made of all of the units alive in the player's group. If there is at least 1 alive (>0) then the the player will spawn at the respawn_west marker and immediately be teleported to his leader's location. If not, the setPos command is ignored and the player will just spawn at the respawn_west marker. Share this post Link to post Share on other sites
thy_raven 0 Posted April 5, 2008 the code so far works wonderfully, tried it out with a group of friends last night, the only problem seems to be that if the leader of the group dies, he will only re spawn using the missions default re spawn setting. I thought a new leader would be elected from the remaining squad members left alive, but it appears that the leader keeps his rank and everything even if he dies. The only way we found to get the player who is leader to spawn off someone else was to have his score drop lower than someone else's in the squad, then everyone would spawn off of this player (the one with the highest score) instead. Is there a way of getting the ranks to not be Dependant on score and have it so someone who is left alive in the squad is elected leader until they in turn die? Share this post Link to post Share on other sites
loyalguard 15 Posted April 6, 2008 Ok, let me look at a few options and get back to you. Share this post Link to post Share on other sites
loyalguard 15 Posted April 6, 2008 Ok, here is some new respawn.sqf code for you. Basically when a group leader dies he leaves the group which lets the next highest ranking unit become leader and then on respawn the former leader re-joins the group as a non-leader. Make sure you put the addEventHandler code from above into EVERY unit in the group (including the initial leader) Update Edit: Code is now commented with full functionality. Feel free to delete comments in your actual script. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_unit", "_playerWasLeader", "_curGroup", "_newLeader"]; _unit = _this select 0; // The unit that was killed if (player != _unit) exitWith{}; // If the player is not the unit killed then exit. if (player == leader group player) then // If the player was the leader of his group execute the following code. { _playerWasLeader = true; // Record that the player was a leader for use after respawn. _curGroup = group player; // Record the group of which the player was the leader. [player] join GrpNull; // Make the player leave the group so someone else can take over as leader. }; waitUntil {alive player}; // Wait until the player respawns. if ({alive _x} count units _curGroup > 0) then // If there is at least one unit alive in the player's previous group then execute the follwing code. { if (_playerWasLeader) then // If the player was a leader then execute the following code. { _newLeader = leader _curGroup; // Record the new leader of the group. [player] join _newLeader; // Make the player re-join the group under the new leader. }; player setPos (getPos leader player); // Teleport the player to the group leader's position. }; // If no units are left alive then by default player will respawn and stay at the respawn marker. If you want the former leader to become leader again that is possible as well with some additional code. Share this post Link to post Share on other sites
thy_raven 0 Posted April 6, 2008 have been play testing the new re spawn script, i don't know if I've done something wrong again but now it seems to never re spawn off of another player, it always sends all dead players to the re spawn marker. the changing leader thing works tho, i've been play testing it with freinds and the group leader changes right, but the leader and players that die always respawn on the marker, not off eachother. Here's what i did, try and see where i've gone wrong Opened a mission, placed down a squad, placed the line in their initialization box, then placed a marker down called Respawn_west and placed it away from the group. made everyone playable and the leader as Player. Saved it as a user mission, closed editor, opened the mission older and created Description.ext ; respawn = 3; respawnDelay = 5; and respawn.sqf; private ["_unit", "_playerWasLeader", "_curGroup", "_newLeader"]; _unit = _this select 0; // The unit that was killed if (player != _unit) exitWith{}; // If the player is not the unit killed then exit. if (player == leader group player) then // If the player was the leader of his group execute the following code. { _playerWasLeader = true; // Record that the player was a leader for use after respawn. _curGroup = group player; // Record the group of which the player was the leader. [player] join GrpNull; // Make the player leave the group so someone else can take over as leader. }; waitUntil {alive player}; // Wait until the player respawns. if ({alive _x} count units _curGroup > 0) then // If there is at least one unit alive in the player's previous group then execute the follwing code. { if (_playerWasLeader) then // If the player was a leader then execute the following code. { _newLeader = leader _curGroup; // Record the new leader of the group. [player] join _newLeader; // Make the player re-join the group under the new leader. }; player setPos (getPos leader player); // Teleport the player to the group leader's position. }; // If no units are left alive then by default player will respawn and stay at the respawn marker. then loaded back up the editor, resaved the mission and then exported it as a multilayer mission, then tried to play it. Have i left something out? Share this post Link to post Share on other sites
loyalguard 15 Posted April 6, 2008 Everything looks ok...let me see if I can recreate your process and see if I can find any problems. It may not be until later tonight though. Share this post Link to post Share on other sites
loyalguard 15 Posted April 6, 2008 I found the problem. It was my code, not your implementation. I needed to move the line where _curGroup is defined to before the if-statements that way it is always recorded even if the player is not the leader. I tested it and it should now be fine now. New respawn.sqf below: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_unit", "_playerWasLeader", "_curGroup", "_newLeader"]; _unit = _this select 0; // The unit that was killed _curGroup = group player; // Record the players group. if (player != _unit) exitWith{}; // If the player is not the unit killed then exit. if (player == leader group player) then // If the player was the leader of his group execute the following code. { _playerWasLeader = true; // Record that the player was a leader for use after respawn. [player] join GrpNull; // Make the player leave the group so someone else can take over as leader. }; waitUntil {alive player}; // Wait until the player respawns. if ({alive _x} count units _curGroup > 0) then // If there is at least one unit alive in the player's previous group then execute the follwing code. { if (_playerWasLeader) then // If the player was a leader then execute the following code. { _newLeader = leader _curGroup; // Record the new leader of the group. [player] join _newLeader; // Make the player re-join the group under the new leader. }; player setPos (getPos leader player); // Teleport the player to the group leader's position. }; // If no units are left alive then by default player will respawn and stay at the respawn marker. Share this post Link to post Share on other sites
thy_raven 0 Posted April 7, 2008 Have just play tested the new script, everything appears to work really well now, the respawn on the leader works well too, only one problem. For some reason sometimes it doesn't let the origional squad leader spawn on the new leader. For an example, Leader1 dies, he will re spawn at re spawn point, but if anyone else dies they will re spawn on leader1. if Leader1 then dies again he will re spawn on the new leader (leader2) and if leader2 dies he will re spawn on leader1 but, if leader1 becomes leader again and dies, he will re spawn at the re spawn point instead. not sure why it doesn't like the original leader re spawning like the rest of the squad, but it works for someone who was never originally the leader. Share this post Link to post Share on other sites
loyalguard 15 Posted April 7, 2008 Quote[/b] ]Leader1 dies, he will re spawn at re spawn point, but if anyone else dies they will re spawn on leader1. So he respawns at the respawn_west marker location and stays there? If that is so it does not happen in my test mission. He should immediately respawn and get setPos'd to the new leader' location. I will take a look. Share this post Link to post Share on other sites