Skip to content

Script to redirect npc attacker's target

I've created an item a PC can use with the taunt skill to make a target npc attack them instead of another party member. It compiles, but I don't see the "ClearAllActions" or "ActionAttack(oActivator)" happen. I appreciate any help.
void main()
{
    object oActivator = GetItemActivator();
    object oTarget=GetItemActivatedTarget();

    SendMessageToPC(oActivator, "Using Taunt Skill Item");

    // get target to perform concentration skill check
    int iSkill=GetSkillRank(SKILL_CONCENTRATION, oTarget);
    int iRoll=d20(1);
    int iResult = iRoll + iSkill;

    //compare target skill check to activator's taunt skill check
    if(GetIsSkillSuccessful(oActivator, SKILL_TAUNT, iResult))
      {
        SendMessageToPC(oActivator, "Taunt Succeeded");

        ClearAllActions(TRUE, oTarget);
        SendMessageToPC(oActivator, "Cleared Actions");

        AssignCommand(oTarget, ActionAttack(oActivator));
        SendMessageToPC(oActivator, "Attack Taunter");

      }
      else
      {SendMessageToPC(oActivator, "Taunt failed");}

}

Comments

  • MelkiorMelkior Member Posts: 240
    Try using AssignCommand to send the ClearAllActions to oTarget instead. That's the way I've always seen it done. My guess is that the way you're doing it, the command is not executed until after the script ends, which means that all commands, including the one to attack the activator, are being cleared. Using AssignCommand should put it into the creature's command queue and force it to be done before the ActionAttack command is added into the queue.
  • martiganmartigan Member Posts: 2
    That appears to have worked, thank you.
    void main()
    {
        object oActivator = GetItemActivator();
        object oTarget=GetItemActivatedTarget();
    
        SendMessageToPC(oActivator, "Using Taunt Skill Item");
    
        // get target to perform concentration skill check
        int iSkill=GetSkillRank(SKILL_CONCENTRATION, oTarget);
        int iRoll=d20(1);
        int iResult = iRoll + iSkill;
    
        //compare target skill check to activator's taunt skill check
        if(GetIsSkillSuccessful(oActivator, SKILL_TAUNT, iResult))
          {
            SendMessageToPC(oActivator, "Taunt Succeeded");
    
            AssignCommand(oTarget, ClearAllActions(TRUE, oTarget));
            SendMessageToPC(oActivator, "Cleared Actions");
    
            AssignCommand(oTarget, ActionAttack(oActivator));
            SendMessageToPC(oActivator, "Attack Taunter");
    
          }
          else
          {SendMessageToPC(oActivator, "Taunt failed");}
    
    }
    
Sign In or Register to comment.