Page 1 of 1

[GAME MODE] Tracks

Posted: Tue May 28, 2013 2:57 pm
by thepolm3
Idea by ninjapig; Original topic
Code: Select all
"""
thepolm3
tracks, based on "payload" from tf2
idea by ninja pig
"""

from pyspades.collision import vector_collision
from twisted.internet.task import LoopingCall
#the default looks quite smooth
STEPS=1000
SPEED=10#moves per second
HIDE_POS=(0,0,63)
def apply_script(protocol, connection, config):
    
    class TracksProtocol(protocol):
        game_mode=xstep=ystep=xg=yg=winning_allowed=0

        def advance_cart(self,player):
            team=player.team
            cart=self.green_team.flag
            x,y=float(cart.x),float(cart.y)
            if team==self.green_team:
                x+=float(self.xstep)
                y+=float(self.ystep)
            else:
                x-=float(self.xstep)
                y-=float(self.ystep)
            cart.set(x,y,self.map.get_z(x,y))
            cart.update()
            if vector_collision(team.other.base, cart):
                self.winning_allowed=1
                player.take_flag()
                player.capture_flag()
                self.winning_allowed=0
                self.reset_cart()
                for player in self.players.values():
                    player.spawn()

        def reset_cart(self):
            cart=self.green_team.flag
            x,y=self.xstep*(STEPS/2)+self.xg,self.ystep*(STEPS/2)+self.yg
            cart.set(x,y,self.map.get_z(x,y))
            cart.update()

        def initial_setup(self):
            g=self.green_team.base #temp
            b=self.blue_team.base
            xg,yg=float(g.x),float(g.y)
            xb,yb=float(b.x),float(b.y)
            self.xstep=(xb-xg)/STEPS
            self.ystep=(yb-yg)/STEPS
            self.xg,self.yg=xg,yg
            #flagsetting time!
            self.reset_cart()

        def on_connect(self,connection):
            if not self.xstep:
                self.initial_setup()
            return protocol.on_connect(self,connection)

        def on_advance(self,map):
            for player in self.players.values():
                player.cartcheck = None
            return protocol.on_advance(self,map)

        def on_flag_spawn(self,x,y,z,flag,entity_id):
            return(0,0,0)

    class TracksConnection(connection):
        cartcheck=None
        
        def on_spawn(self,pos):
            if self.cartcheck:
                self.cartcheck.stop()
            self.cartcheck=LoopingCall(self.check_cart)
            self.cartcheck.start(1/SPEED)
            return connection.on_spawn(self,pos)

        def check_cart(self):
            if self.protocol.green_team and self.protocol.green_team.flag and self.world_object:
                if vector_collision(self.world_object.position, self.protocol.green_team.flag):
                    self.protocol.advance_cart(self)
        
        def on_flag_take(self):
            if self.protocol.winning_allowed:
                return connection.on_flag_take(self)
            return False
            

        def on_flag_capture(self):
            if self.protocol.winning_allowed:
                return connection.on_flag_capture(self)
            return False
    
    return TracksProtocol, TracksConnection
Intel is on invisible track between the bases: touching it will send it off on this track

Download the mod pack!
Download!

Re: [GAME MODE] Tracks

Posted: Sat Jun 01, 2013 6:14 pm
by Ninja_pig_pro
Thanks!
Can someone make a server for this?

Re: [GAME MODE] Tracks

Posted: Sun Jun 02, 2013 11:25 am
by Venator
Wow sounds good.
Its exiting to see how many different gamemodes you are able to produce :D

Re: [GAME MODE] Tracks

Posted: Sun Jun 02, 2013 11:41 am
by thepolm3
Its exciting that all this is possible on a python based server!

Re: [GAME MODE] Tracks

Posted: Sun Jun 02, 2013 7:54 pm
by TB_
Nothing seemed to happen when we played it earlier. It acted like CTF. Do you have to write down where the invisible tracks goes somewhere?

Re: [GAME MODE] Tracks

Posted: Sun Jun 02, 2013 8:46 pm
by thepolm3
I don't know why that would happen... Can you give more details about what you did?

Re: [GAME MODE] Tracks

Posted: Mon Jun 03, 2013 3:07 am
by colorpinpoint
Line 15 should be:

class TracksProtocol(protocol):

instead of:

class TracksProtocol(protocol):s

Re: [GAME MODE] Tracks

Posted: Mon Jun 03, 2013 7:24 am
by thepolm3
hmmm... I don't think thats in the download
but thanks! I really should have spotted that.

Re: [GAME MODE] Tracks

Posted: Mon Jun 24, 2013 2:31 pm
by colorpinpoint
There was a problem with the script.

line 75, in check_cart
if vector_collision(self.world_object.position, self.protocol.green_team.flag):
exceptions.AttributeError: 'NoneType' object has no attribute 'position'

Re: [GAME MODE] Tracks

Posted: Mon Jun 24, 2013 2:33 pm
by thepolm3
ignore; its not a critical eroor, i'll fix when i have a bit o free time

Re: [GAME MODE] Tracks

Posted: Tue Jun 25, 2013 4:17 am
by colorpinpoint
Also the script seems to be erroring out and getting 100% cpu usage.

Re: [GAME MODE] Tracks

Posted: Tue Jun 25, 2013 7:27 am
by thepolm3
AH. There are two settings at the top of the script. Lower them to get better performance