Advanced Town Selection Script v1.0

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
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:

Advanced Town Selection Script v1.0

Post by Xuri »

This script is a more advanced version of the already existing Town Selection Script.

It mimics the look of the built-in town-selection menu in the client, the one that appears for characters that pick the "advanced" option during character creation, and will allow any character to select a starting town once they're in-game. If the process is interrupted (disconnect, manual logout) it will restart the next time they re-connect.

Copy & paste into a text-editor, save document with a .js file extension in your UOX3/JS/custom folder, and then assign it ScriptID 0 in jse_fileassociations.scp to make it run for all new characters.
townselection.jpg
// Advanced Town Selection Script
// v1.0 by Xuri
//
// Allows new characters to choose a starting town, both after initial login and for consequent
// logins should they fail to select a town before logging out/getting disconnected.
// First teleports them out of danger (to the jails, but location is customizable), then applies
// various safety measures to ensure that they can't interact with anyone or be interacted with
// by anyone else until they have selected a town - at which point those safety measures get removed.
//
// Server admins can customize whether to show the town-selection verification dialogue by setting the
// verifyTownSelection-option to true or false, as well as temporary starting coordinates (currently the Jail).

// Configuration options:
var verifyTownSelection = true;
var tempX = 5282;
var tempY = 1186;
var tempZ = 0;
var tempWorld = 0;

function onCreateDFN( objMade, objType)
{
   var pUser = objMade;
   if( objType == 1 && !pUser.npc)
   {
       // If the newly created object is a character, and NOT an NPC, then
       // put in some safety measures against abuse before starting town-selection process
        pUser.frozen = true;
        pUser.vulnerable = false;
        pUser.visible = 3;
        pUser.squelch = true;
        pUser.SetTag( "StartTownSel", 1 );
        pUser.SetLocation( tempX, tempY, tempZ, tempWorld );
   }
}

function onLogin( pSocket, pUser )
{
    // Checks on each login to see if the town-selection tag is present
    // If it is, it means the character hasn't completed the town-selection process
   if( pUser.GetTag( "StartTownSel" ) == 1 )
   {
      var ret = SelectStartTownMap( pUser, pSocket );
   }
}

//----------------------------------------------------------------
//----------------------------------------------------------------

