Aller au contenu

Photo

Jump to a location


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

#1
Jereniva

Jereniva
  • Members
  • 124 messages

I have a generic script to force an NPC to "go home" at end of a conversation, where home is tag of a waypoint stored as local string (homeloc) on them.

I want the NPC to maybe run off in a direction for a couple steps before fading out and jumping, but because I am making this as generic as possible I can't just force movement towards a known object.

 

Any suggestions for having run in a random direction for a few seconds before fading out and jumping?

 

Here's the script

 

void main()

{

object oNPC = OBJECT_SELF;

// homeloc is string, with tag of their home waypoint

object oWP = GetObjectByTag(GetLocalString(oNPC, "homeloc"));

location locWP = GetLocation(oWP);

AssignCommand(oNPC, ActionJumpToLocation(locWP));

}



#2
Tchos

Tchos
  • Members
  • 5 054 messages

Sure, since you're using action commands, and those go in the NPC's action queue, all you have to do is put another ActionMoveTo (something) command in the queue before the ActionJumpToLocation, and for best results set the character to be uncommandable once you've assigned those two commands, so it can't abort them for any reason.  (Set it to restore commandability after the jump.)  You can get a semi-random looking location by using GetNearestObject(OBJECT_TYPE_WAYPOINT) assuming you have enough waypoints in the area.


  • Jereniva aime ceci

#3
Jereniva

Jereniva
  • Members
  • 124 messages

Thank you for the help, Tchos.

I solved the problem of hardcoding an object to move towards, and instead used ActionMoveAwayFromObject, forcing NPC to instead move away from PC.



#4
Dann-J

Dann-J
  • Members
  • 3 161 messages

Here's a cut-down version of a script I'm using. It requires there to be an exit waypoint in any area the conversation is run from, with a tag of WP_[area tag]. In this script, if the target point is in the same area then the creature simply walks towards it (although it jumps after 60 seconds). If the target waypoint is in another area, then the creature heads towards the exit waypoint for five seconds before jumping to it.

#include "ginc_item"

void main(string sCreatureTag, string sTargetTag)
{
object oCreature = GetNearestObjectByTag(sCreatureTag, GetPCSpeaker());
  
if (!GetIsObjectValid(oCreature))
  return;

string sAreaTag = GetTag(GetArea(OBJECT_SELF));
string sExit = "WP_"+sAreaTag;
object oExit = GetWaypointByTag(sExit);
object oHome = GetWaypointByTag(sTargetTag);
if (GetArea(oHome) == GetArea(OBJECT_SELF))
	{
	AssignCommand(oCreature, ActionForceMoveToObject(oHome, FALSE, 0.5, 60.0));
	}
else
	{
	AssignCommand(oCreature, ActionForceMoveToObject(oExit, TRUE, 0.5, 4.9));
	AssignCommand(oCreature, DelayCommand(5.0, ActionJumpToObject(oHome, 0)));
	}

}

  • Jereniva aime ceci

#5
Jereniva

Jereniva
  • Members
  • 124 messages

Nice Dann-J, great idea, thank you.