npc set facing?
#1
Posté 02 décembre 2012 - 10:16
Setting by script to reface an object would be painful as there are a fair few this would affect.
Thanks
PJ
#2
Guest_Iveforgotmypassword_*
Posté 02 décembre 2012 - 11:47
Guest_Iveforgotmypassword_*
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
Posté 02 décembre 2012 - 01:06
Ah well, good job I love this sooo much
Thanks Tsongo,
PJ
#4
Posté 02 décembre 2012 - 03:07
#5
Posté 02 décembre 2012 - 10:24
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
Posté 02 décembre 2012 - 10:27
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
Posté 03 décembre 2012 - 12:19
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
Posté 03 décembre 2012 - 12:50
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
Posté 03 décembre 2012 - 01:01
Do they all have POSTs obediently set ...
#10
Posté 03 décembre 2012 - 06:44
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
PJ
#11
Posté 03 décembre 2012 - 07:46
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: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?
// 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
so I'm wondering if you might simply make a call to GetNearestCreature() and specify [ CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC ], likeHere 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.
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_*
Posté 03 décembre 2012 - 08:50
Guest_Iveforgotmypassword_*
#13
Posté 03 décembre 2012 - 07:55
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
Posté 03 décembre 2012 - 09:56
#15
Posté 03 décembre 2012 - 11:53
SetOrientOnDialog(oTarget, FALSE); // Prevent turning when spoken to
SetBumpState(oTarget, BUMPSTATE_UNBUMPABLE); // Prevent moving when bumped into
Regards





Retour en haut







