Page 1 of 1

[GAME MODE] Intel tower 1.3

Posted: Fri Apr 19, 2013 4:49 pm
by thepolm3
This simple *touch wood* script does a simple thing: It replaces the conventional intel with intel "towers" that have to be destroyed by the enemy. Enjoy :)
Code: Select all
"""
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 the towers are the actual team colours, not just blue and green
EDIT: made it so that it works with squads
EDIT: made it so that the towers are consistent
THANK YOU SO MUCH ICECRAFT! <3

Re: [SCRIPT] Intel towers!

Posted: Fri Apr 19, 2013 4:53 pm
by IceCream
Niiice thanks a lot :)

is it something like that?

http://dankesaurus-plugins.googlecode.c ... ower_tc.py

Re: [SCRIPT] Intel towers!

Posted: Fri Apr 19, 2013 4:56 pm
by thepolm3
Haden't seen that! I don't think it does the same thing

Re: [GAME MODE] Intel tower 1.1

Posted: Sat Jun 01, 2013 2:57 pm
by IceCream
Hey,

i think i detected a few bugs:

1. The Intel towers are in the team colors (at the beginning). but the second/third etc towers are always grey.
2. if you are in a squad and you destroyed the tower, the script does not reset you and your squad members. you stay at the enemy base, so you can easily destroy the next tower.

Re: [GAME MODE] Intel tower 1.1

Posted: Sat Jun 01, 2013 3:51 pm
by thepolm3
I spotted that too, weird. I'll get right on it.

Re: [GAME MODE] Intel tower 1.2

Posted: Sat Jun 01, 2013 4:08 pm
by thepolm3
All fixed :) re-download for new, fabulous script

Re: [GAME MODE] Intel tower 1.2

Posted: Sat Jun 01, 2013 5:12 pm
by IceCream
Thanks a lot :3

Re: [GAME MODE] Intel tower 1.3

Posted: Mon Jun 03, 2013 5:13 pm
by thepolm3
ahhhhh sorry, but i just realized that i didn't after all fix the grey tower bug. now fixed. please re-download and sorry again :)