def main(): match = re.match(r"((?:\")(.+)(?:\")|([^ ]+))" "( (removeall|(add|remove) ([^ ]+)|add))?", msg) if not match: activator.Controller().DrawInfo( "Usage: /cmd_permission <[]\"]player name[]\"]>", color = COLOR_WHITE) return player = match.group(2) or match.group(3) action = match.group(6) or match.group(5) cmd_permission = match.group(7) pl = FindPlayer(player) if not pl: activator.Controller().DrawInfo("No such player.", color = COLOR_RED) return inf = Interface(activator, pl) if cmd_permission: cmd_permission = markup_unescape(cmd_permission) if action == "add": if cmd_permission: if not cmd_permission in pl.Controller().cmd_permissions: pl.Controller().cmd_permissions.append(cmd_permission) else: inf.add_msg("{pl.name} already has that permission.", color = COLOR_RED, pl = pl) else: inf.set_text_input(prepend = "/cmd_permission {} add ".format( pl.name)) elif action == "remove": try: pl.Controller().cmd_permissions.remove(cmd_permission) except ValueError: inf.add_msg("{pl.name} does not have that permission.", color = COLOR_RED, pl = pl) elif action == "removeall": pl.Controller().cmd_permissions.clear() inf.add_msg("{pl.name} has the following permissions:\n", pl = pl) for tmp in pl.Controller().cmd_permissions: if tmp: inf.add_msg("\n {perm} [y=-2][a=:/cmd_permission " "{pl.name} remove {perm}]x[/a]", perm = markup_escape(tmp), newline = False, pl = pl) inf.add_link("Add permission", dest = "/cmd_permission {} add".format(pl.name)) inf.add_link("Remove all permissions", dest = "/cmd_permission {} removeall".format(pl.name)) inf.send()
def show (self, ac = None, append = None): inf = Interface(self.activator, self.activator) if ac is None: inf.set_title(self.activator.name + "'s Python Console") msg = markup_escape("\n".join(self.inf_data)) inf.add_msg("[font=mono 12]{}[/font]".format(msg)) else: inf.restore() inf.set_text_input(prepend = "/console \"", allow_tab = True, allow_empty = True, cleanup_text = False, scroll_bottom = True, autocomplete = "noinf::ac::", text = ac if ac else "") if append: inf.set_append_text("[font=mono 12]\n{}[/font]".format(append)) inf.send()
def main(): # By checking event number we can handle multiple event types # in a single script. event_nr = GetEventNumber() # Handle say event. if event_nr == EVENT_SAY: from Interface import Interface inf = Interface(activator, me) # Greeting; inform them about the 'go' command. if msg == "hello": inf.add_msg("Do you want me to activate my waypoint?") inf.add_link("Yes.", dest="yes") elif msg == "yes": # Activate the starting waypoint. me.FindObject(name="waypoint1").f_cursed = True inf.dialog_close() inf.send() # Trigger event is triggered when the waypoint has reached its destination. elif event_nr == EVENT_TRIGGER: # Reached waypoint that is used for getting to apples dropped around a tree. if me.name == "apple waypoint": # Try to find the apple by looking at objects below the guard's feet. for obj in activator.map.Objects(activator.x, activator.y): # Is the object an apple? if obj.type == Type.FOOD and obj.arch.name == "apple": # Remove the apple, inform the map and return. obj.Destroy() activator.Say("Omnomnomnomnom!") return # The return wasn't used in the above loop, this means we could not find an # apple where we previously saw it... activator.Say("Hmpf! Somebody stole my apple...") # Inform the map about us reaching this waypoint. else: activator.Say( "I just reached the waypoint [yellow]{}[/yellow].".format( me.name)) # Close event is triggered whenever a waypoint makes a monster move. elif event_nr == EVENT_CLOSE: # Check for existing apple waypoint. apple_wp = activator.FindObject(name="apple waypoint") if apple_wp: # There is an existing apple waypoint for this guard, so do not create # another one, but wait until it is inactive. if apple_wp.f_cursed: return # Inactive, so remove it (we'll create a new one) else: apple_wp.Destroy() # Makes guard move towards an apple he can see. def go_apple(m, x, y): activator.Say("Oh, an apple!") # Find the currently active waypoint of this guard. for wp in activator.FindObjects(type=Type.WAYPOINT_OBJECT): # Is it active? if wp.f_cursed: # Deactivate it; we'll create a new active waypoint, which will # point to this waypoint as the next one to go to. wp.f_cursed = False # Create the new waypoint. new_wp = activator.CreateObject("waypoint") # Set up the waypoint's ID and the next waypoint to go to. new_wp.name = "apple waypoint" new_wp.title = wp.name # The coordinates new_wp.hp = x new_wp.sp = y new_wp.slaying = m.path # Activate the waypoint. new_wp.f_cursed = True # Create an event object; will be triggered when the guard # reaches the apple waypoint, which will make the guard "eat" # the apple (it will only be removed, really). new_event = CreateObject("event_obj") # Set it up. new_event.sub_type = EVENT_TRIGGER new_event.race = WhatIsEvent().race # Insert it into the new waypoint. new_event.InsertInto(new_wp) break # Try to look for an apple around the guard. Squares that he cannot see # past or squares with walls are ignored. for (m, x, y) in activator.SquaresAround(5, AROUND_BLOCKSVIEW | AROUND_WALL, True): for obj in m.Objects(x, y): # Is there an apple? if obj.type == Type.FOOD and obj.arch.name == "apple": # Go get it! go_apple(m, x, y) return