SHARE
TWEET

Untitled

a guest Nov 20th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         one, tag with the zone category. It also supports multiple classes
  2.         of zones simply by adding aliases to the command key.
  3.        
  4.         Credits: Darren @ 7th Sea MUSH.
  5.     """
  6.  
  7.    key = "zone"
  8.    aliases = ("area","region")
  9.    help_category = "Building"
  10.    switch_options = ('clear',)
  11.    locks = "perm(Builder)"
  12.  
  13.    def func(self):
  14.        caller = self.caller
  15.  
  16.        # If they called the command without any args, display a usage
  17.        # message and quit.
  18.        if not self.args:
  19.            caller.msg("Usage: %s[/clear] <room>[=<%s>]" % (self.cmdstring, self.cmdstring))
  20.            return
  21.  
  22.        # Find the object they're trying to zone.            
  23.        obj = caller.search(self.lhs)
  24.  
  25.        # If no object was found, we can just quit because search() will
  26.        # have already handled displaying the error message.
  27.        if not obj:
  28.            return
  29.  
  30.        # Ensure that the target object is a room. Note that this is a
  31.        # design choice and not a limitation of the system! Zones are just
  32.        # tags and all typeclasses can have tags.
  33.        if not utils.inherits_from(obj, "typeclasses.rooms.Room"):
  34.            caller.msg("Only rooms should have %ss." % self.cmdstring)
  35.            return
  36.  
  37.        # Ensure the caller has permission to modify the room.
  38.        if not (obj.access(caller, "control") or obj.access(caller, "edit")):
  39.            self.caller.msg("You don't have permission to change the %s of %s." % (self.cmdstring, obj.get_display_name(caller)))
  40.            return
  41.  
  42.        # Are we just clearing?
  43.        just_clearing = ("clear" in self.switches) if self.switches else False
  44.  
  45.        # Now let's check to see if there is a zone already set.
  46.        tmp = obj.tags.get(category=self.cmdstring, return_list=True)
  47.        old_zone = tmp[0] if tmp else None
  48.  
  49.        # Now let's deal with the new zone name. Since zones are tags and
  50.        # tags cannot contain spaces, we'll make things easier for our
  51.        # builders by automatically converting any spaces into underscores.
  52.        # We use split() and join() here rather than replace() to make sure that
  53.        # all of the words of the zone name are seperated by a single space.        
  54.        zone = "_".join(self.rhs.split()) if self.rhs else None
  55.  
  56.        # Now let's handle removing the old zone.
  57.        if (old_zone and zone) or just_clearing:
  58.            if old_zone:
  59.                obj.tags.remove(old_zone, category=self.cmdstring)
  60.                caller.msg("Existing %s \"|w%s|n\" removed from |w%s|n." % (self.cmdstring, old_zone, obj.get_display_name(caller)))
  61.            else:
  62.                caller.msg("There is no old %s to clear." % self.cmdstring)
  63.                
  64.            if just_clearing:
  65.                return
  66.                
  67.        if zone:
  68.            # Set the new zone.
  69.            obj.tags.add(zone, category=self.cmdstring)
  70.            caller.msg("%s of |w%s|n set to \"|w%s|n\"." % (self.cmdstring.capitalize(), obj.get_display_name(caller), zone))
  71.        else:            
  72.            # No new zone was given, just display the current zone (if any).
  73.            if old_zone:
  74.                caller.msg("The %s of |w%s|n is \"|w%s|n\"." % (self.cmdstring, obj.get_display_name(caller), old_zone))
  75.            else:
  76.                caller.msg("Room |w%s|n has no %s set." % (obj.get_display_name(caller), self.cmdstring))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top