Town Selection Script for new characters.

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:

Town Selection Script for new characters.

Post by Xuri »

NOTE: A more advanced version of this script can be found here: Advanced Town Selection Script

This is a script for letting players choose a starting town after logging into your shard.

Save the following in a text file with .js extension, and assign that file scriptID 0 in jse_fileassociations.scp to make it run for all users:
// Town Selection Script
// v1.0a by Xuri
//
// Allows new characters to choose a starting town after logging in.
// First it teleports them out of danger (to the jails), freezes them and make them invulnerable,
// before presenting them with a menu with towns to choose from.
// That menu will appear to the player every time they login until they've chosen a starting location.

function onCreateDFN( objMade, objType)
{
   var pUser = objMade;
   if( objType == 1 && !pUser.npc)
   {
      pUser.frozen = true;
      pUser.vulnerable = false;
      pUser.SetTag( "StartTownSel", "Initialized" );
      pUser.SetLocation( 5282, 1186, 0, 0 );
   }
}

function onLogin( pSocket, pUser )
{
   if( pUser.GetTag( "StartTownSel" ) == "Initialized" )
   {
      pUser.SysMessage( "Welcome to <My Shard Name>." );
      pUser.SysMessage( "Please choose a starting town." );
      var ret = SelectStartTown( pUser, pSocket );
   }
}

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

function SelectStartTown( pUser, pSock)
{
   var myGump = new Gump;
   myGump.NoClose();
   myGump.NoMove();
   myGump.AddBackground(0, 0, 300, 230, 0xa3c);
   myGump.AddText( 14, 9, 5, "Which town do you want to start in?" );
   myGump.AddText( 30, 35, 5, "- Britain");
   myGump.AddButton( 14, 40, 0x837, 1, 0, 1 );
   myGump.AddText( 30, 55, 5, "- Jhelom");
   myGump.AddButton( 14, 60, 0x837, 1, 0, 2);
   myGump.AddText ( 30, 75, 5, "- Magincia");
   myGump.AddButton ( 14, 80, 0x837, 1, 0, 3);
   myGump.AddText( 30, 95, 5, "- Minoc");
   myGump.AddButton( 14, 100, 0x837, 1, 0, 4);
   myGump.AddText( 30, 115, 5, "- Moonglow");
   myGump.AddButton( 14, 120, 0x837, 1, 0, 5);
   myGump.AddText( 30, 135, 5, "- Skara Brae");
   myGump.AddButton( 14, 140, 0x837, 1, 0, 6);
   myGump.AddText( 30, 155, 5, "- Trinsic");
   myGump.AddButton( 14, 160, 0x837, 1, 0, 7);
   myGump.AddText( 30, 175, 5, "- Vesper");
   myGump.AddButton( 14, 180, 0x837, 1, 0, 8);
   myGump.AddText( 30, 195, 5, "- Yew");
   myGump.AddButton( 14, 200, 0x837, 1, 0, 9);
   myGump.Send( pUser.socket );
}

function onGumpPress( pSocket, myButtonID )
{
   var pUser = pSocket.currentChar;
   switch( myButtonID )
   {
      case 0: // Trying to escape the town selection?
         var ret = SelectStartTown( pUser, pSocket);
         pUser.SysMessage("Just pick a town...");
      break;
      case 1: // Britain
         pUser.SysMessage("You decide to start in Britain.");
         pUser.SetLocation ( 1495, 1629, 10, 0 );
      break;
      case 2: // Jhelom
         pUser.SysMessage("You decide to start in Jhelom.");
         pUser.SetLocation ( 1492, 3696, 0, 0 );
      break;
      case 2: // Magincia
         pUser.SysMessage("You decide to start in Magincia.");
         pUser.SetLocation ( 3675, 2259, 10, 0 );
      break;
      case 4: // Minoc
         pUser.SysMessage("You decide to start in Minoc.");
         pUser.SetLocation ( 2477, 411, 15, 0 );
      break;
      case 5: // Moonglow
         pUser.SysMessage("You decide to start in Moonglow.");
         pUser.SetLocation ( 4406, 1045, 0, 0 );
      break;
      case 6: // Skara Brae
         pUser.SysMessage("You decide to start in Skara Brae.");
         pUser.SetLocation ( 639, 2236, 0, 0 );
      break;
      case 7: // Trinsic
         pUser.SysMessage("You decide to start in Trinsic.");
         pUser.SetLocation ( 1832, 2779, 0, 0 );
      break;
      case 8: // Vesper
         pUser.SysMessage("You decide to start in Vesper.");
         pUser.SetLocation ( 2771, 977, 0, 0 );
      break;
      case 9: // Yew
         pUser.SysMessage("You decide to start in Yew.");
         pUser.SetLocation ( 545, 982, 0, 0 );
      break;
   }
   pUser.frozen = false;
   pUser.vulnerable = true;
   pUser.SetTag( "StartTownSel", null );
}
Last edited by Xuri on Fri Jun 17, 2011 7:15 am, edited 5 times in total.
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Now correct me if I'm wrong... but wouldn't that fire on any object created by the scripts, thus affecting both characters and items that weren't created with the tileID (likely erroring out for items, and making NPC's frozen).

As a side note, at the bottom of SelectStartTown() you set their vulnerable flag to false, making them invulnerable. :)
Scott
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 »

Ah.. Good point. Missing an if( objectType == 1 ), perhaps? :P
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

and something like if( !pUser.npc )

:)
Scott
erekose
UOX3 Novice
Posts: 52
Joined: Sun Feb 18, 2007 4:30 pm
Has thanked: 0
Been thanked: 0

Post by erekose »

'mornin boys and girls...

I thought this script just sounded lovely. I am using a (so far) unmodified copy of the Start World Kit, and this would have been my first modification...

It doesn't seem to have worked...

1. I made a new .js file and placed it in the custom folder, copying the script above into it verbatum (copy and paste).
2. I then modified the file association file, replacing 0=custom/global.js with 0=custom/picktown.js
3. I then restarted my server and tried to create two new characters (one custom, one necromancer); in neither case did I get to chose my town.

So, two part question...

1. Am I missing a step? If so, what? OR

2. If this does not work, than is it possible for me to redirect the default start location to somewhere other than Britania? (If so, than I will make a newby location on the server, and then give them gates to the various cities)...

Thanks in advance
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 »

The script doesn't work for you because stranf's worldstarter kit uses an old UOX3.EXE file which has a bug where the onCreateDFN() JS event won't "exist" to UOX3 unless there is also an onCreateTile() JS event in the same script.

What you can do to make the script work, is either update to a newer UOX3.EXE (download the experimental build and use the UOX3.EXE from that archive) - which will fix the bug but may also bring unforseen bugs to some of stranfs numerous scripts (or they might work fine - I don't know :), or you can add the following to your picktown.js script:

Code: Select all

function onCreateTile( objMade, objType )
{
}
UOX3 will then recognize the existence of onCreateDFN in the same script, and new players will be given the town-selection script when they login after having created their character.
-= Ho Eyo He Hum =-
erekose
UOX3 Novice
Posts: 52
Joined: Sun Feb 18, 2007 4:30 pm
Has thanked: 0
Been thanked: 0

Post by erekose »

Let me ask this in a slightly different way; I am afraid I don't quite follow what you were saying there in the last post Xuri...

Assuming I don't want to switch out the .exe (if something broke, I would have no clue where to start to fix) than what exactlly do I need to do to get this working?

The .js file has been created. The association file has not been changed in any way.
1. where do I add that code snipet? to which file, at what location, and does it replace or add to?
2. where exactlly do I reference the js file and does it replace anoterh call or add to there as well?

Thanks in advance! This is the one piece I would LOVE to get going before I open the server to the public.
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 »

If you've setup the script with a script-ID of "0" in the jse_fileassociations.scp file, all you should need to do is add the above onCreateTile snippet (with no code whatsoever between the { and } brackets) to the top of your startup.js file (the townselection-script), like this:

Code: Select all

// Town Selection Script 
// v1.0 by Xuri 
// 
// Allows new characters to choose a starting town after logging in. 
// First it teleports them out of danger (to the jails), freezes them and make them invulnerable, 
// before presenting them with a menu with towns to choose from. 
// That menu will appear to the player every time they login until they've chosen a starting location. 

[color=orange]function onCreateTile( objMade, objType )
{
}[/color]

function onCreateDFN( objMade, objType) 
{
... 
1. You should not replace any existing code, only add the highlighted code from above to the script.
2. The js-file must be setup in jse_fileassociations.scp with a script-ID of 0, like this:

Code: Select all

[SCRIPT_LIST]
{
//-------------------------------------------
// CORE:[0-99] Rerserved for specific core server needs
[color=orange]0=custom/startup.js[/color]
//-------------------------------------------
-= Ho Eyo He Hum =-
erekose
UOX3 Novice
Posts: 52
Joined: Sun Feb 18, 2007 4:30 pm
Has thanked: 0
Been thanked: 0

Post by erekose »

in the association file, as I am finding it, I already find a zero call... That is, this already exists

Code: Select all

0=custom/global.js
do I add to this, replace it, which?

Thanks!
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 »

Ah yes, that means stranf already has a script setup with the global script-ID. Unless his script (global.js) contains any of the same JS events (onCreateDFN, onGumpPress, etc) as the town-selection script does, you should be able to just copy & paste the town-selection stuff into the global.js file, without overwriting anything already there.

In short, just add the contents of the town-selection script to the bottom of the global.js file. :)
-= Ho Eyo He Hum =-
erekose
UOX3 Novice
Posts: 52
Joined: Sun Feb 18, 2007 4:30 pm
Has thanked: 0
Been thanked: 0

Post by erekose »

Xuri wrote:Ah yes, that means stranf already has a script setup with the global script-ID. Unless his script (global.js) contains any of the same JS events (onCreateDFN, onGumpPress, etc) as the town-selection script does, you should be able to just copy & paste the town-selection stuff into the global.js file, without overwriting anything already there.

In short, just add the contents of the town-selection script to the bottom of the global.js file. :)
Now THAT is something this old (non) coder can wrap his wee brain around. Let me give that a try!
psychozen
UOX3 Newbie
Posts: 7
Joined: Sun Jul 15, 2007 5:53 am
Has thanked: 0
Been thanked: 0

Post by psychozen »

This script is awesome thanks should og head and put this in permant
Post Reply