Aller au contenu

Photo

npc set facing?


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

#1
PJ156

PJ156
  • Members
  • 2 986 messages
How do I set the npc to not face the player when engaged in conversation? Do I set facing in a script, that seems the obvios thing to do and the most realistic but I wondered if there is a tick box.

Setting by script to reface an object would be painful as there are a fair few this would affect.

Thanks

PJ

#2
Guest_Iveforgotmypassword_*

Guest_Iveforgotmypassword_*
  • Guests
Work out who's around and in the right area for the npc to face and stick their tag in as the listener on each node. If nobody's about put in a cat, dog, rabbit or rat depending on where you are. You can even work out which way they're going to look and stick a camera facing that way too.

There is a ga_face_target in the conversation scripts too.

And then there's this my most used script ever to get the PC to face whoever you want because the listener node part is broken for PC lines..

//PC always disorientated
//PGB 12/05/07
#include "ginc_actions"
void main()
{
object oPC=GetPCSpeaker();
AssignCommand(oPC,ActionOrientToTag("tag of npc",ORIENT_FACE_TARGET));
}

Just put it on every line that the PC needs to face somebody but is busy staring at someone else this normally happens when the last person they spoke to wasn't the one that is adressing them.

Modifié par Iveforgotmypassword, 02 décembre 2012 - 11:50 .


#3
PJ156

PJ156
  • Members
  • 2 986 messages
I though it was going to be something like that. I have been using a generic conversation for all my npc's so I will have to put the set facing on thier heatbeat with thier ambient activity scripts ... so my generic ambient just became npc specific.

Ah well, good job I love this sooo much

Thanks Tsongo,

PJ

#4
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
You can also use the JumpToLocation command, which skips the action queue altogether. Locations include facing as well as xyz coordinate position, so you either get the PC's current position (GetPosition), and then recombine it with the new facing, or just use the location of a waypoint or other object you've already laid down.

#5
PJ156

PJ156
  • Members
  • 2 986 messages
Thanks guys,

In the end I used set facing which sets them back at the right angle without needing a target to look at. That makes it somewhat more generic as I have a series of script set at the right angle. Tha angle i inlcude in the name of the script.

It's odd though. the set facing angle works off north and counts conterclockwise from east at 0 degrees and west at 180. Which is not the angle of ofrientation of the bluprint. It would be very convenient if the two were the same :(

Thanks again for the suggestions

PJ

#6
PJ156

PJ156
  • Members
  • 2 986 messages
This is the beginning of the script by the way, could I have done this better or neater? (the script is a buchered version of the one KevL gave me the other day for ambient behavior in static npcs)

