Ninja_Pig

Survivor.py

Apr 12th, 2013
161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Free for all script written by Yourself
  2. # With scripts from: Jail.py and arena.py
  3. # And btw I doubt this works; Ninja Pig
  4.  
  5.  
  6. from random import randint
  7. from pyspades.common import to_coordinates, coordinates
  8. from commands import add, admin, get_player, join_arguments, name, alias
  9. from pyspades.constants import *
  10.  
  11. jail_location = 0, 0, 0 # x, y, z of the spectator room
  12. jail_coords   = [ ] # e.g. ["B4", "B5"]
  13.  
  14. # If ALWAYS_ENABLED is False, free for all can still be enabled in the map
  15. # metadata by setting the key 'free_for_all' to True in the extensions dictionary
  16. ALWAYS_ENABLED = True
  17.  
  18. # If WATER_SPANS is True, then players can spawn in water
  19. WATER_SPAWNS = False
  20.  
  21. HIDE_POS = (0, 0, 63)
  22.  
  23. def apply_script(protocol, connection, config):
  24.     class FreeForAllProtocol(protocol):
  25.         free_for_all = False
  26.         old_friendly_fire = None
  27.         def on_map_change(self, map):
  28.             extensions = self.map_info.extensions
  29.             if ALWAYS_ENABLED:
  30.                 self.free_for_all = True
  31.             else:
  32.                 if extensions.has_key('free_for_all'):
  33.                     self.free_for_all = extensions['free_for_all']
  34.                 else:
  35.                     self.free_for_all = False
  36.             if self.free_for_all:
  37.                 self.old_friendly_fire = self.friendly_fire
  38.                 self.friendly_fire = True
  39.             else:
  40.                 if self.old_friendly_fire is not None:
  41.                     self.friendly_fire = self.old_friendly_fire
  42.                     self.old_friendly_fire = None
  43.             return protocol.on_map_change(self, map)
  44.  
  45.         def on_base_spawn(self, x, y, z, base, entity_id):
  46.             if self.free_for_all:
  47.                 return HIDE_POS
  48.             return protocol.on_base_spawn(self, x, y, z, base, entity_id)
  49.  
  50.         def on_flag_spawn(self, x, y, z, flag, entity_id):
  51.             if self.free_for_all:
  52.                 return HIDE_POS
  53.             return protocol.on_flag_spawn(self, x, y, z, flag, entity_id)
  54.  
  55.     class FreeForAllConnection(connection):
  56.         score_hack = False
  57.         def on_spawn_location(self, pos):
  58.             if not self.score_hack and self.protocol.free_for_all:
  59.                 while True:
  60.                     x = randint(0, 511)
  61.                     y = randint(0, 511)
  62.                     z = self.protocol.map.get_z(x, y)
  63.                     if z != 63 or WATER_SPAWNS:
  64.                         break
  65.                 # Magic numbers taken from server.py spawn function
  66.                 z -= 2.4
  67.                 x += 0.5
  68.                 y += 0.5
  69.                 return (x, y, z)
  70.             return connection.on_spawn_location(self, pos)
  71.  
  72.         def on_refill(self):
  73.             if self.protocol.free_for_all:
  74.                 return False
  75.             return connection.on_refill(self)
  76.  
  77.         def on_flag_take(self):
  78.             if self.protocol.free_for_all:
  79.                 return False
  80.             return connection.on_flag_take(self)
  81.  
  82.         def on_kill(self, by, type, grenade):
  83.             # Switch teams to add score hack
  84.             if by is not None and by.team is self.team and self is not by:
  85.                 self.score_hack = True
  86.                 pos = self.world_object.position
  87.                 self.set_team(self.team.other)
  88.                 self.spawn((pos.x, pos.y, pos.z))
  89.                 self.score_hack = False
  90.             return connection.on_kill(self, by, type, grenade)
  91.  
  92.                 def on_spawn(self, pos):
  93.             returned = connection.on_spawn(self, pos)
  94.               protocol = connection.protocol # Meh
  95.     player = get_player(protocol, value) # Get player
  96.  
  97.  
  98.     return FreeForAllProtocol, FreeForAllConnection
RAW Paste Data