Jump to content
Doom11_CZ

Respawn as group unit

Recommended Posts

So, here's my case:
I am trying to respawn player as other member of group. First time it works, but when i die in the second (new) unit, the game stays at dead screen. And even the "after dead menu" with respawn etc. doesn't show.
Here's my init.sqf:
 

[player] spawn {

_player = _this select 0;


_player addEventHandler ["Killed", {
    params ["_unit", "_killer", "_instigator", "_useEffects"];
    
    _unitsArray = [];
    _unitsArray = switchableUnits select { alive _x };
    _randomUnit = selectRandom _unitsArray;
    selectPlayer _randomUnit;
    (group _randomUnit) selectLeader _randomUnit;
}];
};

I thought that it doesn't work bc the variable _randomUnit is already assigned, so I tried adding this to the event handler:

if ( !(isNil _randomUnit)) then {_randomUnit = nil} else {code in event handler}

but doesn't work either.

Thanks for any help guys. 🙂

Share this post


Link to post
Share on other sites

Just from a quick look, I think I see what the problem is.

 

You are adding "killed" event handler to the original player unit. <- Good

Then upon death, you call selectPlayer to new unit, and player is now controlling that new unit. <- Good

But you never add "killed" event handler to the new unit. <- Bad

 

So when that new player unit dies, there is no "killed" event handler (on that new unit) to take effect.

Share this post


Link to post
Share on other sites

I thought that when i add event handler to the player it always assign it to the unit the player is actually "using"
Also I noticed my another mistake, so i added code from event handler also into "then" syntax. Bc it would do nothing if the var was nil 😄

Share this post


Link to post
Share on other sites
27 minutes ago, madrussian said:

Just from a quick look, I think I see what the problem is.

 

You are adding "killed" event handler to the original player unit. <- Good

Then upon death, you call selectPlayer to new unit, and player is now controlling that new unit. <- Good

But you never add "killed" event handler to the new unit. <- Bad

 

So when that new player unit dies, there is no "killed" event handler (on that new unit) to take effect.



I thought that when i add event handler to the player it always assign it to the unit the player is actually "using"
Also I noticed my another mistake, so i added code from event handler also into "then" syntax. Bc it would do nothing if the var was nil 😄

Share this post


Link to post
Share on other sites
17 minutes ago, Doom11_CZ said:

I thought that when i add event handler to the player it always assign it to the unit the player is actually "using"

 

Not in my experience.  Yeah, you'll need that "killed" EH on each new selectPlayered guy.

 

Btw - If I read between the lines, what it sounds like you are trying to do is super complicated (having spent many moons on something similar myself).  Have you tried simply using the game's built-in group respawn mechanics?

^ Of course, that will only work in MP (multi-player).  And only works for your own group.

 

If you want group respawn in SP (single player), check out my mission... in my signature.  My Group Linked Respawn (GLR) system is pretty easy to break out and insert into your own mission.  You can span group respawn across multiple friendly groups, add new units on-the-fly, give yourself limited lives that show up as little soldier icons that fade out every time you get killed, and more.  Lots of options.

 

Share this post


Link to post
Share on other sites
2 hours ago, madrussian said:

 

Not in my experience.  Yeah, you'll need that "killed" EH on each new selectPlayered guy.

 

Btw - If I read between the lines, what it sounds like you are trying to do is super complicated (having spent many moons on something similar myself).  Have you tried simply using the game's built-in group respawn mechanics?

^ Of course, that will only work in MP (multi-player).  And only works for your own group.

 

If you want group respawn in SP (single player), check out my mission... in my signature.  My Group Linked Respawn (GLR) system is pretty easy to break out and insert into your own mission.  You can span group respawn across multiple friendly groups, add new units on-the-fly, give yourself limited lives that show up as little soldier icons that fade out every time you get killed, and more.  Lots of options.

 



