Advertisement
Kovitikus

Evennia - Take Item From Container

Apr 1st, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 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.  
  11.     def parse(self):
  12.         # get args into 2 variables
  13.         self.item_arg, self.container_arg = self.args.split("from")
  14.         self.item_arg = self.item_arg.strip()
  15.         self.container_arg = self.container_arg.strip()
  16.      
  17.            
  18.  
  19.     def func(self):
  20.         caller = self.caller
  21.         container_arg = self.container_arg
  22.         item_arg = self.item_arg
  23.  
  24.         container = caller.search(container_arg, location=caller.location, quiet=True) # Check if container is in the room.
  25.         if container:
  26.             item = caller.search(item_arg, location=container, quiet=True) # Check if the item is in the container.
  27.         else:
  28.             caller.msg(f"{container_arg} doesn't exist!")
  29.             return
  30.  
  31.         if item:
  32.             item.move_to(caller, quiet=True) #move the item to the caller inventory
  33.             caller.msg(f"You take {item} from {container}")
  34.             caller.location.msg_contents(f"{caller.name} takes {item} from {container}.", exclude=caller)
  35.         else:
  36.             caller.msg(f"{item_arg} isn't in {container}!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement