room_commands.html 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <html>
  2. <head>
  3. <link href="../tutorial.css" rel="stylesheet" type="text/css">
  4. </head>
  5. <body>
  6. <div class="header">
  7. The NakedMud Tutorial :: Room Commands
  8. </div>
  9. <!-- content starts here -->
  10. <div class="content-wrap"><div class="content-body-wrap"><div class="content">
  11. <div class="head">Room Comands</div>
  12. <div class="info">
  13. NakedMud has a global command handler. When a new command is added to the game,
  14. it is entered into the global command handler. However, each individual room
  15. also has a local command handler. Rooms can have their own unique commands
  16. added. In fact, when a room has a unique exit, all that happens is a command
  17. is added to the room that allows movement between multiple rooms. Commands are
  18. functions that take three arguments: a character, the command name, and the
  19. argument supplied to the command:
  20. <pre class="code">
  21. def cmd_touch(ch, cmd, arg):
  22. try:
  23. obj, = parse_args(ch, True, cmd, arg, "[the] obj.room")
  24. except: return
  25. # are we touching the activator device?
  26. if obj.isinstance("mage_teleport_orb"):
  27. try:
  28. map = {"mage_guild_entrance@moonhaven" : "magic_tower01@moonhaven",
  29. "magic_tower01@moonhaven" : "mage_guild_entrance@moonhaven"}
  30. dest = map[ch.room.proto]
  31. except:
  32. # no destination (or source) was found
  33. message(ch, obj, None, None, False, "to_char",
  34. "You reach out and touch $o, but nothing happens.")
  35. return
  36. ch.send("As you reach out and touch the orb, your mind clouds with a "
  37. "blue haze. Once the haze fades, you find your surroundings "
  38. "have changed.")
  39. ch.room = dest
  40. ch.act("look")
  41. # or are we just touching any old random object?
  42. else:
  43. message(ch, obj, None, None, False, "to_char",
  44. "You reach out and touch $o, but nothing happens.")
  45. me.add_cmd("touch", None, cmd_touch, "player", True)
  46. </pre>
  47. Rooms, like the mud module, has an add_cmd method that can be called. Commands
  48. can be set up and added in the extra code section of a room prototype. The
  49. add_cmd method takes five arguments: the command name, and abbrevation (if any,
  50. e.g., ne for northeast), the command itself, the player group that can use the
  51. command, and a truth value whether or not mobiles can use the command.
  52. <p></p>
  53. Checks can also be added to room commands:
  54. <pre class="code">
  55. def chk_unconscious(ch, cmd):
  56. if ch.pos == "unconscious" or ch.pos == "sleeping":
  57. return False
  58. return True
  59. me.add_cmd_check("touch", chk_unconscious)
  60. </pre>
  61. </div>
  62. <!-- content ends here-->
  63. </div></div></div>
  64. <!-- navigation starts here -->
  65. <div class="nav-wrap"><div class="nav">
  66. <iframe src="nav.html" height="100%" width="100%" scrolling=no frameborder=0>
  67. </iframe>
  68. <!-- navigation ends here -->
  69. </div></div>
  70. <!--div class="footer">Edit Date: Nov 15, 2008. By Geoff Hollis</div-->
  71. </body>
  72. </html>