Aller au contenu

Photo

Surrounding enemies join the attack, non-event breaking?


  • Veuillez vous connecter pour répondre
3 réponses à ce sujet

#1
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
I currently have a script in my mod which allows for surrounding enemies which are part of the same group as an attacked ally to join in on the fight.

This currently brings two problems with it:

1) Only enemies of the attacked enemy's teamID join in, no other enemies that stand around
2) It might mess with special encounters or special situations where enmies aren't supposed to join their allies

I've come up with the below script to work around point 1 and minimize the risks involved of point 2. I have two questions about this:

1) Is there a better way to be certain that a creature isn't part of a special encounter or has any other special commands ordered? I currently only allow creatures with INVALID commands to join the attack. Would it be enough to just exclude any creatures that have the "AI_COMMAND_RUN_SCRIPT" attached to them? Or perhaps only allow "INVALID" and "WAIT"?

2) For debugging purposes, I had all the surrounding creatures display their current commands. In one of the first areas after the origins (don't want to spoiler) there are archers standing on top of a cliff. They had current command "14" set, which - according to AI_Constants_h - equals:

AI_COMMAND_FLY = 14; // used currently only for *** (special creature)

Seems like that shouldn't be happening?



case EVENT_TYPE_ATTACKED:
{
 if(IsPartyMember(OBJECT_SELF) == FALSE
   && IsPartyMember(GetEventObject(ev, 0)) == TRUE)
 {
  object oAttacker = GetEventObject(ev, 0);
  object [] oAllies =
    GetNearestObjectByHostility(OBJECT_SELF, FALSE, OBJECT_TYPE_CREATURE, 5, 1, 1);
  int nMax = GetArraySize(oAllies);
  int i;

  for(i = 0; i < nMax; i++)
  {
   object oCreature = oAllies[i];

   if (GetCombatState(oCreature) == FALSE
     && IsPartyMember(oCreature) == FALSE
     && IsObjectHostile(oAttacker, oCreature) == TRUE)
   {
    command aCurr = GetCurrentCommand(oCreature);

    if(GetCommandType(aCurr) != AI_COMMAND_RUN_SCRIPT)
    {
     object oPartyMember = GetRandomPartyMember();
     object oAtt = oAttacker;
     object [] oPerceived = GetPerceivedCreatureList(oCreature, 1);
     int nSize = GetArraySize(oPerceived);

     if(IsPerceiving(oCreature, oPartyMember) == TRUE)
     {
      oAtt = oPartyMember;
     }
     else if(nSize != 0)
     {
      oAtt = oPerceived[Random(nSize)];
     }

     SetCombatState(oCreature, TRUE);
     command cAtt = CommandAttack(oAtt);
     WR_AddCommand(oCreature, cAtt);
    }
   }
  }
 }
 HandleEvent(ev); // this passes the event to the default handler of the event's target object
 break;
}

Modifié par Joshua Raven, 28 novembre 2009 - 10:33 .


#2
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
Well, I've just had a bug reported about the script crashing the game in the basement of Redcliff Castle when opening the first door to the area where the skeletons are trying to attack the prisoner. I'm going to build in some more checks to make sure the event only fires on very specific conditions.



My question still stands though, is this script a safe way to handle the kind of thing I'm trying to accomplish and which "AI Commands" should I check for and exclude from executing this script besides the "AI_COMMAND_RUN_SCRIPT"?

#3
Nodrak

Nodrak
  • Members
  • 144 messages
There is an enemy based shout system you might want to look into: http://social.biowar..._(dascript_type)

#4
Joshua Raven

Joshua Raven
  • Members
  • 182 messages
D'oh, if only I had found that final paragraph before I started work on this script, lol.

Still. It's a bit vague in its description. It signals "allies". So far all the descriptions I've read in the Toolset editor referred to "allies" as "creatures with the same group ID", which is not what I'm after, since there are plenty of situations where enemies stand 10m apart from each other but are in different groups.

Still, worth investigating, especially since my script apparently crashes the game * shrugs*

An extra check fixed the crash.... for now :o

Modifié par Joshua Raven, 28 novembre 2009 - 11:10 .