// userenv_sit_at_post
/*
This is the "On User Defined" script for a posted character
who will normally be seated at the post location. To activate,
run SetSpawnInCondition( NW_FLAG_HEARTBEAT_EVENT ) in a spawn
script (0x00100000 = 1048576 in the "NW_GENERIC_MASTER" variable).
*/
// 26apr13 RJHall
#include "x0_i0_walkway"
#include "x0_i0_position"
#include "ginc_math"
/* Play a custom animation that will cause this creature to
appear seated. If bDrink is set to TRUE, then drinking
animations will be included. If bTalk is set to TRUE,
then talking animations will be used.
*/
void PlaySitAnimation( int bDrink = FALSE, int bTalk = FALSE )
{
// Select the animation
int nRandom = Random( 6 );
string sAnim = "sitidle";
switch(nRandom)
{
case 0:
if ( bDrink )
sAnim = "sitdrink";
break;
case 1:
if ( bTalk )
sAnim = "sittalk01";
break;
case 2:
if ( bTalk )
sAnim = "sittalk02";
break;
case 3:
if ( bDrink )
sAnim = "sitdrinkidle";
break;
case 4:
sAnim = "sitfidget";
break;
}
// Run the animation
PlayCustomAnimation( OBJECT_SELF, sAnim, 1);
}
/* Check if this creature is posted at his waypoint and facing
in the right direction, then run the 'sit' animation.
*/
void SitAtPost( int bDrink = FALSE, int nTalk = FALSE )
{
// Exit if it's doing something
if ( GetCurrentAction() != ACTION_INVALID )
return;
// Exit if it's not posted
if ( !GetIsPosted() )
return;
// It's posted, so this should return the posting waypoint
string sPrefix = GetWPPrefix();
object oWP = GetWaypointByNum( 1, sPrefix );
if ( GetIsObjectValid( oWP ) ) {
// Check if it's at the post
float fDist = GetDistanceToObject( oWP );
if ( fDist < 1.0f ) {
// Check if it's facing the right direction
float fPostFacing = GetFacing( oWP );
float fSelfFacing = GetFacing( OBJECT_SELF );
if ( IsDirectionWithinTolerance( fSelfFacing, fPostFacing, 5.0f ) ) {
PlaySitAnimation( bDrink, nTalk );
}
}
}
}
void main()
{
int nEvent = GetUserDefinedEventNumber();
switch( nEvent )
{
case EVENT_HEARTBEAT:
{
SitAtPost( TRUE );
}
break;
}
return;
}
Suggestions? (Stupid BBCode tag won't indent properly.)
Modifié par rjshae, 23 octobre 2013 - 03:38 .





Retour en haut






