Skip to content

SetFacing issue.

NeverwinterWightsNeverwinterWights Member Posts: 339
edited June 2018 in Builders - Scripting
Another one of those things I just can't remember if its always been this way or not.
So I have some code in a merchants HB script. On one heartbeat the merchant will walk away from his saved location. In the next heartbeat he will return to his saved location. The problem I'm having is with the SetFacing function after he moves to his saved location. For some reason the ONLY way it will work is like so:

ActionMoveToLocation(lSaved, FALSE);
AssignCommand(oNPC, ActionDoCommand(SetFacing(GetFacingFromLocation(lSaved))));

SetFacing should just work in the HB script as per description it uses the caller of the script. Which should be the creature the HB script is attached to. Now I realized that this may be an action queue issue so then shouldn't just an ActionDoCommand(SetFacing.. work? I even made a custom function to SetFacing and tried an ActionDoCommand in front of that too. But the line above, which seems a bit convoluted, is the only way the NPC will move to the location and then face the right direction after moving. Am I missing something? Is this a bug?

Entire script just in case:

//Merchant AI Heartbeat Script void main() { object oNPC = OBJECT_SELF; if (IsInConversation(oNPC)) return; //Do nothing if NPC is in a conversation int iDoOnce = GetLocalInt(oNPC, "LOCATION_SET"); if (!iDoOnce) { SetLocalInt(oNPC, "LOCATION_SET", 1); SetLocalLocation(oNPC, "MY_POST", GetLocation(oNPC)); SendMessageToPC(GetFirstPC(), "Merchant location saved!"); } //Do one of the following per HB randomly: nothing, say something, an animation, //or move away or back to a location int iRandomAction = 3;//change back to Random(4) after facing gets fixed if (iRandomAction == 0)//Do nothing this HB { SendMessageToPC(GetFirstPC(), "Merchant does nothing this heartbeat.");//test line return; } if (iRandomAction == 1)//Say something random this HB { string sSay; switch (Random(8)) { case 0: sSay = "I can help whoever is next in line." ; break; case 1: sSay = "I can help the next customer." ; break; case 2: sSay = "Just let me know if you need anything." ; break; case 3: sSay = "Are you finding everything you need?" ; break; case 4: sSay = "Please be careful with that." ; break; case 5: sSay = "Welcome to Adventurer's Emporium!" ; break; case 6: sSay = "Feel free to browse our merchandise." ; break; case 7: sSay = "I've got my eye on you." ; break; } SpeakString(sSay); return; } if (iRandomAction == 2)//Play a random animation this HB { int iAnimation; switch (Random(10)) { case 0: iAnimation = ANIMATION_FIREFORGET_HEAD_TURN_LEFT ; break; case 1: iAnimation = ANIMATION_FIREFORGET_HEAD_TURN_RIGHT ; break; case 2: iAnimation = ANIMATION_FIREFORGET_PAUSE_BORED ; break; case 3: iAnimation = ANIMATION_FIREFORGET_PAUSE_SCRATCH_HEAD; break; case 4: iAnimation = ANIMATION_FIREFORGET_READ ; break; case 5: iAnimation = ANIMATION_LOOPING_PAUSE ; break; case 6: iAnimation = ANIMATION_LOOPING_PAUSE2 ; break; case 7: iAnimation = ANIMATION_LOOPING_PAUSE_TIRED ; break; case 8: iAnimation = ANIMATION_LOOPING_TALK_LAUGHING ; break; case 9: iAnimation = ANIMATION_LOOPING_TALK_NORMAL ; break; } PlayAnimation(iAnimation); SendMessageToPC(GetFirstPC(), "Merchant should be doing animation.");//test line return; } if (iRandomAction == 3)//Move away or back to location { location lCurrent = GetLocation(oNPC); location lSaved = GetLocalLocation(oNPC, "MY_POST"); vector vCurrent = GetPositionFromLocation(lCurrent); vector vSaved = GetPositionFromLocation(lSaved); if (vCurrent == vSaved) { ActionMoveAwayFromLocation(lCurrent, FALSE, 2.0); SendMessageToPC(GetFirstPC(), "Merchant moving away from saved loc.");//test line } else { ActionMoveToLocation(lSaved, FALSE); AssignCommand(oNPC, ActionDoCommand(SetFacing(GetFacingFromLocation(lSaved)))); SendMessageToPC(GetFirstPC(), "Merchant moving to saved loc.");//test line } return; } }

Comments

  • pscythepscythe Member Posts: 116
    Have you tried using SetFacingPoint instead? You shouldn't need to use AssignCommand for that.

    ActionDoCommand(SetFacingPoint(vSaved));
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    pscythe said:

    Have you tried using SetFacingPoint instead? You shouldn't need to use AssignCommand for that.

    ActionDoCommand(SetFacingPoint(vSaved));

    Appreciate the suggestion but unfortunately that doesn't work either. I'll just stick with the other weird line for now. I'm curious to know why the function acts the way it does though.
  • PhantasmaPhantasma Member Posts: 79
    Your code works fine for me (with the AssignCommand replaced with just ActionDoCommand) - maybe something in another of the merchant's scripts is interfering? I just placed a default NPC in a new module and added just your code, and only your code, into a heartbeat script.
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    Phantasma said:

    Your code works fine for me (with the AssignCommand replaced with just ActionDoCommand) - maybe something in another of the merchant's scripts is interfering? I just placed a default NPC in a new module and added just your code, and only your code, into a heartbeat script.

    Hmm. I just decided to try again with just the ActionDoCommand and it is now working for me too. I'm not sure why it didn't before. Also used a default NPC. With only the script above. Weird. Thank you for testing it. Appreciate it.
Sign In or Register to comment.