| [ LiB ] |
Interfacing two completely different languages is an interesting, fun topic. You can do much more with Python and C combined,
I hope I've given you a good introduction to Python, and I doubt you'll have much trouble with it, since it's incredibly simple. If you're ever stuck, the Python website has a great tutorial. Or you can look at all the scripts I'm including with the BetterMUD for examples of how things are done.
And now, we're off the
| [ LiB ] |
| [ LiB ] |
The previous seven chapters were
So far, you've got thousands of lines of code, but no game! The problem with designing a system like the BetterMUD is that you can't put it together in bits and piecesat least not at first. Once the physical game core is up and running, however, you can go nuts and start adding scripts left and right.
This chapter is designed primarily to show you how to create basic scripts to make your physical engine into an actual game. I'm not going to go bananas with scripts; in fact the version of the BetterMUD that will be on the CD is going to be just a tiny bit more advanced than the SimpleMUD.
However, with all of the flexibility of the BetterMUD at your fingertips, you can immediately start playing around with scripts.
I would like to invite you again to join my own MUD server at http://dune.net and play around (if I change servers, you can find out about it on my website, http://www.ronpenton.net. I'll be continuously adding scripts and updates, so if you're interested in seeing some of the really cool things that can be done, I'll have my own scripts available to download.
In this chapter, you will learn to create:
A login script to manage new
A base Python script class for your modules to use
Command scripts
Logic scripts
A script to
A script to manage encumbrance
A script to manage arming weapons
A script to manage currency and
A script to perform combat between characters
AI scripts for non-player characters
| [ LiB ] |
| [ LiB ] |
I mentioned in Chapter 16 that the login process
This script is located in the /data/logon/logon.py file.
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
def gettemplateid( option ):
if option == 1: return 1
if option == 2: return 2
return 0
This function takes an option number and
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
| [ LiB ] |