[GAME MODE] Tracks

Intended for use on live public servers.
12 posts Page 1 of 1 First unread post
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


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!
Attachments
tracks.py
(3.15 KiB) Downloaded 227 times
Last edited by thepolm3 on Mon Jul 22, 2013 9:52 pm, edited 3 times in total.
Ninja_pig_pro
Build and Shoot's 1st Birthday
Build and Shoot's 1st Birthday
Posts: 418
Joined: Thu Dec 20, 2012 1:24 pm


Thanks!
Can someone make a server for this?
Venator
League Participant
League Participant
Posts: 1225
Joined: Wed Nov 07, 2012 8:32 pm


Wow sounds good.
Its exiting to see how many different gamemodes you are able to produce :D
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


Its exciting that all this is possible on a python based server!
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


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?
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


I don't know why that would happen... Can you give more details about what you did?
colorpinpoint
League Champs
League Champs
Posts: 60
Joined: Tue Nov 06, 2012 11:06 pm


Line 15 should be:

class TracksProtocol(protocol):

instead of:

class TracksProtocol(protocol):s
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


hmmm... I don't think thats in the download
but thanks! I really should have spotted that.
colorpinpoint
League Champs
League Champs
Posts: 60
Joined: Tue Nov 06, 2012 11:06 pm


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'
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


ignore; its not a critical eroor, i'll fix when i have a bit o free time
colorpinpoint
League Champs
League Champs
Posts: 60
Joined: Tue Nov 06, 2012 11:06 pm


Also the script seems to be erroring out and getting 100% cpu usage.
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


AH. There are two settings at the top of the script. Lower them to get better performance
12 posts Page 1 of 1 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 16 guests