Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- one, tag with the zone category. It also supports multiple classes
- of zones simply by adding aliases to the command key.
- Credits: Darren @ 7th Sea MUSH.
- """
- key = "zone"
- aliases = ("area","region")
- help_category = "Building"
- switch_options = ('clear',)
- locks = "perm(Builder)"
- def func(self):
- caller = self.caller
- # If they called the command without any args, display a usage
- # message and quit.
- if not self.args:
- caller.msg("Usage: %s[/clear] <room>[=<%s>]" % (self.cmdstring, self.cmdstring))
- return
- # Find the object they're trying to zone.
- obj = caller.search(self.lhs)
- # If no object was found, we can just quit because search() will
- # have already handled displaying the error message.
- if not obj:
- return
- # Ensure that the target object is a room. Note that this is a
- # design choice and not a limitation of the system! Zones are just
- # tags and all typeclasses can have tags.
- if not utils.inherits_from(obj, "typeclasses.rooms.Room"):
- caller.msg("Only rooms should have %ss." % self.cmdstring)
- return
- # Ensure the caller has permission to modify the room.
- if not (obj.access(caller, "control") or obj.access(caller, "edit")):
- self.caller.msg("You don't have permission to change the %s of %s." % (self.cmdstring, obj.get_display_name(caller)))
- return
- # Are we just clearing?
- just_clearing = ("clear" in self.switches) if self.switches else False
- # Now let's check to see if there is a zone already set.
- tmp = obj.tags.get(category=self.cmdstring, return_list=True)
- old_zone = tmp[0] if tmp else None
- # Now let's deal with the new zone name. Since zones are tags and
- # tags cannot contain spaces, we'll make things easier for our
- # builders by automatically converting any spaces into underscores.
- # We use split() and join() here rather than replace() to make sure that
- # all of the words of the zone name are seperated by a single space.
- zone = "_".join(self.rhs.split()) if self.rhs else None
- # Now let's handle removing the old zone.
- if (old_zone and zone) or just_clearing:
- if old_zone:
- obj.tags.remove(old_zone, category=self.cmdstring)
- caller.msg("Existing %s \"|w%s|n\" removed from |w%s|n." % (self.cmdstring, old_zone, obj.get_display_name(caller)))
- else:
- caller.msg("There is no old %s to clear." % self.cmdstring)
- if just_clearing:
- return
- if zone:
- # Set the new zone.
- obj.tags.add(zone, category=self.cmdstring)
- caller.msg("%s of |w%s|n set to \"|w%s|n\"." % (self.cmdstring.capitalize(), obj.get_display_name(caller), zone))
- else:
- # No new zone was given, just display the current zone (if any).
- if old_zone:
- caller.msg("The %s of |w%s|n is \"|w%s|n\"." % (self.cmdstring, obj.get_display_name(caller), old_zone))
- else:
- caller.msg("Room |w%s|n has no %s set." % (obj.get_display_name(caller), self.cmdstring))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement