Aller au contenu

Photo

Issues storing attack target


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

#1
manageri

manageri
  • Members
  • 394 messages
I'm using GetAttemptedAttackTarget() to store the creature my char is attacking at the end of a round, then another script gets that from a local, turns rapid shot on, and continues attacking the stored target the next round. The scripts are working ok, except that GetAttemptedAttackTarget() seems to be storing some random gibberish half the time. Here's the script storing it:

object oTarget = GetAttemptedAttackTarget();
string sAttackTarget;
SetLocalObject(OBJECT_SELF, sAttackTarget, oTarget);
string sTarget = ObjectToString(oTarget);
SpeakString(sTarget);

ClearAllActions(FALSE);

DelayCommand(0.5, ExecuteScript("mi_override", OBJECT_SELF));   //runs the second script after enough delay to change rounds
-----------------------------------------------------------------------
And here's the script retrieving it:

string sAttackTarget;
object oTarget = GetLocalObject(OBJECT_SELF, sAttackTarget);

if (GetActionMode(OBJECT_SELF,ACTION_MODE_RAPID_SHOT))
    {
    DelayCommand(0.1, ActionAttack(oTarget, FALSE));
    }
    else
    {
     ClearAllActions(FALSE);
    SetActionMode(OBJECT_SELF, ACTION_MODE_RAPID_SHOT, 1);
        if (GetActionMode(OBJECT_SELF,ACTION_MODE_RAPID_SHOT))
            {
             DelayCommand(0.1, ActionAttack(oTarget, FALSE));
            }
    }           


Is it supposed to store the tag of the creature or what? What I get out of the SpeakString on the first script when testing is "c50" at first, then usually after a few rounds it says "7f000000" and stops attacking the target.

#2
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
You are not setting sAttackTarget as anything in your second line there, its an empty string. To get the target's tag, try this line instead:



string sAttackTarget = GetTag(oTarget);

#3
MasterChanger

MasterChanger
  • Members
  • 686 messages
I think the issue may be bigger than that. Have you actually found that GetAttemptedAttackTarget returns a valid object where you call it? When I was working on custom AI, I found that you really had to determine your own target; all the Get____Target functions returned invalid objects.

What I was able to narrow this down to was that the target was only defined within a narrow slice of DetermineCombatRound: Seemingly between the  __TurnCombatRoundOn(TRUE) and  __TurnCombatRoundOn(FALSE) calls. The call in DCR to any special AI scripts (which I believe The Fred may be using) is actually before the call to __TurnCombatRoundOn(TRUE).

However, this may not be a big issue. Combat AI is partially about choosing a more appropriate target than the stock AI will do, or choosing to use a different power, in which case you still have to select a target. If this is the case with what you're working on, then simply store the target you wish the AI to attack directly as a local object.

For reference, the file that DCR and related functions are found in is nw_i0_generic.

#4
manageri

manageri
  • Members
  • 394 messages
What I'm trying to do is emulate puppet mode with the one exception of forcing rapid shot on every round since the standard AI will shut combat modes off sometimes even in puppet mode. The first script is in "gb_comp_combat" and it's actually being run with puppet mode on, which runs the "mi_override" script which is just a copy paste of the HotU AI override code used by The Fred, which then runs whatever custom AI script has been assigned for the char with The Fred's tool, in this case the forced rapid shot script. I don't think there's a DetermineCombatRound running at any time.



The c50 returned by GetAttemptedAttackTarget is a valid target since the char keeps attacking as long as that's what it returns. Things go downhill when it returns the 7f000000 so I assume that means it's getting invalid object but I can't figure out why the function works only sometimes.

#5
manageri

manageri
  • Members
  • 394 messages
I think I solved this, it's rather embarrasingly simple really. In my tests I wanted to see if the char will continue attacking on the next round even if I move him and interupt the attack action. What I didn't consider is that this will cause him to not be attacking at the end of the round when GetAttemptedAttackTarget is run so it will return an invalid object. That's actually good because the ultimate goal is to have puppet-like behaviour so I don't want attacking to be started again if I interupted it, I just hadn't deliberately built that kinda check yet so I thought this version of the script should start the attack by itself.

After more testing GetAttemptedAttackTarget seems to work totally fine, if I just leave the character there with attack on he'll continue nuking until the target drops (and even get the next nearby target and attack that, which I thought I'd have to manually script). Thanks everyone for the replies!

#6
The Fred

The Fred
  • Members
  • 2 516 messages
OK, it's good to see this system actually works. ;-)