function SelectStartTownMap( pUser, pSock)
{
    var townGump = new Gump;
    townGump.NoClose();
    townGump.NoMove();
    townGump.AddPage( 0 );
        townGump.AddBackground( 0, 0, 650, 485, 0x2436);
        townGump.AddBackground( 465, 422, 143, 42, 0x13ec );
        townGump.AddGump(50, 50, 0x1598);
        townGump.AddGump(1, 1, 0x157c);
        townGump.AddHTMLGump( 195, 15, 200, 25, true, false, "<big><center><b>Starting Locations</b></center></big>" );
        townGump.AddHTMLGump( 50, 440, 380, 25, true, false, "<center>Please select a town to start your adventures in.</center>" );
        townGump.AddPageButton( 90, 150, 0x2c92, 1 ); //Yew
        townGump.AddText( 85, 130, 1172, "Yew" );
        townGump.AddPageButton( 240, 100, 0x2c92, 2 ); //Minoc
        townGump.AddText( 235, 80, 1172, "Minoc" );
        townGump.AddPageButton( 165, 200, 0x2c92, 3 ); //Britain
        townGump.AddText( 160, 180, 1172, "Britain" );
        townGump.AddPageButton( 385, 160, 0x2c92, 4 ); //Moonglow
        townGump.AddText( 380, 140, 1172, "Moonglow" );
        townGump.AddPageButton( 190, 310, 0x2c92, 5 ); //Trinsic
        townGump.AddText( 185, 290, 1172, "Trinsic" );
        townGump.AddPageButton( 325, 250, 0x2c92, 6 ); //Magincia
        townGump.AddText( 320, 230, 1172, "Magincia" );
        townGump.AddPageButton( 150, 395, 0x2c92, 7 ); //Jhelom
        townGump.AddText( 145, 375, 1172, "Jhelom" );
        townGump.AddPageButton( 90, 250, 0x2c92, 8 ); //Skara Brae
        townGump.AddText( 85, 230, 1172, "Skara Brae" );
        townGump.AddPageButton( 265, 130, 0x2c92, 9 ); //Vesper
        townGump.AddText( 260, 110, 1172, "Vesper" );
    townGump.AddPage( 1 );
        townGump.AddXMFHTMLGump( 445, 65, 180, 350, 1075072, true, true ); //Yew description from clilocs
        townGump.AddButton( 470, 430, 0x13b2, 1, 0, 1 ); //Continue button to start in Yew
        townGump.AddButton( 90, 150, 0x2c93, 1, 0, 1 ); //Second town-button overlaid on map to start in Yew
    townGump.AddPage( 2 );
        townGump.AddXMFHTMLGump( 445, 65, 180, 350, 1075073, true, true ); //Minoc description from clilocs
        townGump.AddButton( 470, 430, 0x13b2, 1, 0, 2 );
        townGump.AddButton( 240, 100, 0x2c93, 1, 0, 2 );
    townGump.AddPage( 3 );
        townGump.AddXMFHTMLGump( 445, 65, 180, 350, 1075074, true, true ); //Britain description from clilocs
        townGump.AddButton( 470, 430, 0x13b2, 1, 0, 3 );
        townGump.AddButton( 165, 200, 0x2c93, 1, 0, 3 );
    townGump.AddPage( 4 );
        townGump.AddXMFHTMLGump( 445, 65, 180, 350, 1075075, true, true ); //Moonglow description from clilocs
        townGump.AddButton( 470, 430, 0x13b2, 1, 0, 4 );
        townGump.AddButton( 385, 160, 0x2c93, 1, 0, 4 );
    townGump.AddPage( 5 );
        townGump.AddXMFHTMLGump( 445, 65, 180, 350, 1075076, true, true ); //Trinsic description from clilocs
        townGump.AddButton( 470, 430, 0x13b2, 1, 0, 5 );
        townGump.AddButton( 190, 310, 0x2c93, 1, 0, 5 );
    townGump.AddPage( 6 );
        townGump.AddXMFHTMLGump( 445, 65, 180, 350, 1075077, true, true ); //Magincia description from clilocs
        townGump.AddButton( 470, 430, 0x13b2, 1, 0, 6 );
        townGump.AddButton( 325, 250, 0x2c93, 1, 0, 6 );
    townGump.AddPage( 7 );
        townGump.AddXMFHTMLGump( 445, 65, 180, 350, 1075078, true, true ); //Jhelom description from clilocs
        townGump.AddButton( 470, 430, 0x13b2, 1, 0, 7 );
        townGump.AddButton( 150, 395, 0x2c93, 1, 0, 7 );
    townGump.AddPage( 8 );
        townGump.AddXMFHTMLGump( 445, 65, 180, 350, 1075079, true, true ); //Skara Brae description from clilocs
        townGump.AddButton( 470, 430, 0x13b2, 1, 0, 8 );
        townGump.AddButton( 90, 250, 0x2c93, 1, 0, 8 );
    townGump.AddPage( 9 );
        townGump.AddXMFHTMLGump( 445, 65, 180, 350, 1075080, true, true ); //Vesper description from clilocs
        townGump.AddButton( 470, 430, 0x13b2, 1, 0, 9 );
        townGump.AddButton( 265, 130, 0x2c93, 1, 0, 9 );
    townGump.Send( pUser.socket );
}
 
 function onGumpPress( pSocket, myButtonID )
 {
    var pUser = pSocket.currentChar;

    // Cases 0 to 9 just save which button was pushed as a temporary value in the clickZ socket property
    // Depending on whether or not the town-selection verification option is enabled, the script will
    // either go to the confirmation dialogue or directly to the actual teleportation - which is handled
    // in case 10
    switch( myButtonID )
    {
        case 0: // Managed to somehow escape the town selection?
            var ret = SelectStartTownMap( pUser, pSocket);
            pUser.SysMessage("Just must select a town to start in to continue.");
            break;
        case 1: // Yew
            pSocket.clickZ = 1;
            break;
        case 2: // Minoc
            pSocket.clickZ = 2;
            break;
        case 3: // Britain
            pSocket.clickZ = 3;
            break;
        case 4: // Moonglow
            pSocket.clickZ = 4;
            break;
        case 5: // Trinsic
            pSocket.clickZ = 5;
            break;
        case 6: // Magincia
            pSocket.clickZ = 6;
            break;
        case 7: // Jhelom
            pSocket.clickZ = 7;
            break;
        case 8: // Skara Brae
            pSocket.clickZ = 8;
            break;
        case 9: // Vesper
            pSocket.clickZ = 9;
            break;
        case 10:
            // Here we reset the character flags!
            pUser.frozen = false;
            pUser.vulnerable = true;
            pUser.visible = 0;
            pUser.squelch = false;
            pUser.SetTag( "StartTownSel", null );
            switch( pSocket.clickZ )
            {
                case 1:
                    pUser.SysMessage("You decide to start in Yew.");
                    pUser.SetLocation ( 545, 982, 0, 0 );
                    break;
                case 2:
                    pUser.SysMessage("You decide to start in Minoc.");
                    pUser.SetLocation ( 2477, 411, 15, 0 );
                    break;
                case 3:
                    pUser.SysMessage("You decide to start in Britain.");
                    pUser.SetLocation ( 1495, 1629, 10, 0 );
                    break;
                case 4:
                    pUser.SysMessage("You decide to start in Moonglow.");
                    pUser.SetLocation ( 4406, 1045, 0, 0 );
                    break;
                case 5:
                    pUser.SysMessage("You decide to start in Trinsic.");
                    pUser.SetLocation ( 1832, 2779, 0, 0 );
                    break;
                case 6:
                    pUser.SysMessage("You decide to start in Magincia.");
                    pUser.SetLocation ( 3675, 2259, 10, 0 );
                    break;
                case 7:
                    pUser.SysMessage("You decide to start in Jhelom.");
                    pUser.SetLocation ( 1492, 3696, 0, 0 );
                    break;
                case 8:
                    pUser.SysMessage("You decide to start in Skara Brae.");
                    pUser.SetLocation ( 639, 2236, 0, 0 );
                    break;
                case 9:
                    pUser.SysMessage("You decide to start in Vesper.");
                    pUser.SetLocation ( 2771, 977, 0, 0 );
                    break;
                default:
                    // Shouldn't happen, but here just in case
                    pUser.SysMessage( "Town-Selection script failed. Contact a GM." );
                    break;
            }
            //Town-selection process complete, reset temporary socket property
            pSocket.clickZ = null;
            break;
    }
    if( pUser.GetTag( "StartTownSel" ) == 1 && myButtonID != 0 ) //if selection-process has started, but is not finished
    {
        // If townselection-verification is enabled, pop up the confirmation dialogue
        // If not, goto case 10 in onGumpPress, and teleport without confirmation, based on town-number saved in pSocket.clickZ
        if( verifyTownSelection == true && myButtonID != 10 )
            TownVerificationPopup( pUser, pSocket );
        else
            onGumpPress( pSocket, 10 );
    }
}
 
