Updated and cleaned the wiki2rest converter. The ReST documentation should look a lot better now, with less weirdness. Using a python google-code snippet to convert now, so no more need for third-party ruby downloads! This should transfer to readthedocs shortly.
This commit is contained in:
parent
43f16094c1
commit
ae0f7a04c5
55 changed files with 3990 additions and 1778 deletions
|
|
@ -1,3 +1,5 @@
|
|||
Adding a command prompt to your game
|
||||
|
||||
Adding a command prompt
|
||||
=======================
|
||||
|
||||
|
|
@ -11,11 +13,13 @@ Prompt after the command
|
|||
|
||||
The easiest form of prompt is one that is sent after every command you
|
||||
send. So, say you enter the look command; you would then get the result
|
||||
of the look command, followed by the prompt. As an example:
|
||||
of the look command, followed by the prompt. As an example:Â
|
||||
|
||||
::
|
||||
|
||||
> look You see nothing special. HP:10, SP:20, MP: 5
|
||||
> look
|
||||
You see nothing special.
|
||||
HP:10, SP:20, MP: 5
|
||||
|
||||
MUD clients can be set to detect prompts like this and display them in
|
||||
various client-specific ways.
|
||||
|
|
@ -31,7 +35,20 @@ administration for example).
|
|||
|
||||
::
|
||||
|
||||
class MyCommand(Command): [...] def at_post_cmd(self): # we assume health/stamina/magic are just stored # as simple attributes on the character. hp = self.caller.db.hp sp = self.caller.db.sp mp = self.caller.db.mp self.caller.msg("HP: %i, SP: %i, MP: %i" % (hp, sp, mp))
|
||||
class MyCommand(Command):
|
||||
|
||||
[...]
|
||||
|
||||
def at_post_cmd(self):
|
||||
|
||||
# we assume health/stamina/magic are just stored
|
||||
# as simple attributes on the character.
|
||||
|
||||
hp = self.caller.db.hp
|
||||
sp = self.caller.db.sp
|
||||
mp = self.caller.db.mp
|
||||
|
||||
self.caller.msg("HP: %i, SP: %i, MP: %i" % (hp, sp, mp))
|
||||
|
||||
Prompt on the same line
|
||||
-----------------------
|
||||
|
|
@ -41,7 +58,8 @@ return of every command, on the same line:
|
|||
|
||||
::
|
||||
|
||||
> look HP: 10, SP:20, MP:5 -- You see nothing special.
|
||||
> look
|
||||
HP: 10, SP:20, MP:5 -- You see nothing special.
|
||||
|
||||
Now, there is an ``at_pre_cmd()`` hook analogous to the hook from last
|
||||
section except called just *before* parsing of the command. But putting
|
||||
|
|
@ -50,20 +68,23 @@ before* the function return:
|
|||
|
||||
::
|
||||
|
||||
> look HP:10, SP:20, MP: 5 You see nothing special.
|
||||
> look
|
||||
HP:10, SP:20, MP: 5
|
||||
You see nothing special.
|
||||
|
||||
... which might be cool too, but not what we wanted. To have the prompt
|
||||
appear on the same line as the return this, we need to change how
|
||||
messages are returned to the player. This means a slight modification to
|
||||
our *Character class* (see `here <Objects#Characters.html>`_ on how to
|
||||
change the default Character class to your custom one). Now, all
|
||||
commands use the ``object.msg()`` method for communicating with the
|
||||
player. This is defined in ``src/objects/models.py``, on the
|
||||
``ObjectDB`` base class. This is how the ``msg()`` method is defined:
|
||||
our *Character class* (see [Objects#Characters here] on how to change
|
||||
the default Character class to your custom one). Now, all commands use
|
||||
the ``object.msg()`` method for communicating with the player. This is
|
||||
defined in ``src/objects/models.py``, on the ``ObjectDB`` base class.
|
||||
This is how the ``msg()`` method is defined:
|
||||
|
||||
::
|
||||
|
||||
def msg(self, outgoing_message, from_obj=None, data=None): ...
|
||||
def msg(self, outgoing_message, from_obj=None, data=None):
|
||||
...
|
||||
|
||||
The only argument we are interested in here is the ``outgoing_message``,
|
||||
which contains the text that is about to be passed on to the player. We
|
||||
|
|
@ -74,7 +95,19 @@ custom Character typeclass add this:
|
|||
|
||||
::
|
||||
|
||||
def msg(self, outgoing_message, from_obj=None, data=None): # prepend the prompt in front of the message hp = self.db.hp sp = self.db.sp mp = self.db.mp prompt = "%i, %i, %i -- " % (hp, sp, mp) outgoing_message = prompt + outgoing_message # pass this on to the original msg() method on the database object self.dbobj.msg(outgoing_message, from_obj=from_obj, data=data)
|
||||
def msg(self, outgoing_message, from_obj=None, data=None):
|
||||
|
||||
# prepend the prompt in front of the message
|
||||
|
||||
hp = self.db.hp
|
||||
sp = self.db.sp
|
||||
mp = self.db.mp
|
||||
prompt = "%i, %i, %i -- " % (hp, sp, mp)
|
||||
outgoing_message = prompt + outgoing_message
|
||||
|
||||
# pass this on to the original msg() method on the database object
|
||||
|
||||
self.dbobj.msg(outgoing_message, from_obj=from_obj, data=data)
|
||||
|
||||
Note that this solution will *always* give you the prompt, also if you
|
||||
use admin commands, which could get annoying. You might want to have
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue