Login Script

[ LiB ]

I mentioned in Chapter 16 that the login process accesses a Python script that issued to perform various login tasks , such as printing the races you can choose from and initializing your character whenever you create a new one.

This script is located in the /data/logon/logon.py file.

Listing Available Races

Whenever you want to create a new character, the game's logon module contacts the logon script and asks for a string representing the races your character can participate in.

Here's the function for requesting races:

 def listchars():     s =  "<#FFFFFF>------------------------------------------------\r\n"     s += "<#00FF00> Please Choose a Race For Your Character:\r\n"     s += "<#FFFFFF>------------------------------------------------\r\n"     s += "<$reset> 0 - Go Back\r\n"     s += "<$reset> 1 - Human\r\n"     s += "<$reset> 2 - Elf\r\n"     s += "<#FFFFFF>------------------------------------------------\r\n"     s += "<#FFFFFF> Enter Choice: <$reset>"     return s 

After the options are printed to the user , he can choose one, and the choice is sent to the logon script again, this time to the following function:

 def gettemplateid( option ):     if option == 1: return 1     if option == 2: return 2     return 0 

This function takes an option number and translates it into the template ID of the new player's character. Incidentally, I have the database set up right now so that options 1-2 correspond to template IDs 12, but that's a coincidence . Later on, you may want to make an option 3 that creates characters with a template ID of 100 or something like that.

Setting Up the New Character

Once the logon module creates your new character, it sends the ID of that new character into the logon script once morethis time to give the character all the commands he needs, and to put him in the right room. Here's a condensed version of the function:

 def setup( id ):     c = BetterMUD.character( id )     a = BetterMUD.account( c.GetAccount() )     l = a.AccessLevel();     c.SetRoom( 1 )     c.SetRegion( 1 )     if( l >= 0 ):         c.AddCommand( "north" ) ... <SNIP> ...         c.AddCommand( "say" )     if( l >= 2 ):         c.AddCommand( "kick" )         c.AddCommand( "announce" )     if( l >= 3 ):         c.AddCommand( "shutdown" ) ... <SNIP> ...         c.AddCommand( "destroyitem" ) 

The script sets the room and region of the character and then assigns commands based on your account's access level. You can do whatever else you want here. It's up to you. That's the beauty of scripts.

[ LiB ]


MUD Game Programming
MUD Game Programming (Premier Press Game Development)
ISBN: 1592000908
EAN: 2147483647
Year: 2003
Pages: 147
Authors: Ron Penton

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net