Aller au contenu

Photo

trying to come up with a script that makes enemies switch target


  • Veuillez vous connecter pour répondre
1 réponse à ce sujet

#1
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
when the player has run away for a short while. the reason is that in some battles i don't want it for the player to run around with his character being chased by monsters while his friendly NPC's hack away at the monsters and the monsters doesn't attack back.

the custom ai event might be a good place to start perhaps? If i check the distance between the PC and the monsters then i could see if they're standing next to each other or if the PC is a bit of a distance away and if that's the case the enemy should pick another target? if anyone got any good ideas for a different way of doing it or functions that can be used for the thing i thought about in this post i would appriciate any help..

#2
FergusM

FergusM
  • Members
  • 460 messages
Your solution is not bad, but you might still have problems where the enemy is chasing the PC but always very close. Also, what if your party member is using ranged attacks? It might be worth trying to use a heartbeat event (InitHeartbeat and EVENT_TYPE_HEARTBEAT_2) to simply reduce threat every round if the target IsPartyMember, meaning the player has to constantly attack to keep their attention. But that might have problems if none of the allies are able to catch/hit the enemy. Note also that using custom ai can be a little tricky because you might find it hard to keep normal attacking/ability use functional.

Anyway, you'll want to look at the functions GetDistanceBetween, GetThreatEnemy, ClearEnemyThreat, GetThreatValueByIndex and UpdateThreatTable.

Something like this might work, but you'd have to tinker with the numbers. Just reducing the threat to the main target if they're a little far away and a player.

InitHeartbeat(oCreature,1.0); //somewhere else, tinker with time

case EVENT_TYPE_HEARTBEAT_2:
{
object target = GetThreatEnemy(OBJECT_SELF,0);
if (IsPartyMember(target) && GetDistanceBetween(OBJECT_SELF,target) > 4.0) //tweak distance. Or maybe remove distance requirement
{
//ClearEnemyThreat(OBJECT_SELF,target) //this is if you want to just totally clear it
UpdateThreatTable(OBJECT_SELF,target,-5.0) //tweak threat value change
}
break;
}

Modifié par FergusM, 22 octobre 2010 - 08:29 .