Jump to content
Sign in to follow this  
mr_shadow

Force Ai to aatck if player is in trigger

Recommended Posts

Hello, I would like to know if this is possible to force a freindly AI to attack a player if he is in trigger list, however once he left it will be stopped.

Share this post


Link to post
Share on other sites

Something with doTarget may be up for grabs, using the onAct and onDeact fields of your trigger with:

//in trigger condition field

player in thisList;

Share this post


Link to post
Share on other sites

Adjust the player rating to -50000 when he's in the trigger and then reset it to something like 5000 when he leaves.

Share this post


Link to post
Share on other sites

Yes it should still work, as long as the rating of the unit is below -2000 it is set to enemy to all sides.

addRating

Rating Values

So your trigger would look something like this:

Condition:

player in thisList;

OnAct:

player addRating -100000;

OnDeact:

player addRating 200000;//just to be sure that the rating goes back up to a "positive"

Share this post


Link to post
Share on other sites

There has already been a similar post to that issue, but I can't find it right now, so I'll just post my code again:

[color=#FF8040][color=#1874CD]_aiUnit[/color] [color=#191970][b]spawn[/b][/color]
[color=#8B3E2F][b]{[/b][/color]
   [color=#191970][b]while[/b][/color] [color=#8B3E2F][b]{[/b][/color][color=#191970][b]sleep[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b];[/b][/color] [color=#191970][b]alive[/b][/color] [color=#000000]_this[/color][color=#8B3E2F][b]}[/b][/color] [color=#191970][b]do[/b][/color]
   [color=#8B3E2F][b]{[/b][/color]
       [color=#191970][b]scopeName[/b][/color] [color=#7A7A7A]"unitAliveScope"[/color][color=#8B3E2F][b];[/b][/color]

       [color=#8B3E2F][b]{[/b][/color]
           [color=#191970][b]if[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#191970][b]isPlayer[/b][/color] [color=#000000]_x[/color] [color=#8B3E2F][b]&[/b][/color][color=#8B3E2F][b]&[/b][/color] [color=#8B3E2F][b]{[/b][/color][color=#000000]_this[/color] [color=#191970][b]distance[/b][/color] [color=#000000]_x[/color] [color=#8B3E2F][b]<[/b][/color] [color=#FF0000]200[/color][color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]then[/b][/color]
           [color=#8B3E2F][b]{[/b][/color]
               [color=#000000]_this[/color] [color=#191970][b]doTarget[/b][/color] [color=#000000]_x[/color][color=#8B3E2F][b];[/b][/color]
               [color=#000000]_this[/color] [color=#191970][b]doFire[/b][/color] [color=#000000]_x[/color][color=#8B3E2F][b];[/b][/color]
               [color=#191970][b]waitUntil[/b][/color] [color=#8B3E2F][b]{[/b][/color][color=#191970][b]sleep[/b][/color] [color=#FF0000]3[/color][color=#8B3E2F][b];[/b][/color] [color=#8B3E2F][b]![/b][/color][color=#191970][b]alive[/b][/color] [color=#000000]_this[/color] [color=#8B3E2F][b]|[/b][/color][color=#8B3E2F][b]|[/b][/color] [color=#8B3E2F][b]{[/b][/color][color=#000000]_this[/color] [color=#191970][b]distance[/b][/color] [color=#000000]_x[/color] [color=#8B3E2F][b]>[/b][/color] [color=#FF0000]200[/color][color=#8B3E2F][b]}[/b][/color] [color=#8B3E2F][b]|[/b][/color][color=#8B3E2F][b]|[/b][/color] [color=#8B3E2F][b]{[/b][/color][color=#8B3E2F][b]![/b][/color][color=#191970][b]alive[/b][/color] [color=#000000]_x[/color][color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]
               [color=#191970][b]breakTo[/b][/color] [color=#7A7A7A]"unitAliveScope"[/color][color=#8B3E2F][b];[/b][/color]
           [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]
       [color=#8B3E2F][b]}[/b][/color] [color=#191970][b]forEach[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#000000]_this[/color] [color=#191970][b]nearEntities[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"Man"[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]350[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]
[color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]
[/color]

...where _aiUnit is the respective AI unit you want to force to attack the player.

Kudos to Killzone_Kid for his SQF to BBCode Converter.

With this code, the AI unit recognizes any player within 350 meters and will shoot at the first one which gets closer than 200 meters. If the shot at player leaves the 200m radius and another player comes that close, the AI unit will switch and attack that "new" player. All this happens until either the targeted player or the AI unit is dead.

EDIT:

I just re-read the title and saw that the issue is about a trigger and not a unit independent from any triggers. So sorry, my bad. But maybe at some point, you are interested in that code so I'll leave it here, just in case.

Regards,

Johnny

Edited by Heeeere's Johnny!

Share this post


Link to post
Share on other sites

As stated, doFire is what you want... I have used this to force opfor to fire on civilians for hostage missions

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  

×