Jump to content

How to script which target to attack?


haganinc

Recommended Posts

Anyone know if it is possible through scripting to change combat target priorities? For example, say I have an actor variable named Bob and two actor enemies called Enemy1 and Enemy2 that Bob is in combat with. How can I make it so Enemy2 is the higher priority target to attack and only attack Enemy1 if Enemy2 is dead or unreachable? I'm not sure how the AI chooses a target when multiple options are available.
Link to comment
Share on other sites

I have found this to work well

 

Event OnInit()
         RegisterForSingleUpdate(0.5)
EndEvent

Event OnUpdate()
    If (SomeCondition==true)
          If (YourActor.GetCombatTarget() !=YourEnemy1)  
             YourActor.StopCombat()
             YourActor.StartCombat(YourEnemy1)
         EndIf
    EndIf
    RegisterForSingleUpdate(0.5)
EndEvent

 

 

So basically, this periodically checks to see if the target is attacking the wrong target, and if it is, it tries to initiate combat with the right target. The target you want attacked, in this case, being YourEnemy1. The first if statement is basically some variable, possibly a global var that you could use to turn on or off this "prioritization." That second if statement will actually try to make your actor attack enemy 1 no matter how many other enemies there are, because any enemy other than YourEnemy1 that the actor is attacking will meet the requirement of that if statement. StopCombat() seems to be effective at clearing aggro, I found StartCombat() didn't always work without using StopCombat() right in front of it. Usually, the actor has gained the aggro of the target that it is attacking so well that the enemy will be attacking back, and thus hold your actors attention after a few updates. You could probably use another if statement and a count to see if the past X checks to see if the actor is attacking the right target came up ok, then you could probably turn off the looping onupdates.

 

 

What are you trying to do exactly? It sounds interesting. Controlling combat mechanics is fascinating to me.

Edited by elseagoat
Link to comment
Share on other sites

Thanks for the help, unfortunately I've tried this method all ready and haven't gotten it to work successfully. The problem is I don't want the enemy to attack back so it isn't drawing any attention at all even if I stop combat and restart it. Basically I am trying some type of taunting spell where I force an enemy to attack a different non-violent target other than the player. I guess I could try having the non-violent actor keep casting a detrimental area affect spell with no effect and see if that draws aggro.
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...