I'll check it, thanks. I thought about checking in init of every unit of group, if the unit is player and if it is, do something like execVM and the code i posted. Or some loop which will wait until player spawn into new unit. But just my ideas 😄 I am like week in Arma scripting/editing, so..

Share this post


Link to post
Share on other sites
4 hours ago, Doom11_CZ said:

I thought that when i add event handler to the player it always assign it to the unit the player is actually "using"

No you are not applying it to the player, but to the unit the player is using at the time the eventHandler applied. But selectPlayer changes this unit so there is no EH applied for subsequent deaths.

 

3 hours ago, Doom11_CZ said:

I thought about checking in init of every unit of group, if the unit is player and if it is, do something

Maybe MEH of EntityKilled or EntityRespawned?

Share this post


Link to post
Share on other sites
17 hours ago, Larrow said:

No you are not applying it to the player, but to the unit the player is using at the time the eventHandler applied. But selectPlayer changes this unit so there is no EH applied for subsequent deaths.

 

Maybe MEH of EntityKilled or EntityRespawned?



Ty for respond, but I don't understand what is the difference between entity killed and just killed.. both works/return with the object I am playing for .. or not? Or where/whom i should put this EH ?

Share this post


Link to post
Share on other sites
17 hours ago, Larrow said:

No you are not applying it to the player, but to the unit the player is using at the time the eventHandler applied. But selectPlayer changes this unit so there is no EH applied for subsequent deaths.

 

Maybe MEH of EntityKilled or EntityRespawned?



My another idea was do for loop, something like:



[player] spawn {

_unit0 = _this select 0;


for [{_i = 0},{_i < (count (units group _unit0))},{_i = _i + 1}] do {

(_unit+str _i) addEventHandler ["Killed", {
    params ["_unit", "_killer", "_instigator", "_useEffects"];
    
    _unitsArray = [];
    _unitsArray = switchableUnits select { alive _x };
    (_unit + str (_i+1)) = selectRandom _unitsArray;
    selectPlayer (_unit + str (_i+1));
    (group (_unit + str (_i+1))) selectLeader (_unit + str (_i+1));
}];
//some condition to "stop" the loop until (_unit + str (_i+1)) is dead
};
};


Or something like this.. i think it's really very complicated overkill, but that's just my idea 😄

The idea is that the loop will start with player and then it will add EH to the next unit due to the _i var .. but I can't think of any reasonable condition.. I don't know if the EH will work if i write condition: waitUntil {!alive (_unit + str(_i+1))}; ?

 

Share this post


Link to post
Share on other sites

Curious what are you trying to accomplish, more broadly?  Btw - Have you tried the game's built-in group respawn?

  • Like 1

Share this post


Link to post
Share on other sites
On 11/26/2020 at 1:21 AM, madrussian said:

Curious what are you trying to accomplish, more broadly?  Btw - Have you tried the game's built-in group respawn?

 

Well, I gave up and used game's "playable" option on group units. Also when I spawn reinforcements I set them playable too. My goal was to do automatic "respawn" mechanism, which will "select player" another unit from players group. And to get this working, I need to give killed EH to the new selected unit, so the respawn could repeat. I haven't tried bult-in group respawn mechanism. I thought that it would be really great to have nice and dynamic respawn system, so u don't have to choose respawn option and then select another group member during firefight.
Hope you get my idea, bc I am from CZ and my english isn't on point sometimes 😄

Share this post


Link to post
Share on other sites

Good deal, more or less yes all that makes sense.

 

So you want an automatic "takeover" style respawn that upon player death, transfers player control to another living unit within the player's group.  And specifically, when you die you want this takeover to happen automatically, without having to view or interact with any User Interface.  And you're looking at using the selectPlayer command as part of the overall solution.  Does that all sound right?

 

Btw also - Sounds like you are trying to do this in MP (multi-player)...  Just to clarify, would you like this to work in SP (single player), MP, or both?

 

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

×