Jump to content
Sign in to follow this  
jorxe33

Make only leaders team switchable

Recommended Posts

hi everyone, I have a script that allows to switch only team leaders switchable (activated by a radio trigger).

It works well, but the problem is that it let me to select team leaders of blufor and opfor and I only want to select blufor leaders

(by teamswitch) Here is the script:

// Arma 2 function

private ["_Units","_NumUnits","_ui","_unit","_group","_isleader","_isplayer"];

_Units = allunits;
_NumUnits = count _Units;

for [{ _ui = 0 }, { _ui < _NumUnits }, { _ui = _ui + 1 }] do {

_unit = _Units select _ui;
_group = group _unit;
_isleader = ((leader _group) == _unit);
_isplayer = (player == _unit);

if (_isleader || _isplayer) then {

	addSwitchableUnit _unit;
} else {
	removeSwitchableUnit _unit;
};
};

nil;

Share this post


Link to post
Share on other sites

There are other ways to do this... but try something like this. This should fit in with what you already have.

_isside = ((side _unit) == WEST);

Then...

if ((_isleader || _isplayer) && _isside) then {

Share this post


Link to post
Share on other sites

ok checked but is not working, now when I activated the script by radio trigger I can switch all units ¿Is there a way to select only squad leaders of blufor?

Share this post


Link to post
Share on other sites

ok checked and it works well! :)

I only have a question, I have another radio trigger for return to all units switchable (west), but when I activated it shows all units teamswitchable (west and east), the name is MakeUnitsTeamSwitchable.sqf

and contains

// Arma 2 function

private ["_Units","_nunits","_ui"];

_Units = allunits;
_nunits = (count _Units);

for [{ _ui = 0 }, { _ui < _nunits }, { _ui = _ui + 1 }] do {

_unit = _Units select _ui;
addSwitchableUnit _unit;
};

nil;

I tried to put this:

// Arma 2 function

private ["_Units","_nunits","_ui"];

_Units = allunits;
_nunits = (count _Units);

for [{ _ui = 0 }, { _ui < _nunits }, { _ui = _ui + 1 }] do {

_unit = _Units select _ui;
addSwitchableUnit _unit;
       side _unit == WEST;
};

nil;

but not works, when I activate it shows all units teamswitchable (west and east).

Share this post


Link to post
Share on other sites

Well... do the same sort of thing as before... check if the unit you pulled from the array is WEST and if it is then make it switchable.

// Arma 2 function

private ["_Units","_nunits","_ui"];

_Units = allunits;
_nunits = (count _Units);

for [{ _ui = 0 }, { _ui < _nunits }, { _ui = _ui + 1 }] do {
_unit = _Units select _ui;
       [color="#FF0000"]if (side _unit == WEST) then {
           addSwitchableUnit _unit;
       };[/color]
};
nil;

Share this post


Link to post
Share on other sites

I tested, it works like a charm!;)

I just noticed a small detail: when I select (by a radio trigger) "only team leaders switchable" I can see in the teamswitch menu only the leaders, ok, but when some of them die, the soldier with the rank nearest becomes the leader but not appear in this menu, I have to activate "all units teamswitchable" and again activate "only team leaders switchable" to it appears in the teamswitch menu.

Share this post


Link to post
Share on other sites

OK...this is more complicated. You will have to have some way of running a script every time a switchable unit (leader) dies.

You can use addEventhandler for this.

Add the code in red to what you already have above.

for [{ _ui = 0 }, { _ui < _nunits }, { _ui = _ui + 1 }] do {
_unit = _Units select _ui;
       if (side _unit == WEST) then {
           addSwitchableUnit _unit;
           [color="#FF0000"]_unit addeventhandler ["KILLED",{nul = [_this] execVM "script.sqf"}];[/color]
       };
};

Then create the necessary little script.... called script.sqf for want of a better name :)

script.sqf:-

_array = _this select 0;

_victim = _array select 0;
_group = group _victim;

sleep 5;

addSwitchAbleUnit (leader _group);

When the unit is killed...the new leader of the group is made switchable.

The sleep is necessary because the unit doesn't seem to "die" right away and remains the leader for a few seconds.

Sleep 5 works for me.... you may be able to shorten the time. I didn't experiment much there.

The code below is the same thing but has an extra check so that only WEST Leaders are made switchable first time around.

for [{ _ui = 0 }, { _ui < _nunits }, { _ui = _ui + 1 }] do {
_unit = _Units select _ui;
       if ((side _unit == WEST) [color="#FF0000"]&& (_unit == leader group _unit)[/color]) then {
           addSwitchableUnit _unit;
           [color="#FF0000"]_unit addeventhandler ["KILLED",{nul = [_this] execVM "script.sqf"}];[/color]
       };
};

EDIT: Something was bugging me here and I checked.

You don't need to use leader group _unit..... you can just use leader _unit

Haven't changed the code above because it works as is... and then if I do... this edit will make no sense.

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

it does not work, now if I call by radio trigger "only Leaders Teamswitchable" I can see only the team leaders, that is right but if after that I activated by radio trigger "Make Units TeamSwitchable" can not switch all units, I only still see the team leaders.

Share this post


Link to post
Share on other sites

Why not just make them all switchable and then just switch to a Teamleader?

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
Sign in to follow this  

×