Advertisement
Kovitikus

Take Item From Container

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