Page 1 of 1

Unfinished JS - Quest?

Posted: Tue Feb 09, 2010 4:16 am
by Mindless Automaton
Here is some JS I've tooled around with but never finished. Its been about a year so I figured I would throw it up and maybe someone else can use it. Or maybe it would make them throw up also ;P

Here was a simple quest I was starting on. Basically a guy in Britain wants you to go kill a headless and get item X. I made this gump to turn it on and off, which would just spawn/delete the quest characters.
// Quest Command
// Script no: 1056

function CommandRegistration()
{
    RegisterCommand( "quest", 2, true ); //Talk to a targeted character or item
}

function command_QUEST( pSock, execString )
{
    var pUser = pSock.currentChar;
    var myGump = new Gump; // create a new gump
    myGump.AddBackground( 0, 0, 300, 300, 2600 ); // add an automic scaled background
    myGump.AddButton( 300, 5, 0xa50, 1, 0, 0);  // Add a close-gump button
    myGump.AddPicture( 20, 40, 0x12D8 ); // add tile art
    myGump.AddText( 85, 135, 5, "Quest 1: Kill the Headless! - ON" ); // add text, gets assigned TextID 0
    myGump.AddText( 85, 165, 7, "Quest 1: Kill the Headless! - OFF" ); // add text, gets assigned TextID 1
    myGump.AddRadio( 50, 130, 2152, 0, 0 ); //RadioButton with ID 0
    myGump.AddRadio( 50, 160, 2152, 1, 1 ); //RadioButton with ID 1
    myGump.AddButton( 160, 265, 0xF7, 1, 0, 1 ); // add the "okay" button
    myGump.Send( pUser.socket ); // send this gump to client now
    myGump.Free(); // clear this gump from uox-memory
    return false;
}


function onGumpPress( pSock, pButton, gumpData )
{
    var pUser = pSock.currentChar;
   
    switch(pButton)
    {
        case 0:
            // abort and do nothing
            break;
        case 1:
            var OtherButton = gumpData.getButton(0);
            switch(OtherButton)
            {
                case 0:
                    qmSpawned = SpawnNPC( "q1_questmaster", 1714, 1612, 3, 0 );  //add this npc
                    if( qmSpawned != null )
                    qmSpawned.SetTag( "qmSpawnedSerial", ( qmSpawned.serial & 0x00FFFFFF ) ); //get the serial number for the npc
                    pUser.SysMessage( "Wheee - a questmaster just spawned at my location!" ); //confirm
                   
                    hSpawned = SpawnNPC( "q1_headless", 1839, 1535, 0, 0 );  //add this npc
                    if( hSpawned != null )
                    hSpawned.SetTag( "hSpawnedSerial", ( hSpawned.serial & 0x00FFFFFF ) ); //get the serial number for the npc
                    pUser.SysMessage( "Wheee - a headless just spawned at my location!" ); //confirm
                    break;
                   
                case 1:
                    var qmSpawnedObj = CalcCharFromSer( qmSpawned.GetTag( "qmSpawnedSerial" ) ); //figure out the serial number
                    qmSpawnedObj.Delete();  // delete the npc
                    pUser.SysMessage( "Wheee - a questmaster is deleted!" );  //confirm

                    var hSpawnedObj = CalcCharFromSer( hSpawned.GetTag( "hSpawnedSerial" ) ); //figure out the serial number
                    hSpawnedObj.Delete();  // delete the npc
                    pUser.SysMessage( "Wheee - a headless is deleted!" );  //confirm
                    break;

            }
            break;
    }
}
THen you have the quest guy:
// UOX3 Speech File (JavaScript)// Converted by Dark-Storm// Date: 29.12.2001 2:07 am
// Tools used: PERL :)
//
// Rewritten by Xuri, July 2004
//
// This script uses regular expressions in it's searches. this allows to for instance include "hi", "hi!", and "hi?" as positive search results,
// while leaving out words where "hi" is simply a part of the word, like "hiking" or "hinder" or "hill".
// The regular expression is placed within two forward slashes, for instance /hello/. To make sure that the script only searches for the whole
// word "hello" and leaves off any preceeding or trailing letters/numbers/symbols, enclose the trigger-word in \b \b. Example: /\bhello\b/
// By adding an additional "i" behind the last forward slash, you specify that the search is case-insensitive, example: /\bhello\b/
// Script No. 3001
function onSpeech( myString, myPlayer, myNPC )
{
    if( !myNPC.InRange( myPlayer, 2 ) )
        return;
    var Speech_Array = myString.split(" ");
    var i = 0, currObj = 0;
    for( i = 1; i <= Speech_Array.length; i++ )
    {
        if( Speech_Array[currObj].match( /\bName\b/i ))
        {
            myNPC.TurnToward( myPlayer );
            myNPC.TextMessage( "My name is "+myNPC.name+". A pleasure, I'm sure." );
            return;
        }

        if( Speech_Array[currObj].match( /\bHail\b/i ) || Speech_Array[currObj].match( /\bHi\b/i ) || Speech_Array[currObj].match( /\bHello\b/i )) 
        {
            myNPC.TurnToward( myPlayer );
            myNPC.TextMessage( "Hello there!" );
            return;
        }

        if( Speech_Array[currObj].match( /\bquest\b/i ))   
        {
            myNPC.TurnToward( myPlayer );
            myNPC.TextMessage( "Why yes, please follow the shore until you come to a headless beast, then slay it!" );
            myNPC.TextMessage( "I would give you a reward but I haven't been programmed to yet!" );
            myNPC.TextMessage( "Also, when you kill it, I'll never even know it! No script!" );
            return;
        }
           
           
           
        currObj++;
    }
}
And the headless:
function onDeath( pDead )
{
    SysMessage( "Alas, I am dead!" );
}
Heh.. Enjoy?

Finish Him!

Posted: Tue Feb 09, 2010 2:59 pm
by Mindless Automaton
So to finish this, I was going to give the headless an item that when given to the quest guy, it would finish the quest.

Obviously I didn't make it that far. :)

Posted: Tue Feb 09, 2010 3:31 pm
by Puck
And I'm glad! Because this is a slippery slope which can only lead to ... well... nothing good.

:lol: