Guest User

Untitled

a guest
Apr 12th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.73 KB | None | 0 0
  1. """
  2. Map Extensions+
  3. Extensions to the map metadata;
  4. - Water Damage
  5. - Map-Specific Command Removal
  6. - Spawn Locations
  7. - Block Protection
  8.  
  9. Maintainer: ?
  10. Updated by Influx
  11. """
  12.  
  13. import random
  14.  
  15. def apply_script(protocol, connection, config):
  16.     class MapExtensionConnection(connection):
  17.        
  18.         def on_position_update(self):
  19.             extensions = self.protocol.map_info.extensions
  20.             if (extensions.has_key('water_damage') and
  21.                 self.world_object.position.z>=61):
  22.                 water_damage = extensions['water_damage']
  23.                 self.environment_hit(water_damage)
  24.             if (extensions.has_key('boundary_damage')):
  25.                 x = self.world_object.position.x
  26.                 y = self.world_object.position.y
  27.                 boundary_damage = extensions['boundary_damage']
  28.                 if (x<=boundary_damage['left'] or x>=boundary_damage['right'] or
  29.                     y<=boundary_damage['top'] or y>=boundary_damage['bottom']):
  30.                     self.environment_hit(boundary_damage['damage'])                
  31.             connection.on_position_update(self)
  32.    
  33.         def environment_hit(self, value):
  34.             if value < 0 and self.hp >= 100: # do nothing at max health
  35.                 return
  36.             self.set_hp(self.hp - value)
  37.        
  38.         def on_command(self, command, parameters):
  39.             disabled = self.protocol.map_info.extensions.get(
  40.                 'disabled_commands', [])
  41.             if command in disabled:
  42.                 self.send_chat("Command '%s' disabled for this map" % command)
  43.                 return
  44.             return connection.on_command(self, command, parameters)
  45.            
  46.            
  47.         def on_spawn_location(self, pos):
  48.             extensions = self.protocol.map_info.extensions
  49.             if (extensions.has_key('blue_spawn')):
  50.                 blue_spawn_centre = extensions['blue_spawn']
  51.             else:
  52.                 blue_spawn_centre = None
  53.             if (extensions.has_key('green_spawn')):
  54.                 green_spawn_centre = extensions['green_spawn']
  55.             else:
  56.                 green_spawn_centre = None
  57.             if (extensions.has_key('blue_spawn_offset')):
  58.                 blue_spawn_offset = extensions['blue_spawn_offset']
  59.             else:
  60.                 blue_spawn_offset = 100
  61.             if (extensions.has_key('green_spawn_offset')):
  62.                 green_spawn_offset = extensions['green_spawn_offset']
  63.             else:
  64.                 green_spawn_offset = 100
  65.             if self.team == self.protocol.blue_team:
  66.                 spawn_centre = blue_spawn_centre
  67.                 spawn_offset = blue_spawn_offset
  68.             elif self.team == self.protocol.green_team:
  69.                 spawn_centre = green_spawn_centre
  70.                 spawn_offset = green_spawn_offset
  71.             if spawn_centre != None:
  72.                 spawn_choice = random.choice(spawn_centre)
  73.                 if len(spawn_choice) == 3:
  74.                     x1, y1, z = spawn_choice
  75.                     x, y = self.protocol.map.get_random_point((x1 - spawn_offset), (y1 - spawn_offset), (x1 + spawn_offset), (y1 + spawn_offset))
  76.                     newpos = x, y, z
  77.                     return newpos
  78.                 elif len(spawn_choice) == 2:
  79.                     x1, y1 = spawn_choice
  80.                     x, y = self.protocol.map.get_random_point((x1 - spawn_offset), (y1 - spawn_offset), (x1 + spawn_offset), (y1 + spawn_offset))
  81.                     z = self.protocol.map.get_z(x, y)
  82.                     newpos = x, y, z
  83.                     return newpos
  84.             return connection.on_spawn_location(self, pos)
  85.                    
  86.         def on_block_destroy(self, x, y, z, mode):
  87.             extensions = self.protocol.map_info.extensions
  88.             if (extensions.has_key('protected')):
  89.                 protected = extensions['protected']
  90.             if mode == 3:
  91.                 grenade_prevention = 1
  92.             else:
  93.                 grenade_prevention = 0
  94.             for area in protected:
  95.                 start, finish = area
  96.                 a, b, c = start
  97.                 d, e, f = finish
  98.                 if a <= d:
  99.                     start_x = a - grenade_prevention
  100.                     finish_x = d + grenade_prevention
  101.                 else:
  102.                     start_x = d - grenade_prevention
  103.                     finish_x = a + grenade_prevention
  104.                 if b <= e:
  105.                     start_y = b - grenade_prevention
  106.                     finish_y = e + grenade_prevention
  107.                 else:
  108.                     start_y = e - grenade_prevention
  109.                     finish_y = b + grenade_prevention
  110.                 if c <= f:
  111.                     start_z = c - grenade_prevention
  112.                     finish_z = f + grenade_prevention
  113.                 else:
  114.                     start_z = f - grenade_prevention
  115.                     finish_z = c + grenade_prevention
  116.                 if (start_x <= x <= finish_x and start_y <= y <= finish_y
  117.                     and start_z <= z <= finish_z):
  118.                     self.send_chat('This area is protected!')
  119.                     return False    
  120.             return connection.on_block_destroy(self, x, y, z, mode)
  121.  
  122.         def on_block_build_attempt(self, x, y, z):
  123.             extensions = self.protocol.map_info.extensions
  124.             if (extensions.has_key('protected')):
  125.                 protected = extensions['protected']
  126.             for area in protected:
  127.                 start, finish = area
  128.                 a, b, c = start
  129.                 d, e, f = finish
  130.                 if a <= d:
  131.                     start_x = a
  132.                     finish_x = d
  133.                 else:
  134.                     start_x = d
  135.                     finish_x = a
  136.                 if b <= e:
  137.                     start_y = b
  138.                     finish_y = e
  139.                 else:
  140.                     start_y = e
  141.                     finish_y = b
  142.                 if c <= f:
  143.                     start_z = c
  144.                     finish_z = f
  145.                 else:
  146.                     start_z = f
  147.                     finish_z = c
  148.                 if (start_x <= x <= finish_x and start_y <= y <= finish_y
  149.                     and start_z <= z <= finish_z):
  150.                     self.send_chat('This area is protected!')
  151.                     return False    
  152.             return connection.on_block_build_attempt(self, x, y, z)
  153.  
  154.         def on_line_build_attempt(self, points):
  155.             extensions = self.protocol.map_info.extensions
  156.             if (extensions.has_key('protected')):
  157.                 protected = extensions['protected']
  158.             for area in protected:
  159.                 start, finish = area
  160.                 a, b, c = start
  161.                 d, e, f = finish
  162.                 if a <= d:
  163.                     start_x = a
  164.                     finish_x = d
  165.                 else:
  166.                     start_x = d
  167.                     finish_x = a
  168.                 if b <= e:
  169.                     start_y = b
  170.                     finish_y = e
  171.                 else:
  172.                     start_y = e
  173.                     finish_y = b
  174.                 if c <= f:
  175.                     start_z = c
  176.                     finish_z = f
  177.                 else:
  178.                     start_z = f
  179.                     finish_z = c
  180.                 for point in points:
  181.                     x, y, z = point
  182.                     if (start_x <= x <= finish_x and start_y <= y <= finish_y
  183.                         and start_z <= z <= finish_z):
  184.                         self.send_chat('This area is protected!')
  185.                         return False    
  186.             return connection.on_line_build_attempt(self, points)
  187.            
  188.            
  189.     return protocol, MapExtensionConnection
Advertisement
Add Comment
Please, Sign In to add comment