Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Map Extensions+
- Extensions to the map metadata;
- - Water Damage
- - Map-Specific Command Removal
- - Spawn Locations
- - Block Protection
- Maintainer: ?
- Updated by Influx
- """
- import random
- def apply_script(protocol, connection, config):
- class MapExtensionConnection(connection):
- def on_position_update(self):
- extensions = self.protocol.map_info.extensions
- if (extensions.has_key('water_damage') and
- self.world_object.position.z>=61):
- water_damage = extensions['water_damage']
- self.environment_hit(water_damage)
- if (extensions.has_key('boundary_damage')):
- x = self.world_object.position.x
- y = self.world_object.position.y
- boundary_damage = extensions['boundary_damage']
- if (x<=boundary_damage['left'] or x>=boundary_damage['right'] or
- y<=boundary_damage['top'] or y>=boundary_damage['bottom']):
- self.environment_hit(boundary_damage['damage'])
- connection.on_position_update(self)
- def environment_hit(self, value):
- if value < 0 and self.hp >= 100: # do nothing at max health
- return
- self.set_hp(self.hp - value)
- def on_command(self, command, parameters):
- disabled = self.protocol.map_info.extensions.get(
- 'disabled_commands', [])
- if command in disabled:
- self.send_chat("Command '%s' disabled for this map" % command)
- return
- return connection.on_command(self, command, parameters)
- def on_spawn_location(self, pos):
- extensions = self.protocol.map_info.extensions
- if (extensions.has_key('blue_spawn')):
- blue_spawn_centre = extensions['blue_spawn']
- else:
- blue_spawn_centre = None
- if (extensions.has_key('green_spawn')):
- green_spawn_centre = extensions['green_spawn']
- else:
- green_spawn_centre = None
- if (extensions.has_key('blue_spawn_offset')):
- blue_spawn_offset = extensions['blue_spawn_offset']
- else:
- blue_spawn_offset = 100
- if (extensions.has_key('green_spawn_offset')):
- green_spawn_offset = extensions['green_spawn_offset']
- else:
- green_spawn_offset = 100
- if self.team == self.protocol.blue_team:
- spawn_centre = blue_spawn_centre
- spawn_offset = blue_spawn_offset
- elif self.team == self.protocol.green_team:
- spawn_centre = green_spawn_centre
- spawn_offset = green_spawn_offset
- if spawn_centre != None:
- spawn_choice = random.choice(spawn_centre)
- if len(spawn_choice) == 3:
- x1, y1, z = spawn_choice
- x, y = self.protocol.map.get_random_point((x1 - spawn_offset), (y1 - spawn_offset), (x1 + spawn_offset), (y1 + spawn_offset))
- newpos = x, y, z
- return newpos
- elif len(spawn_choice) == 2:
- x1, y1 = spawn_choice
- x, y = self.protocol.map.get_random_point((x1 - spawn_offset), (y1 - spawn_offset), (x1 + spawn_offset), (y1 + spawn_offset))
- z = self.protocol.map.get_z(x, y)
- newpos = x, y, z
- return newpos
- return connection.on_spawn_location(self, pos)
- def on_block_destroy(self, x, y, z, mode):
- extensions = self.protocol.map_info.extensions
- if (extensions.has_key('protected')):
- protected = extensions['protected']
- if mode == 3:
- grenade_prevention = 1
- else:
- grenade_prevention = 0
- for area in protected:
- start, finish = area
- a, b, c = start
- d, e, f = finish
- if a <= d:
- start_x = a - grenade_prevention
- finish_x = d + grenade_prevention
- else:
- start_x = d - grenade_prevention
- finish_x = a + grenade_prevention
- if b <= e:
- start_y = b - grenade_prevention
- finish_y = e + grenade_prevention
- else:
- start_y = e - grenade_prevention
- finish_y = b + grenade_prevention
- if c <= f:
- start_z = c - grenade_prevention
- finish_z = f + grenade_prevention
- else:
- start_z = f - grenade_prevention
- finish_z = c + grenade_prevention
- if (start_x <= x <= finish_x and start_y <= y <= finish_y
- and start_z <= z <= finish_z):
- self.send_chat('This area is protected!')
- return False
- return connection.on_block_destroy(self, x, y, z, mode)
- def on_block_build_attempt(self, x, y, z):
- extensions = self.protocol.map_info.extensions
- if (extensions.has_key('protected')):
- protected = extensions['protected']
- for area in protected:
- start, finish = area
- a, b, c = start
- d, e, f = finish
- if a <= d:
- start_x = a
- finish_x = d
- else:
- start_x = d
- finish_x = a
- if b <= e:
- start_y = b
- finish_y = e
- else:
- start_y = e
- finish_y = b
- if c <= f:
- start_z = c
- finish_z = f
- else:
- start_z = f
- finish_z = c
- if (start_x <= x <= finish_x and start_y <= y <= finish_y
- and start_z <= z <= finish_z):
- self.send_chat('This area is protected!')
- return False
- return connection.on_block_build_attempt(self, x, y, z)
- def on_line_build_attempt(self, points):
- extensions = self.protocol.map_info.extensions
- if (extensions.has_key('protected')):
- protected = extensions['protected']
- for area in protected:
- start, finish = area
- a, b, c = start
- d, e, f = finish
- if a <= d:
- start_x = a
- finish_x = d
- else:
- start_x = d
- finish_x = a
- if b <= e:
- start_y = b
- finish_y = e
- else:
- start_y = e
- finish_y = b
- if c <= f:
- start_z = c
- finish_z = f
- else:
- start_z = f
- finish_z = c
- for point in points:
- x, y, z = point
- if (start_x <= x <= finish_x and start_y <= y <= finish_y
- and start_z <= z <= finish_z):
- self.send_chat('This area is protected!')
- return False
- return connection.on_line_build_attempt(self, points)
- return protocol, MapExtensionConnection
Advertisement
Add Comment
Please, Sign In to add comment