Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. class CmdTakeFrom(Command):
  2.     """
  3.    Usage:
  4.  
  5.    Take <item> from <container>
  6.  
  7.    Gets an item from the container, if it's in there.
  8.    """
  9.     key = "take"
  10.     def parse(self):
  11.         try:
  12.           # get args into 2 variables
  13.           self.item, self.container = self.args.split("from")
  14.           self.item = self.item.strip()
  15.           self.container = self.container.strip()
  16.         except:
  17.           self.caller.msg("Syntax for 'take' is: 'take item from container.'"          
  18.  
  19.     def func(self):
  20.         try:
  21.             caller = self.caller
  22.             container = caller.search(self.container, location=caller.location) # Check if container is in the room.
  23.             if container:
  24.               item = caller.search(self.item, location=container) # Check if the item is in the container.
  25.             else:
  26.               caller.msg(f"{self.container} doesn't exist.")
  27.               return False          
  28.             if item:
  29.                item.move_to(caller, quiet=True) #move the item to the caller inventory
  30.                caller.msg(f"You take {item} from {container}.")
  31.                caller.location.msg_contents(f"{caller.name} takes {item} from {container}.", exclude=caller)
  32.                return True
  33.             else:
  34.                caller.msg(f"{self.item} isn't in {self.container}.")
  35.         except:
  36.             pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement