Code: Select all
EDIT: made it so that the towers are the actual team colours, not just blue and green"""
thepolm3
converts the intel to a tower to be defended
"""
from twisted.internet.reactor import callLater
from pyspades.constants import *
from pyspades.server import block_action, set_color, block_line
from commands import get_team
from pyspades.common import make_color
HIDE_COORD=(0,0,0)
def apply_script(protocol, connection, config):
class IntelTowerConnection(connection):
def on_flag_take(self):
if self.protocol.flagtakingallowed:
return connection.on_flag_take(self)
self.send_chat("Destroy the tower up top, don't get the intel!")
return False
def on_block_destroy(self, x, y, z, mode):
xa,ya=self.protocol.intels[0]
xb,yb=self.protocol.intels[1]
if 1>=x-xa>=-1 and 1>=y-ya>=-1: #if blue tower
if self.tool!=SPADE_TOOL:
return False
if self.team==get_team(self,"blue"):
return False
callLater(0.1,self.protocol.check_win,self)
if 1>=x-xb>=-1 and 1>=y-yb>=-1: #if green tower
if self.tool!=SPADE_TOOL:
return False
if self.team==get_team(self,"green"):
return False
callLater(0.1,self.protocol.check_win,self)
return connection.on_block_destroy(self, x, y, z, mode)
class IntelTowerProtocol(protocol):
game_mode=CTF_MODE
flagtakingallowed=False
intels=[0,0]
towers=[0,0]
def destroyBlock(self, x,y,z):
if 1<x<511 and 1<y<511 and 1<z<63:
block_action.value = DESTROY_BLOCK
block_action.x,block_action.y,block_action.z=x,y,z
self.map.remove_point(x,y,z)
self.send_contained(block_action)
def buildBlock(self, x,y,z,colour):
if 1<x<511 and 1<y<511 and 1<z<63:
block_action.value = BUILD_BLOCK
block_action.x,block_action.y,block_action.z=x,y,z
set_color.value=make_color(*colour)
self.map.set_point(x,y,z,colour)
self.send_contained(block_action)
self.send_contained(set_color)
def win_round(self,winner):
self.flagtakingallowed=True
winner.take_flag()
winner.capture_flag()
self.flagtakingallowed=False
temp=self.respawn_time
self.respawn_time=1
for name in self.players:
player=self.players[name]
if player.world_object:
player.kill()
self.respawn_time=temp
def blue_tower_has_fallen(self):
x,y,z=self.towers[0]
if self.map.get_solid(x,y,z):
return False
return True
def green_tower_has_fallen(self):
x,y,z=self.towers[1]
if self.map.get_solid(x,y,z):
return False
return True
def check_win(self,player):
if player.team==get_team(player,"blue"):
if self.green_tower_has_fallen():
self.destroy_old_tower(1)
self.win_round(player)
elif player.team==get_team(player,"green"):
if self.blue_tower_has_fallen():
self.destroy_old_tower(0)
self.win_round(player)
def destroy_old_tower(self, ID=0):
xa,ya=self.intels[ID]
xb,yb,zb=self.towers[ID]
height=zb+9
zb=height
solid=False
for x in range(-1,2):
for y in range(-1,2):
for z in range(0,height):
self.destroyBlock(x+xa,y+ya,z)
self.buildBlock(xa,ya,62,(155,155,155))
def create_tower(self,ID):
xa,ya=self.intels[ID]
height=self.map.get_z(xa,ya)-10
colour=[self.blue_team.color,self.green_team.color][ID]
for x in range(-1,2):
for y in range(-1,2):
for z in range(height,64):
self.buildBlock(x+xa,y+ya,z,colour)
for x in range(-1,2):
for y in range(-1,2):
self.destroyBlock(x+xa,y+ya,height+1)
self.buildBlock(x+xa,y+ya,height+1,(0,0,0))
self.towers[ID]=(x+xa,y+ya,height+1)
self.destroyBlock(xa,ya,62) #puts the intel below the tower
def on_flag_spawn(self, x, y, z, flag, entity_id):
if x<3:
x+=3
elif x>509:
x-=3
if y<3:
y+=3
elif y>509:
y-=3
self.intels[entity_id]=(x,y)
self.create_tower(entity_id)
return (x,y,63)
return IntelTowerProtocol, IntelTowerConnection
EDIT: made it so that it works with squads
EDIT: made it so that the towers are consistent
THANK YOU SO MUCH ICECRAFT! <3
