1

I have been trying to write a multiuser dungeon using MUD-PI and im stuck at making a combat command i would like to have it be something like kill [monster] an example would be like kill troll.

Here is my code for the command

elif command == "kill":
            mn = params.lower()
            rm = rooms[players[id]["room"]]
            if rm["enemy"] == 'yes':

                if mn in rm["monsterName"]:
                    monster = mn
                    if monster.hp >= 0:
                        mud.send_message(id,"You attack %s for %d damage" % (rm["monsterName"], players[id]["ATK"]))
                        monster.hp -= players[id]["ATK"]
                    else:
                        monster.death()
                else:
                    mud.send_message(id, "you dont see a %s" % mn)
            else:
                mud.send_message(id, "you dont see an enemy")

Here is my rooms code.

#Rooms

import sys, random, os

#import monsters
from Monsters import *
# structure defining the rooms in the game. Try adding more rooms to the game!
rooms = {
    "Tavern": {
        "description": "You're in a cozy tavern warmed by an open fire.",
        "exits": { "outside": "Outside" },
    },
    "Outside": {
        "description": "You're standing outside a tavern. there is a troll.",
        "exits": { "inside": "Tavern" },
        "enemy": "yes",
        "monsterName": {"troll": troll },
    }
}

And my Monster code.

#monsters

import sys,random,os,time



#Troll
class Troll():
    def __init__(self):
        self.name = "Troll"
        self.ATK = 2
        self.hp = 10
        self.max_hp = 10

    def death(self):
        mud.send_message(id,"you killed the troll")
        self.hp = self.max_hp


troll = Troll()

when i try the kill command i get this error.

    if monster.hp >= 0:
AttributeError: 'unicode' object has no attribute 'hp'

i want to know if there is a better way to do this if so how and if not how i can fix my problem here.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Arcxes
  • 29
  • 9
  • Step through your code... `mn = params.lower()`... `monster = mn`... It looks like `monster` is set to a string, not a `Monster` class object. So `monster.hp` will return the error you are seeing. – OneCricketeer Feb 20 '16 at 20:37

1 Answers1

1

Are you sure you want the line

monster = mn

which assigns the name of the monster to monster instead of its object. I would think it needs to looks something more like

monster = rm["monsterName"][mn]
Savinien
  • 86
  • 7
  • We'll but you should get a different error message, right now you obviously check for .hp on a Unicode, which is wrong. Maybe, when you try my code you get a no .ho on None, which might show you, that troll was not set properly. – Savinien Feb 21 '16 at 03:54
  • i get the same error and could you show an example of what i should be doing im getting confused – Arcxes Feb 22 '16 at 01:50
  • Well, just the piece I wrote in my answer. I would change nothing else. If you really do get exactly the same error code something else is wrong with your code. The way you do it, `monster` gets assigned to a string, so I expect a string related error code. The way I posted it, `monster` indirectly gets assigned to `troll` which according to your code should be an object. So you should get a very different error. If you get the same error you did not post all the relevant parts of your code. – Savinien Feb 22 '16 at 04:51
  • i took a look at my code again and it worked thank you for your help – Arcxes Feb 24 '16 at 04:14
  • i have worked the game up a lot and have everything working the way i want it to, i have a beta running now at IP: 12.227.142.185 port: 5000 – Arcxes Mar 22 '16 at 17:39