void main()
{
 //object oDebug = GetFirstPC(FALSE); // debug only.
 // Comment out debug lines below for public consumption.
 if (IsInConversation(OBJECT_SELF) || GetCurrentAction() != ACTION_INVALID)
 {
  //SendMessageToPC(oDebug, ". . hb _ In convo or action, Exit"); // debug
  return;
 }
 int i = 0;
 
  i = Random(5);
  SetFacing (5.0f,TRUE);
 {
  switch (i)
  {
   
   case 0:
    //SendMessageToPC(oDebug, ". in Case 0 - 2 : idle"); // debug
    // this engages automatically and needs no call:
    PlayCustomAnimation(OBJECT_SELF, "standidle", TRUE);
   break;

PJ

#7
Dann-J

Dann-J
  • Members
  • 3 161 messages
That script would seem to make the NPC face a certain direction if they're not doing anything.

You could have achieved the same thing by giving the NPC a single waypoint (right-click on the NPC instance in an area and choose 'make waypoint'). Then the NPC would automatically face the direction the waypoint was facing when idle, with no scripting required. Plus, if you bumped the NPC or they ran to attack something, they'd keep returning to their spot.

#8
kevL

kevL
  • Members
  • 4 070 messages
hey PJ

can you describe a bit better what you're trying to do? ie. If it's possible to set down a waypoint, or use a particular object to face toward, that should be the way to go. or Is this going to be a generic "ga_" dialog script? Or heartbeat, for after a conversation finishes, just to get NPC to turn away

Morbane & i were getting peculiar results w/ SetFacing() : the NPC would often stop turning before it got to the spec'd direction. ( and yeah it would be nice if the blueprint direction and ingame direction were the same ) But if the direction just wants to be random away from PC that might not be a problem


- for a heartbeat

void main()
{
	if (IsInConversation(OBJECT_SELF) || GetCurrentAction() != ACTION_INVALID)
	{
		return;
	}

	int iDir = Random(360);
	float fDir = IntToFloat(iDir);
	SetFacing(fDir, TRUE); // <- false?

	// int i = Random(5);
	// etc.
	// Note that if animations follow, they probably should go into a
	// DelayCommand() which means you might have to wrap PlayCustomAnimation()
	// so it works when wrapped by DelayCommand() .....
}

/untested

#9
kevL

kevL
  • Members
  • 4 070 messages
ah, so you want NPC to face back to its original direction?

Do they all have POSTs obediently set ...

#10
PJ156

PJ156
  • Members
  • 2 986 messages

DannJ wrote...

That script would seem to make the NPC face a certain direction if they're not doing anything.

You could have achieved the same thing by giving the NPC a single waypoint (right-click on the NPC instance in an area and choose 'make waypoint'). Then the NPC would automatically face the direction the waypoint was facing when idle, with no scripting required. Plus, if you bumped the NPC or they ran to attack something, they'd keep returning to their spot.


Ooooooo!

Sounds to me like that might be all I need to do.

Thanks again KevL. I did not put down what I was doing clearly. Here the npc is talking with another npc if you interupt then they turn to you, then return to the direction they were facing whent he conversation is done and continue thier heartbeat animations. I am going to have to look at this again I think.

I would be grateful if you would explain the term wrapper I am guessing that you cannot delay playcutomanimation directly (I know that from bitter experience) so what can you do? Do you refer to the code on a separate script line. What form might this take?

This is turning into a scripting thread. I guess it always was.

No worries the moderators will move me Image IPB

PJ

#11
kevL

kevL
  • Members
  • 4 070 messages

PJ156 wrote...

I would be grateful if you would explain the term wrapper I am guessing that you cannot delay playcutomanimation directly (I know that from bitter experience) so what can you do? Do you refer to the code on a separate script line. What form might this take?

DelayCommand() -- there might be others also -- requires that its enclosed function returns "void", but PlayCustomAnimation() returns an "int". That's how i understand it. ( btw, CreateObject() is another that does not return "void" -- hence functions like CreateObjectVoid(), which is just a 'wrapper' for CreateObject() that returns "void" instead of "object" ). Here's the format:


// custom function to wrap PlayCustomAnimation()
void PlayCustomAnimationVoid(object oObject, string sAnimation, int iLoop, float fSpeed = 1.f)
{
	PlayCustomAnimation(oObject, sAnimation, iLoop, fSpeed);
}

// main script here.
void main()
{
	// regular scripting here

	// Use actual values here; the function above remains as-is. //
	//object oObject = ...;
	//string sAnimation = ...;
	//int iLoop = ...;
	//float fSpeed ...;
	//DelayCommand(1.f, PlayCustomAnimationVoid(oObject, sAnimation, iLoop, fSpeed));

	// regular scripting cont'd.
}


Usually you can prune things down by using defaults in the custom function definition, eg. fSpeed above; if you give the wrapper some defaults, they can then be left completely out of the "main" body call. ( as long as no parameters get skipped; ie, they have to appear at the end of the call/ def'n. )

ps. The method Dann refers, which is really excellent and my own preferred method, needs either the default HB scripts in place or at least a 'strategic' call to WalkWayPoints() in a custom HB ....

but you say

Here the npc is talking with another npc if you interupt then they turn to you, then return to the direction they were facing whent he conversation is done and continue thier heartbeat animations.

so I'm wondering if you might simply make a call to GetNearestCreature() and specify [ CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC ], like

object oTarget = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC, OBJECT_SELF, 1, CREATURE_TYPE_IS_ALIVE, CREATURE_ALIVE_TRUE);
AssignCommand(OBJECT_SELF, SetFacingPoint(GetPosition(oTarget)));

- though, uhm, that'd seem to require that they were actually chatting up a nearby NPC. If not, try going with Dann's suggestions, with POST waypoints and the WalkWayPoints() function. I'm still not sure how dedicated you are to a custom HB script, or if you're going to try to get by with a default HB ... in any case, it looks like a few more hours of effort heading yer way.

Question: Is this used with those animations we dealt with in another thread? (if so then you probably are looking at a custom HB)


/sry for rambling

#12
Guest_Iveforgotmypassword_*

Guest_Iveforgotmypassword_*
  • Guests
DannJ... Genius ! That'll sort out all my wandering peasants that should be at work.

#13
PJ156

PJ156
  • Members
  • 2 986 messages
KevL, thanks, that is a good explanantion and I think I have the things I need to have a go myself.

It is as you surmised. the npc is in ambient conversation with another npc so I have a heartbeat script and Dann's idea did not work. I am still using setfacing but I will give it another go by looking for the nearest npc. that might give some interesting effects if a mobile npc passes close by :)

The original script was yours but I did not get the weighting factor you used so I simplified it by weighting it in the allcoation of the cases. In any case it works for me and thank you.

Set facing has been stable so far but I am going to give the other solutions here a go if only to learn how/if they work.

PJ

#14
Dann-J

Dann-J
  • Members
  • 3 161 messages
The functions that make creatures walk waypoints are in the default creature HB script, so any custom HB would have to incorporate those functions into it. Otherwise they'd ignore their waypoint.

#15
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
In my on spawn statue script posted here I use the standard SetOrientOnDialog and SetBumpState functions to lock the NPC in place. This prevents them from moving at all. Just put these lines in a spawn script like so:

SetOrientOnDialog(oTarget, FALSE); // Prevent turning when spoken to
SetBumpState(oTarget, BUMPSTATE_UNBUMPABLE); // Prevent moving when bumped into

Regards