Push is driven by map extensions. The map makers set spawn size, spawn locations, and command post locations for each team and sets water damage to 100. Use the code below as a guide to create your own push maps.
Code: Select all
This script itself:extensions = {
'push': True,
'push_spawn_range' : 5,
'push_blue_spawn' : (91, 276, 59),
'push_blue_cp' : (91, 276, 59),
'push_green_spawn' : (78, 86, 59),
'push_green_cp' : (78, 86, 59),
'water_damage' : 100
}
Code: Select all
# The idea of Push
# Teams spawn at set locations with the intel
# They push the intel towards the CP's, which is also a set location
#
#Essentially we need read the map meta data get the spawn and cp locations
# and have the players and cp spawn at the apporiate locations
#
#Bonus feature: on intel cap the map rollbacks
#
# Sample extensions dictionary of an arena map with two gates:
# In this example there is one spawn location for blue and two spawn locations for green.
# extensions = {
# 'push': True,
# 'push_spawn_range' : 5,
# 'push_blue_spawn' : (91, 276, 59),
# 'push_blue_cp' : (91, 276, 59),
# 'push_green_spawn' : (78, 86, 59),
# 'push_green_cp' : (78, 86, 59),
# 'water_damage' : 100
# }
from pyspades.constants import *
from random import randint
from commands import add, admin
from twisted.internet.task import LoopingCall
from pyspades.constants import CTF_MODE
# If ALWAYS_ENABLED is False, then the 'push' key must be set to True in
# the 'extensions' dictionary in the map metadata
ALWAYS_ENABLED = False
GRIEF_PROTECTION = False
KILL_REQUIREMENT = 5
#team is associated intel team
def reset_intel(protocol, team):
extensions = protocol.map_info.extensions
if team is protocol.green_team and extensions.has_key('push_blue_spawn'):
z = protocol.map.get_z(*extensions.get('push_blue_spawn'))
pos = (extensions.get('push_blue_spawn')[0], extensions.get('push_blue_spawn')[1], z)
if team is protocol.blue_team and extensions.has_key('push_green_spawn'):
z = protocol.map.get_z(*extensions.get('push_green_spawn'))
pos = (extensions.get('push_green_spawn')[0], extensions.get('push_green_spawn')[1], z)
team.flag.set(*pos)
team.flag.update()
protocol.send_chat("The %s intel has been reset." % team.name)
@admin
def resetblueintel(connection):
reset_intel(connection.protocol, connection.protocol.blue_team)
@admin
def resetgreenintel(connection):
reset_intel(connection.protocol, connection.protocol.green_team)
add(resetblueintel)
add(resetgreenintel)
def get_entity_location(self, entity_id):
extensions = self.protocol.map_info.extensions
if entity_id == BLUE_BASE and extensions.has_key('push_blue_cp'):
return extensions['push_blue_cp']
elif entity_id == GREEN_BASE and extensions.has_key('push_green_cp'):
return extensions['push_green_cp']
#this next part might seem counter intiutive but you need the blue intel to spawn near the greens and vice versa
elif entity_id == BLUE_FLAG and extensions.has_key('push_green_spawn'):
return extensions['push_green_spawn']
elif entity_id == GREEN_FLAG and extensions.has_key('push_blue_spawn'):
return extensions['push_blue_spawn']
def get_spawn_location(connection):
extensions = connection.protocol.map_info.extensions
#distance from spawn center to randomly spawn in
spawn_range = 5;
if extensions.has_key('push_spawn_range'):
spawn_range = extensions['push_spawn_range']
if connection.team is connection.protocol.blue_team:
if extensions.has_key('push_blue_spawn'):
xb = extensions.get('push_blue_spawn')[0]
yb = extensions.get('push_blue_spawn')[1]
xb += randint(-spawn_range, spawn_range)
yb += randint(-spawn_range, spawn_range)
return (xb, yb, connection.protocol.map.get_z(xb, yb))
if connection.team is connection.protocol.green_team:
if extensions.has_key('push_green_spawn'):
xb = extensions.get('push_green_spawn')[0]
yb = extensions.get('push_green_spawn')[1]
xb += randint(-spawn_range, spawn_range)
yb += randint(-spawn_range, spawn_range)
return (xb, yb, connection.protocol.map.get_z(xb, yb))
def apply_script(protocol, connection, config):
class PushProtocol(protocol):
push = False
check_loop = None
game_mode = CTF_MODE
def check_intel_locations(self):
if self.blue_team.flag is not None:
if self.blue_team.flag.get()[2] >= 63:
reset_intel(self, self.blue_team)
if self.green_team.flag is not None:
if self.green_team.flag.get()[2] >= 63:
reset_intel(self, self.green_team)
def on_map_change(self, map):
extensions = self.map_info.extensions
if ALWAYS_ENABLED:
self.push = True
else:
if extensions.has_key('push'):
self.push = extensions['push']
else:
self.push = False
if self.push:
self.map_info.get_entity_location = get_entity_location
self.map_info.get_spawn_location = get_spawn_location
self.check_loop = LoopingCall(self.check_intel_locations)
self.check_loop.start(0.5)
return protocol.on_map_change(self, map)
# class PushConnection(connection):
# kill_reputation = 0
# def on_team_changed(self, old_team):
# self.kill_reputation = 0
# return connection.on_team_changed(self, old_team)
# def on_block_destroy(self, x, y, z, mode):
# if GRIEF_PROTECTION and self.kill_reputation < KILL_REQUIREMENT:
# self.send_chat("You need more kills to be able to destroy blocks.")
# return False
# return connection.on_block_destroy(self, x, y, z, mode)
# def on_kill(self, killer, type, grenade):
# self.kill_reputation += 1
# return connection.on_kill(self, killer, type, grenade)
return PushProtocol, connection