// ms_turn_to_face
/*
This is the On Enter script for a Trigger blueprint that
causes an NPC to turn and face the entering creature.
If the 'NPC_Tag' is not set to the tag of a valid
creature, it exits. If the 'OnlyFacePC' variable is
set to 1, it ignores non-PCs who enter the trigger.
If 'BlurtOnce' is non-null, the NPC will speak the
string the first time the creature enters the trigger.
*/
// RJH 31may12
const string NPCtag = "NPC_Tag";
const string OnlyFacePC = "OnlyFacePC";
const string BlurtOnce = "BlurtOnce";
void main()
{
object oTarget = GetEnteringObject();
if ( ! GetIsObjectValid( oTarget ) )
return; // Invalid object
// Get the NPC tag
string sNPC = GetLocalString( OBJECT_SELF, NPCtag );
if ( GetStringLength( sNPC ) == 0 )
return; // Variable was not set
// Find the NPC
object oNPC = GetObjectByTag( sNPC );
if ( ! GetIsObjectValid( oNPC ) )
return; // Invalid object
// Get the Face PC setting
int bFacePC = GetLocalInt( OBJECT_SELF, OnlyFacePC );
if ( bFacePC && ! GetIsPC( oTarget ) )
return; // Entering object is not a PC
// Get entering creature's stealth mode
int nStealthMode = GetStealthMode( oTarget );
if ( nStealthMode == STEALTH_MODE_ACTIVATED )
return; // Don't break the illusion of stealthiness
// Get the tag of the entering object
string sEnterTag = GetTag( oTarget );
if ( StringCompare( sNPC, sEnterTag ) == 0 )
return; // Ignore self
// Check for a blurt string
int bDoBlurt = FALSE;
string sBlurt = GetLocalString( OBJECT_SELF, BlurtOnce );
if ( GetStringLength( sBlurt ) > 0 ) {
string SBlurtCheck = BlurtOnce + sNPC;
int bHasBlurted = GetLocalInt( oTarget, SBlurtCheck );
if ( bHasBlurted == 0 ) {
bDoBlurt = TRUE;
// Clear actions so blurt string is not delayed
AssignCommand( oNPC, ClearAllActions() );
}
SetLocalInt( oTarget, SBlurtCheck, 1 );
}
// Turn to face target
vector vTarget = GetPosition( oTarget );
vector vNPC = GetPosition( oNPC );
vector vDelta = vTarget - vNPC;
float fFacing = VectorToAngle( vDelta );
AssignCommand( oNPC, SetFacing( fFacing ) );
if ( bDoBlurt ) {
// Speak the blurt string
DelayCommand( 0.33f, AssignCommand( oNPC,
ActionSpeakString( sBlurt ) ) );
}
}
Any enhancements you can think of?
Modifié par rjshae, 02 juin 2012 - 03:08 .





Retour en haut