function TownVerificationPopup( pUser, pSock )
{
    var townSelectNum = pSock.clickZ;

    var verifyGump = new Gump;
    verifyGump.NoClose();
    verifyGump.NoMove();
    verifyGump.AddPage( 0 );
    verifyGump.AddBackground( 0, 0, 215, 235, 0x2436 );  //main background
    verifyGump.AddBackground( 60, 145, 95, 38, 0x13ec ); //cancel-button background
    verifyGump.AddButton( 65, 150, 0x1450, 1, 0, 0 ); //cancel-button
    verifyGump.AddBackground( 35, 185, 143, 38, 0x13ec ); //continue-button background
    verifyGump.AddButton( 40, 190, 0x13b2, 1, 0, 10 ); //continue-button
    verifyGump.AddText( 20, 15, 1172, "Verify Your City-Selection" );
    switch ( townSelectNum )
    {
        case 1:
            verifyGump.AddHTMLGump( 15, 45, 185, 95, true, false, "You have chosen to start in <center><big><b>Yew</b></big>,<br>the City of Justice</center>." );
            break;
        case 2:
            verifyGump.AddHTMLGump( 15, 45, 185, 95, true, false, "You have chosen to start in <center><big><b>Minoc</b></big>,<br>the Miner's Frontier</center>." );
            break;
        case 3:
            verifyGump.AddHTMLGump( 15, 45, 185, 95, true, false, "You have chosen to start in <center><big><b>Britain</b></big>,<br>the City of Bards</center>." );
            break;
        case 4:
            verifyGump.AddHTMLGump( 15, 45, 185, 95, true, false, "You have chosen to start in <center><big><b>Moonglow</b></big>,<br>the City of Magic</center>." );
            break;
        case 5:
            verifyGump.AddHTMLGump( 15, 45, 185, 95, true, false, "You have chosen to start in <center><big><b>Trinsic</b></big>,<br>the Walled City</center>." );
            break;
        case 6:
            verifyGump.AddHTMLGump( 15, 45, 185, 95, true, false, "You have chosen to start in <center><big><b>Magincia</b></big>,<br>the Isle of Riches</center>." );
            break;
        case 7:
            verifyGump.AddHTMLGump( 15, 45, 185, 95, true, false, "You have chosen to start in <center><big><b>Jhelom</b></big>,<br>the Mercenaries' Isle</center>.." );
            break;
        case 8:
            verifyGump.AddHTMLGump( 15, 45, 185, 95, true, false, "You have chosen to start in <center><big><b>Skara Brae</b></big>,<br>the City of Rangers</center>." );
            break;
        case 9:
            verifyGump.AddHTMLGump( 15, 45, 185, 95, true, false, "You have chosen to start in <center><big><b>Vesper</b></big>,<br>the City of Bridges</center>." );
            break;
    }
    verifyGump.Send( pUser.socket );
}
-= Ho Eyo He Hum =-
RandallFlagg26
UOX3 Newbie
Posts: 16
Joined: Wed May 18, 2011 1:25 am
Has thanked: 0
Been thanked: 0

Post by RandallFlagg26 »

Thanks
mikel123
UOX3 Neophyte
Posts: 27
Joined: Thu Aug 18, 2011 4:28 pm
Has thanked: 0
Been thanked: 0

Post by mikel123 »

This is great. I'm brand new to UOX3 and have noticed that even when I select to start in Britain, I'm being placed in Yew. Will try to check this out tonight and see if it solves things for me.
Post Reply