Ramble On

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
Puck
UOX3 Novice
Posts: 72
Joined: Sat Jan 23, 2010 3:22 pm
Has thanked: 0
Been thanked: 0

Ramble On

Post by Puck »

This was my first more or less painful contact with java ever. Apart from looking at this little coffee cup they got in their artwork, that is.

It seems to do what it's supposed to do... BUT! I'm sure I made some horrible or at least unelegant mistakes and would definetly appreciate any input on that. It can't just be alright the way it is :P

It's supposed to make an NPC say something random for a certain amount of times, when a player comes into range. Once triggered, additional players shouldnt trigger it again, until the NPC is done talking. After that, players should be able to trigger it again, by moving into range.

You can easily add or remove things the NPC should ramble about inconsistently. Just adjust the maxmess value accordingly.
// Ramble On!
//
// I don't know Java, but I know how to mutilate
// other peoples hard work:

var TalkPause = 17500;      // Pause between sentences
var amTalking = 0;      // Are we rambling yet?
var getTired = 0;       // How often did we talk already
var enuff = 10;         // How many lines at once, before its enough
var maxmess = 10;       // Index of the last message        
var Messidge = new Array;   // The things we have to say
  Messidge[0]="My butt hurts.";
  Messidge[1]="I hate Britannia.";
  Messidge[2]="Thou reeketh, go away!";
  Messidge[3]="GUARDS!";
  Messidge[4]="I can't define which sock to pee in!";
  Messidge[5]="It might be buggy as hell, but it beats playing Halo.";
  Messidge[6]="I put on my robe and wizard hat.";
  Messidge[7]="10 PRINT 'Hello World.'";
  Messidge[8]="Damnit, I should have taken Blizzards offer.";
  Messidge[9]="Garbage collection, my ass! This place is a dump!";
  Messidge[10]="Oh no! My inventory is glitched again!";

function inRange( pCharacter, objInRange, objType )
{
   if( objInRange.isChar == 1 && amTalking == 0)  // we got an audience
      {
       pCharacter.StartTimer( TalkPause, 1); // so RAMBLE ON!
       amTalking = 1;
      }
}

function onTimer( pCharacter, timerID )
{
   if( timerID == 1 )
      {
       var MsgNmbr = RandomNumber( 0, maxmess );
       pCharacter.TextMessage( Messidge[MsgNmbr] );
       getTired = getTired + 1;
      }
   if( getTired < enuff )
       pCharacter.StartTimer( TalkPause, 1);  
   else
     {
      pCharacter.TextMessage("Enough! Leave me alone!");
      amTalking = 0;
      getTired = 0;
     }
}
I'm considering making the timer in between the lines a bit randomized too (should be very easy) so it doesn't feel so... predictable.

Maybe also an array to keep track of the things already said, in one "session" so you don't have any duplicates.

The first NPC that has to bear this script officially is Lord British in his throne room, over here. If you have any input on some more stupid things he should say, please, post away.

Somehting else I would LOVE to do, is to look up names of active characters, and somehow include into the ramblings. Especially if you have a large library of stupid one liners to pick from (maybe I should teach myself some file access stuff?) it could get interesting and exciting, because you never know who might get insulted in which way today!
Last edited by Puck on Wed Feb 03, 2010 3:11 am, edited 1 time in total.
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Nice work :) One note though - Javascript, not Java ;)
-= Ho Eyo He Hum =-
Puck
UOX3 Novice
Posts: 72
Joined: Sat Jan 23, 2010 3:22 pm
Has thanked: 0
Been thanked: 0

Post by Puck »

:oops: *cough*

There is one thing that puzzles me a bit, however. I stole most of the bits in there, and this one I don't get, in the original:

Code: Select all

function inRange( pCharacter, objInRange, objType )
{
   if( objType == 0 )   // Somebody is in range
   {
      if( objInRange.isChar == 1 )
      {
         pCharacter.StartTimer( TalkPause, 1, true ); // Starts monologue
      }
   }   
} 
Why 2x if ? isnt the check whether it's char or not enough? (Like I tried to do)
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 »

There is one thing that puzzles me a bit, however. I stole most of the bits in there, and this one I don't get, in the original:

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


Why 2x if ? isnt the check whether it's char or not enough? (Like I tried to do)
Hey, if it works without if(obType==0), drop it. :P I can't remember why I put that in there assuming it was from the monologue script I hacked up.

--Mindless Automaton
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