Jump to content
Sign in to follow this  
sproyd

How to execute a script ONLY if the unit is AI

Recommended Posts

So I have 3 Playable slots in a SP/Co-Op Mission. I want to execute a script that will only execute on the units in a group that are controlled by AI and not human players. There seems to be a bug where when the script executes on a non-AI infantry that it deletes items or something.

Anyway is there a command like this

if soldier1 = AI then AssignItem "NVGoggles"

or

{if _x = AI then AssignItem "NVGoggles"} foreach unit group player

(the syntax is probably wrong but you get the idea of what I'm trying to do)

Thanks!

Share this post


Link to post
Share on other sites

have you tried using switchableunits (SP) vs playableunits in MP?

you could make an array of all units in the game

_playable= playableunits;_switchunits= switchableunits;

and then remove the playable units from it. that will leave you with all the Players that are left.

_currentplayers = _playable - ["_switchunits"];

that is the only way I have found to work when removing values in an array from an array.

if you just want the AI that are in game at any time then switchableunits would give you that.

Edited by KevsnoTrev

Share this post


Link to post
Share on other sites

actually you are not removing anything, your currentplayers equals playableunits, this is why it works.

Share this post


Link to post
Share on other sites

_units = (if (isMultiplayer) then {playableUnits} else {switchableUnits});

_units = all playable players or AI players in a single or multiplayer game. So this does NOT contain AI units which are non-playable.

allUnits = All UNITS ingame (players and AI playable and non-playable) except from Agents.

_aiUnits = [];
{
_unit = _x;
if !(isPlayer _unit) then
{
	_aiUnits set [count _aiUnits, _unit];
};
}foreach allUnits;

Share this post


Link to post
Share on other sites
actually you are not removing anything, your currentplayers equals playableunits, this is why it works.

Doh!:banghead:

knew i got it the wrong way round somewhere.

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  

×