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
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 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;
}
}
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!