NPC Monologue Script

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

NPC Monologue Script

Post by Mindless Automaton »

// NPC Monologue Script
//
// This script will make an NPC talk a bit to no one in particular.
// Its kinda like a combo of crier.js & turnip.js :)
//

var TalkPause = 7500;  // Pause between sentences
var Msg1 = "I'm not the one who's so far away.."
var Msg2 = "When I feel the snake bite into my veins.."
var Msg3 = "Never did I wanna be here again.."
var Msg4 = "And I don't remember why I came.."
var Msg5 = "Voodoo, voodoo, voodoo, voodoo..."

function inRange( pCharacter, objInRange )
{
    if( objInRange.isChar ) // Somebody is in range
    {
        pCharacter.StartTimer( TalkPause, 1, true ); // Starts monologue
    }  
}

function onTimer( pCharacter, timerID )
{
    if( timerID == 1 )
    {
        pCharacter.StartTimer( TalkPause, 2, true); // The number is what timerID to go to next
        pCharacter.TextMessage( Msg1 );
    }
    if( timerID == 2 )
    {
        pCharacter.StartTimer( TalkPause, 3, true );
        pCharacter.TextMessage( Msg2 );
    }
   
    if( timerID == 3 )
    {
        pCharacter.StartTimer( TalkPause, 4, true );
        pCharacter.TextMessage( Msg3 );
    }

    if( timerID == 4 )
    {
        pCharacter.StartTimer( TalkPause, 5, true );
        pCharacter.TextMessage( Msg4 );
    }

    if( timerID == 5 )
    {
        pCharacter.StartTimer( TalkPause, 1, true );   // You can ditch this line to prevent them from repeating
        pCharacter.TextMessage( Msg5 );
    }

}

// Also, I want to work on computing a range from the NPC's coordinates..
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

You could probably store the message strings in an array. Don't remember my JS off the top of my head while at work. And that would simplify your timer script as well.

But apart from that, looking good.

One suggestion as to ranges is, depending on what you're doing.

Code: Select all

var squaredDistance = ( pCharacter.x - objInRange.x ) * ( pCharacter.x - objInRange.x ) + ( pCharacter.y - objInRange.y ) * ( pCharacter.y - objInRange.y );

if( squaredDistance <= (5 * 5) ) // Is it closer than 5 paces?
{
 // Do something
}
Square roots aren't cheap, so if you can work in squared distance, it's all good. That'll give you the flat 2D distance between them as a square of the distance. A square root would give you the straight line distance between them.
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Mindless Automaton »

Has anyone tried this script out?

I have an issue where it seems I have to leave the area and walk back before the character starts talking.

Also, does adding it twice seem to make the npc say the words twice?

THanks!
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Mindless Automaton »

Alright, I have a theory that when the script begins, since I am already in range, it doesn't check to see if someone is in range?

That is why leaving and coming back starts the script.

:o

For the double speak, how about the script starts, I walk out before it finishes and then I walk in again, starting another instance of the same script? Anyhow, something wacky goes on..

Thanks!
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
Maarc
Developer
Posts: 576
Joined: Sat Mar 27, 2004 6:22 am
Location: Fleet, UK
Has thanked: 0
Been thanked: 0
Contact:

Post by Maarc »

inRange only fires when a new object comes into range. If you're already there, you won't trigger. And yup, it looks like if someone comes in during the monologue, it'll trigger a new one.

To avoid that, add this global

Code: Select all

var amTalking = 0;
Change inRange to wrap the starttimer

Code: Select all

         if( amTalking == 0 )
         {
            pCharacter.StartTimer( TalkPause, 1, true );
            amTalking = 1;
         }
then in timerID == 5, comment out the repeat, and add

Code: Select all

         amTalking = 0;
That should force a single speech instance.
Mindless Automaton
UOX3 Apprentice
Posts: 189
Joined: Wed May 10, 2006 3:48 am
Has thanked: 0
Been thanked: 1 time
Contact:

Post by Mindless Automaton »

I assume this is probably the same issue I was having when I posted a bug in the other forum about it. I guess I will strike that and try it out again.


Thanks!
Mindless Automaton
Linux - UOX3 - 0.99.5 dev branch
Win10Pro 19042.572 - UOX3 0.99.3a; Razor 1.0.14; Client 7.0.87.11 or 4.0.11c (Patch 0)
Post Reply