SetFacing issue.
NeverwinterWights
Member Posts: 339
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:
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;
}
}
0
Comments
ActionDoCommand(SetFacingPoint(vSaved));