Guest User

Untitled

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