Jump to content
sprucewaine

Make second in command playable.

Recommended Posts

addMissionEventHandler ["EntityKilled", {
    params ["_dead"];

    if (_dead in switchableUnits) then {
        addSwitchableUnit (units _dead param [1, objNull]);
    };
}];

This makes it so that when a playable entity is killed, their second in command becomes playable.

Well if you test it, if you kill the first 2 guys really quickly, it doesn't work... or well the code works, but i don't know how to articulate what i want it to do. 

I know its because its selecting the 2nd item in an array, and it takes time for the array to readjust, but i don't know a compact and effective way for it to fix it self in case the first 2 units in the array are killed. 

Share this post


Link to post
Share on other sites

Hi

 

you can serialize all your command in a queue.

 

First create an array, and put all the request inside it

deleteAt 0, one by one each order

 

They will be always play in the good order.

 

 

 

Share this post


Link to post
Share on other sites
1 hour ago, code34 said:

Hi

 

you can serialize all your command in a queue.

 

First create an array, and put all the request inside it

deleteAt 0, one by one each order

 

They will be always play in the good order.

 

 

 

 

0.0 hmmm.... No idea where to begin with that. Could you give an example?

Share this post


Link to post
Share on other sites

Units _dead returns all units even dead ones (if the dead one has yet to be removed/cleaned from the group by the game engine). So after the second death in quick succession it is always choosing the second unit (params[1,objNull]) which is already dead.

Instead filter the array so you know you are only selecting from alive units.

addMissionEventHandler ["EntityKilled", {
    params ["_dead"];

    if ( isPlayer _dead ) then {
         units _dead select { alive _x } params[ [ "_newUnit", objNull ] ];
         if !( isNull _newUnit ) then {
         	addSwitchableUnit _newUnit;
        };
    };
}];

 

Share this post


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

Units _dead returns all units even dead ones (if the dead one has yet to be removed/cleaned from the group by the game engine). So after the second death in quick succession it is always choosing the second unit (params[1,objNull]) which is already dead.

Instead filter the array so you know you are only selecting from alive units.


addMissionEventHandler ["EntityKilled", {
    params ["_dead"];

    if ( isPlayer _dead ) then {
         units _dead select { alive _x } params[ [ "_newUnit", objNull ] ];
         if !( isNull _newUnit ) then {
         	addSwitchableUnit _newUnit;
        };
    };
}];

 

 

Thank you. 

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

×