Aller au contenu

Photo

Simple door problem


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

#1
Verilazic

Verilazic
  • Members
  • 162 messages

Ok, I have a very basic script set for OnEnter for a trigger near a door. When an npc guard enters the trigger, if the nearby door is open, he runs to the door, looks around, closes the door, then continues to the waypoint he was originally walking to. It works beautifully with one exception... he doesn't close the door. I'm 99% sure no other scripts are conflicting and stopping him from closing the door, so I'm trying to figure out what could be wrong with my script:

object oGuard = GetEnteringObject();
if (GetIsPC(oGuard))
    return;
if (GetIsInCombat(oGuard))
    return;

string sTrig = GetTag(OBJECT_SELF);
object oDoor = GetObjectByTag("Door_" + GetStringRight(sTrig, GetStringLength(sTrig) - 5));
object oWP = GetWaypointByTag(GetLocalString(OBJECT_SELF, "sWP"));

if (GetIsOpen(oDoor) && !GetLocalInt(oDoor, "iChecking"))
    {
        SetLocalInt(oGuard, "iChecking", 1);
        SetLocalInt(oDoor, "iChecking", 1);
        AssignCommand(oGuard, ClearAllActions());
        AssignCommand(oGuard, ActionMoveToObject(oDoor, TRUE));
        AssignCommand(oGuard, ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_LEFT, 0.75));
        AssignCommand(oGuard, ActionPlayAnimation(ANIMATION_FIREFORGET_HEAD_TURN_RIGHT, 0.75));
        AssignCommand(oGuard, ActionCloseDoor(oDoor));
        AssignCommand(oGuard, ActionMoveToObject(oWP));
        DelayCommand(10.0, SetLocalInt(oGuard, "iChecking", 0));
    }

About the LocalInt commands: they set flags on the guard and the door to make sure multiple guards don't run to the same door, and to make sure the guard checking the door isn't interrupted by anything except detecting an enemy. The door flag is cleared in it's own OnClosed script.

 

So any thoughts? Did I mess up the guard's action queue in some weird way? Am I missing a silly typo because I've spent so long looking at the exact same text? Is it the kluge of using a DelayCommand to remove the guard's flag? Or is it that I need to go back through the other scripts that could conflict? =/



#2
meaglyn

meaglyn
  • Members
  • 813 messages

You mentioned waypoints he's walking to. I suspect he's having his actions cleared by WalkWaypoints() from his HB.  He probably enters the trigger between HBs and the next one fires before he gets the door closed. You might try adding something like:

AssignCommand(oGuard, ActionDoCommand(SetCommandable(TRUE, oGuard)));
AssignCommand(oGuard, SetCommandable(FALSE, oGuard));

...after the rest of the AssignCommands.


  • Verilazic aime ceci

#3
Verilazic

Verilazic
  • Members
  • 162 messages

I'm avoiding using walkwaypoints actually, but using setcommandable is a good idea. Thanks!