Jump to content
Sign in to follow this  
burdy

Only activate script for AI within squad (and player who ran the action)

Recommended Posts

Say I want to have a script teleport only the man who ran the script (addaction command in this case) and the spawned AI within his squad to a marker.

Currently the script is this :

// Get the destination.
_ldr = _this select 1; // Person who used the addAction
_dest = (_this select 3) select 0;

// Get a random direction
_dir = random 359;

// Move the person 15 meters away from the destination (in the direction of _dir)
{_x SetPos [(getMarkerPos _dest select 0)-10*sin(_dir),(getMarkerPos _dest select 1)-10*cos(_dir)]} forEach units group _ldr;

The script as it is teleports everyone in the squad of the man who ran the script. How would I make the script teleport only the man and AI within the squad and not other players within the squad (and only have the AI teleport if the player who runs the action is leading the AI and the AI are not in combat mode)

Thanks!

Edited by Burdy

Share this post


Link to post
Share on other sites

If the action wasn't shown only to the leader, then right after _ldr definition -

if(_ldr!=leader group _ldr)exitWith{}

Whether the player activating the script is his group's leader

In the forEach -

if(!isPlayer _x||(_x == leader group _x))then{...

As for detection of combat mode for the AI; there isn't a specific check for "whether AI is in a firefight" (as far as I know), if that's what you meant, but you can take a look at AI Combat Modes on Biki

Share this post


Link to post
Share on other sites
As for detection of combat mode for the AI; there isn't a specific check for "whether AI is in a firefight" (as far as I know), if that's what you meant, but you can take a look at AI Combat Modes on Biki

By AI in firefight I mean if there behavior is combat.. So i'm guessing that would be something along the lines of "if (_ldr behavior "COMBAT") then {};" ?

and this is what I gathered from your post. Currently this doesn't execute. Any idea where I went wrong?

{_x SetPos [(getMarkerPos _dest select 0)-10*sin(_dir),(getMarkerPos _dest select 1)-10*cos(_dir)]} if(!isPlayer _x||(_x == leader group _x))then{forEach units group _ldr}; if(_ldr!=leader group _ldr)exitWith{}

Edited by Burdy

Share this post


Link to post
Share on other sites

Sorry, I must have been too ambiguous.

The syntax for behaviour will allow to work as following -

if(behaviour _yourunit=="COMBAT"){...

You could use the check in either the same forEach to only teleport the specific AI units that aren't (or are) in "COMBAT" behaviour mode or you could use it in a preceding forEach (still for the same group, but to preliminarily check if any AI is (or is not) in "COMBAT" mode to judge whether the script should proceed to the teleporting forEach).

The part in the forEach I meant as -

{if(!isPlayer _x||_x == leader group _x)then{_x SetPos [(getMarkerPos _dest select 0)-10*sin(_dir),(getMarkerPos _dest select 1)-10*cos(_dir)]}} forEach units group _ldr;

Also, as a little sidenote, _dir = random 359;, will in fact leave out a degree between 359-360, so 360 is probably what you mean to use there (random does not include the last integer itself but generates floating point (decimal) numbers up to that point).

Edited by geqqo
Didn't close the php tags properly before...

Share this post


Link to post
Share on other sites

It appears that doing that script only allows teleportation of the SL + AI - not other players in the squad. So for example Im looking for the TP to work as an individual thing (where players can TP wherever), but if there an SL, they bring there AI with them (and if there AI are not in combat behavior... Couldn't grasp what to do from your comment on that). Currently the last part (minus behavior) works, but the individual TP does not (only SL players can).

Sorry for my total noobieness - hope to gather some stuff from all this :)

Share this post


Link to post
Share on other sites

So what you want is -

- squad leader can teleport with all units (players and AI) in the team

- non-leader player members can teleport on their own (without taking the AI)

?

That could be done as follows (if you want to write the position setting part only once; "..." stands for the regular position setting part in your code) -

{...}forEach (if(_ldr == leader group _ldr)then{units group _ldr}else{[_ldr]});

What this effectively does, is returning either the full group (if it's the leader) or only the player that triggered the action (if player is not the leader) for iteration by forEach. It's just using if inline to avoid typing the position setting code twice. This alone doesn't deal with behaviour limiting though.

As for the behaviour checking. What I meant was, that you would need another forEach before the one you already have that would go through the units in the group (if the player's a leader in the first place) but instead of setting the position would check for the behaviour. To avoid the inline if altogether you could use another variable to store the unit array so the script would end up like -

scopeName "actionscript";
_unitstoteleport = [];

//... your usual definitions here

if(_ldr == leader group _ldr){
    {if(behaviour _x == "COMBAT")then{breakOut "actionscript"}} forEach units group _ldr;
    _unitstoteleport = units group _ldr;
}else{
    _unitstoteleport = [_ldr];
};

{/* set position here */}forEach _unitstoteleport;

This will cancel the teleport altogether if any AI unit is in "COMBAT" behaviour. To leave behind only the specific AI units with the "COMBAT" behaviour you could still instead use the other forEach code-sample (the one with the inline if) but add inside the forEach a check -

{if(isPlayer _x||(!isPlayer _x && behaviour _x != "COMBAT"))then{/*set position here*/}}forEach ...

Edited by geqqo
Amended, again...; fixed according to below post

Share this post


Link to post
Share on other sites
So what you want is -

- squad leader can teleport with all units (players and AI) in the team

- non-leader player members can teleport on their own (without taking the AI)

?

That could be done as follows (if you want to write the position setting part only once; "..." stands for the regular position setting part in your code) -

{...}forEach (if(_ldr == leader group _ldr)then{units group _ldr}else{[_ldr]});

What this effectively does, is returning either the full group (if it's the leader) or only the player that triggered the action (if player is not the leader) for iteration by forEach. It's just using if inline to avoid typing the position setting code twice. This alone doesn't deal with behaviour limiting though.

As for the behaviour checking. What I meant was, that you would need another forEach before the one you already have that would go through the units in the group (if the player's a leader in the first place) but instead of setting the position would check for the behaviour. To avoid the inline if altogether you could use another variable to store the unit array so the script would end up like -

scopeName "actionscript";
_unitstoteleport = [];

//... your usual definitions here

if(_ldr == leader group _ldr){
    {if(behaviour _x == "COMBAT")then{breakOut "actionscript"}} forEach units group _ldr;
    _unitstoteleport = units group _ldr;
}else{
    _unitstoteleport = [_ldr];
};

{/* set position here */}forEach _unitstoteleport;

This will cancel the teleport altogether if any AI unit is in "COMBAT" behaviour. To leave behind only the specific AI units with the "COMBAT" behaviour you could still instead use the other forEach code-sample (the one with the inline if) but add inside the forEach a check -

{if(!isPlayer _x && behaviour _x == "COMBAT")then{/*set position here*/}}forEach ...

Just about what im looking for - SL can teleport with all units (JUST AI AND NOT PLAYERS) in Team. Essentially the first script you sent was closer (for reference).. So for example if the SL TP's somewhere, only him and his AI will go with him, not the human players. The non SL part is working perfectly, however :) .

Question - how do I implement the "COMBAT" Behavior thing as well (The one that leaves behind only specified AI)? This is what I got (and I know its incorrect, but not a clue on how to correct it).

{if(!isPlayer _x && behaviour _x == "COMBAT") then {_x SetPos [(getMarkerPos _dest select 0)-10*sin(_dir),(getMarkerPos _dest select 1)-10*cos(_dir)]}} forEach (if(_ldr == leader group _ldr)then{units group _ldr}else{[_ldr]});

Edited by Burdy

Share this post


Link to post
Share on other sites

Indeed, it should be

if((!isPlayer _x && behaviour _x != "COMBAT")||isPlayer _x) then {

(lacked the ||isPlayer _x part before as well as checked the opposite of intended behaviour; also fixed in above post)

Edited by geqqo
== -> !=

Share this post


Link to post
Share on other sites
Indeed, it should be

if((!isPlayer _x && behaviour _x != "COMBAT")||isPlayer _x) then {

(lacked the ||isPlayer _x part before as well as checked the opposite of intended behaviour; also fixed in above post)

Okay this works good

{if((!isPlayer _x && behaviour _x == "COMBAT")||isPlayer _x) then {  _x SetPos [(getMarkerPos _dest select 0)-10*sin(_dir),(getMarkerPos _dest select 1)-10*cos(_dir)]}} forEach (if(_ldr == leader group _ldr)then{units group _ldr}else{[_ldr]});

Now how can I edit this too make it so the SL TP that moves all units in the squad only moves the AI units in the squad and not the human units in the squad?

Edited by Burdy

Share this post


Link to post
Share on other sites

Well, that's what the ||isPlayer _x part does - if you use it, it will teleport the players as well (it doesn't take into account the behaviour for players though; if you wanted to apply the behaviour check to both players and AI alike, you'd simply remove all the isPlayer checks altogether (leaving just behaviour!="COMBAT")).

Share this post


Link to post
Share on other sites
Well, that's what the ||isPlayer _x part does - if you use it, it will teleport the players as well (it doesn't take into account the behaviour for players though; if you wanted to apply the behaviour check to both players and AI alike, you'd simply remove all the isPlayer checks altogether (leaving just behaviour!="COMBAT")).

Err... I dont think your understand what im getting at (or maybe its me not understanding the scripting lingo :p ). Taking out the "Isplayer" at the end or putting a "!" limits the TP too ai only - excluding the Squadleader.

I'm looking for it too work in 2 ways :

IF PLAYER IS NOT SQUAD LEAD ) Run as a normal TP (Just himself TP'ing.. That appears to be working)

IF PLAYER IS SQUAD LEADER) Run as Group TP but ONLY for himself and AI .

E.g an illustration would be this :

There are two players, Todd and Bill. Todd is a member of group one and Bill is SL of group one with 3 additional AI under his command (as well as, of course, Todd). When Todd runs the TP, only himself would move from point A to point B. When Bill runs the TP, only himself AND the ai move from point A to B, with Todd remaining untouched.

Edited by Burdy

Share this post


Link to post
Share on other sites

Sorry, that's what I get for being lazy and not testing my suggestions...

That's what you must be looking for -

(!isPlayer _x && behaviour _x != "COMBAT")||(_x==_ldr)

Which effectively means "If unit is AI with non-combat behaviour OR unit is the triggering player..." (... then teleport the unit).

This is still expecting the inline if solution (that determines the forEach input; which is either just the triggering player (if not squad leader) or all units in the group (both AI and players)).

Share this post


Link to post
Share on other sites
Sorry, that's what I get for being lazy and not testing my suggestions...

That's what you must be looking for -

(!isPlayer _x && behaviour _x != "COMBAT")||(_x==_ldr)

Which effectively means "If unit is AI with non-combat behaviour OR unit is the triggering player..." (... then teleport the unit).

This is still expecting the inline if solution (that determines the forEach input; which is either just the triggering player (if not squad leader) or all units in the group (both AI and players)).

EDIT : Got it working. Appears that your code you gave was a bit off with the ( ) at the end

{if((!isPlayer _x && behaviour _x == "AWARE")|| _x==_ldr) then {  _x SetPos [(getMarkerPos _dest select 0)-10*sin(_dir),(getMarkerPos _dest select 1)-10*cos(_dir)]}} forEach (if(_ldr == leader group _ldr)then{units group _ldr}else{[_ldr]});

BTW - An issue with the code (that doesn't effect me but may effect others browsing) is that

(!isPlayer _x && behaviour _x == "AWARE")

sets it so if the AI are in the behavior defined they TP, not the other way around. E.G "COMBAT" = AI only TP if they are in COMBAT mode, not any other.

Edited by Burdy

Share this post


Link to post
Share on other sites
...

sets it so if the AI are in the behavior defined they TP, not the other way around. E.G "COMBAT" = AI only TP if they are in COMBAT mode, not any other.

Thus the != in the given expression. You may want to take a look at the following page, in case this is confusing - Operators on Biki.

Appears that your code you gave was a bit off with the ( ) at the end

The parenthesizing in the provided expression was to be used inside the if condition-delimiting parentheses (possibly along with other conditions) not in place of them, thus your initial failure. The parentheses in the provided sample aren't actually necessary (provided you encase the whole expression in parentheses), it's more of a style/readability matter (in this particular case).

Share this post


Link to post
Share on other sites
Thus the != in the given expression. You may want to take a look at the following page, in case this is confusing - Operators on Biki.

The parenthesizing in the provided expression was to be used inside the if condition-delimiting parentheses (possibly along with other conditions) not in place of them, thus your initial failure. The parentheses in the provided sample aren't actually necessary (provided you encase the whole expression in parentheses), it's more of a style/readability matter (in this particular case).

Ah alright. I'm a bit new to in depth coding (past copy and pasting from others and making changes here and there) so excuse my ignorance ;)

Share this post


Link to post
Share on other sites

Alright, after further testing on a dedi, it appears the TP w/ AI does not run. It appears the script is ran server side I believe (as only host can TP AI for example if he hosts the server locally). How can I fix this?

Edit : Scratch that. Appears to be a different sort of issue related to "MoveinCargo" in MP. Maybe you would understand whats going on? Essentially I tp all of my units too an area and use :

"{_x moveincargo Boat_1} forEach thislist;"

As the Act. for when a unit arrives, and no matter what I do, Moveincargo does not work for AI (Guessing its a locality issue due too the command working for the host if the server is locally hosted).. Any on how to deal with this issue?

Edited by Burdy

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  

×