Aller au contenu

Photo

Poor man's seated guard script


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

#1
rjshae

rjshae
  • Members
  • 4 508 messages
The following is a test script I'm using to create posted guards who take a seat whenever they are at their post. The simplest way to implement it is to create the usual POST_tag waypoint, set the "NW_GENERIC_MASTER" variable on the guard to 1048576, and add this script to the guard's "On User Defined" script. The current form is pretty basic, so there's plenty of room for improvement.

// 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 .


#2
Tchos

Tchos
  • Members
  • 5 083 messages
No suggestions at this time, but a thanks for posting this. I love reading scripting ideas like this.

#3
kamal_

kamal_
  • Members
  • 5 260 messages
My ai generics scripts account for combat and include various sit options, you might get some ideas from them.
www.youtube.com/watch

Does your script have the guard walk waypoints and then sit at one of them?

#4
rjshae

rjshae
  • Members
  • 4 508 messages
Thanks. I use separate separate scripts for the rotating town guard. This was more for an interior situation.

#5
Dann-J

Dann-J
  • Members
  • 3 161 messages
That script is quite similar to the one I use to have NPCs periodically sit and eat/drink in taverns, or sit and read in a library. The PC can also use the system. I use some handy effects that some bearded guy created to put objects in their hands.

#6
ColorsFade

ColorsFade
  • Members
  • 1 271 messages
This is a great thread. I was wondering how sitting worked... Nice job guys!

#7
rjshae

rjshae
  • Members
  • 4 508 messages
The problem I ran into is that when the character is bumped, they can end up sitting in mid-air. I probably need to add some code to translate them back to the exact sitting location. (Making them unbumpable works for this, but I suspect that sometimes they may not sit back down in the correct spot.)

#8
kamal_

kamal_
  • Members
  • 5 260 messages

rjshae wrote...

The problem I ran into is that when the character is bumped, they can end up sitting in mid-air. I probably need to add some code to translate them back to the exact sitting location. (Making them unbumpable works for this, but I suspect that sometimes they may not sit back down in the correct spot.)

Look at how my ai generics handle it, they will return to their position and facing if they leave (bump/combat/teleported by script etc).

Modifié par kamal_, 29 avril 2013 - 08:00 .


#9
Dann-J

Dann-J
  • Members
  • 3 161 messages
I tend to have the sitting script set them temporarily to be both unbumpable and to not orient on dialogue. That helps prevent the new looping idle animation from being interupted.