Page 1 of 2

[GAME MODE] King of the hill 1.2

Posted: Sat Jun 22, 2013 9:56 am
by thepolm3
HOLD THE HILL FOR 1 MINUTE 30 SECONDS TO WIN
Please, enjoy :)
Code: Select all
"""
King of the hill ^^
thepolm3

feel free to set the base position via map extensions using
"KOTH":(x,y)
or
"KOTH":(x,y,z)
and then
"spawn_radius":(min,max)
"""

from twisted.internet.task import LoopingCall
from twisted.internet.reactor import seconds,callLater
from pyspades.constants import *
from pyspades.server import Territory
from random import randint

ANNOY = 6 #times
HOLD_HILL_FOR = 90 #seconds
SPAWN_RADIUS = (70,100) #between these away from the tent
DEFAULT_KOTH = (256,256)

def apply_script(protocol, connection, config):
    class KOTHConnection(connection):

        def get_respawn_time(self):
            if self.team!=self.protocol.entities[0].team: return connection.get_respawn_time(self)/2
            return connection.get_respawn_time(self)

        def on_spawn_location(self,pos):
            e=self.protocol.entities[0]
            xa,ya,za,z,count=e.x,e.y,e.z,64,0
            while z>=63 and count<100:
                x,y=[randint(*SPAWN_RADIUS),randint(0,SPAWN_RADIUS[1])]
                if randint(0,1): y,x=x,y
                x*=(randint(1,2)*2)-3
                y*=(randint(1,2)*2)-3
                x,y=x+xa,y+ya
                print(x,y)
                count+=1
                z=self.protocol.map.get_z(x,y)
            return (x,y,z)

        def on_command(self,command,parameters):

            if command=="time":
                self.send_chat("If they hold it for %d seconds, they win!" %(self.protocol.end-seconds()))
                self.send_chat("%s holds the hill" %(self.protocol.entities[0].team.name))
                return False
            return connection.on_command(self,command,parameters)
            
    class KOTHProtocol(protocol):

        telling=None
        end=None
        game_mode = TC_MODE

        def get_cp_entities(self):
            global SPAWN_RADIUS
            if not self.telling:
                self.telling=LoopingCall(self.tell_time)
                self.telling.start(HOLD_HILL_FOR/ANNOY)
            self.end=None
            #gets the coords
            extensions=self.map_info.extensions
            KOTH=DEFAULT_KOTH
            if extensions.has_key("KOTH"):
                KOTH=extensions["KOTH"]
            if extensions.has_key("spawn_radius"):
                KOTH=extensions["spawn_radius"]

            #makes it allow a z if it wants
            if len(KOTH)>2: x,y,z=KOTH
            else:
                x,y=KOTH
                z=self.map.get_z(x,y)

            #create territory
            entity=Territory(0,self,x,y,z)
            entity.team=None

            #y'all just got RETURNED
            return [entity]
        def hill_is_held(self):
            if self.entities:
                for player in self.entities[0].players:
                    if player.team==self.entities[0].team:
                        return True
                return False

        def tell_time(self):
            valid = self.hill_is_held()
            if not valid and self.end:
                self.end+=HOLD_HILL_FOR/ANNOY
                self.send_chat("If they capture it again, they have %ds left!" %(self.end-seconds()))
                self.send_chat("%s has abandoned the hill!" %(self.entities[0].team.name))
            if valid and self.end and self.end-seconds()>0:
                self.send_chat("If they hold it for %d seconds, they win!" %(self.end-seconds()))
                self.send_chat("%s holds the hill" %(self.entities[0].team.name))

        def win(self):
            if self.end and self.end-seconds()<5:
                self.reset_game(None,self.entities[0],True)
                protocol.on_game_end(self)

        def reset_game(self, player = None, territory = None, ovverule=False):
            if ovverule:
                return protocol.reset_game(self, player, territory)
            elif territory:
                territory.update()

        def on_game_end(self):
            return
            
        def on_cp_capture(self,cp):
            #this must be our only cp
            self.end=HOLD_HILL_FOR+seconds()
            team=cp.team.name
            callLater(HOLD_HILL_FOR,self.win)
            self.send_chat("If they hold it for %d seconds, they win!" %(self.end-seconds()))
            self.send_chat("%s has captured the hill" %(team))
            protocol.on_cp_capture(self,cp)

    return KOTHProtocol, KOTHConnection

EDIT betterified the spawn logic
EDIT made it so that the countdown will freeze if the capturing team leaves it for too long

Re: [GAME MODE] King of the hill

Posted: Sat Jun 22, 2013 10:51 am
by KillerShot
Awesome!
What we really need is servers to run all your gamemodes you make! Green_Wink1

Re: [GAME MODE] King of the hill

Posted: Tue Jun 25, 2013 3:45 pm
by LinktersHD
Hey,

I'll be running this gamemode on my server soon.

Nice Scripts. Where did you learn to Python?

Re: [GAME MODE] King of the hill

Posted: Tue Jun 25, 2013 3:48 pm
by thepolm3
I learned to code python @ http://www.codecademy.com/tracks/python

Re: [GAME MODE] King of the hill

Posted: Tue Jun 25, 2013 4:14 pm
by LinktersHD
Ok the server is up, It's called "Operation Metro | Rush".

Re: [GAME MODE] King of the hill

Posted: Tue Jun 25, 2013 4:49 pm
by thepolm3
Sorry, but thats really a fail
  1. This is the topic for KING OF THE HILL, not rush
  2. You picked a map incompatible with rush
  3. Your server has building disabled, meaning that even if they wanted to players couldn't dig to the cps
I would suggest a map like hallway, with building enabled

Re: [GAME MODE] King of the hill

Posted: Tue Jun 25, 2013 4:51 pm
by Jdrew
wow code acaemy, I didn't expect that. Can you set the points with map extinctions?

Re: [GAME MODE] King of the hill

Posted: Tue Jun 25, 2013 4:53 pm
by TB_
So it's a team-based king of a hill, right?

Re: [GAME MODE] King of the hill

Posted: Tue Jun 25, 2013 4:56 pm
by thepolm3
Jdrew
on this yes, but since Links here seems to think this topic is about rush, atm you can't do so in rush

_TB
yes

Re: [GAME MODE] King of the hill

Posted: Tue Jun 25, 2013 4:57 pm
by LinktersHD
Oh, wrong topic. But i just realized that, thanks for letting me know. Forgot about it.

Re: [GAME MODE] King of the hill

Posted: Tue Jun 25, 2013 4:57 pm
by thepolm3
np :)

Re: [GAME MODE] King of the hill

Posted: Tue Jul 02, 2013 2:53 am
by izzy
Testing on aloha.pk king of the hill @ [aos]aos://1379434439:24887[/aos]

Server status page: http://aos075.aloha.pk:24886/

So far I've concluded the game mode is too difficult for the team that doesn't capture the hill first. I have a few suggestions/requests to balance this problem:

1) The team that owns the control point shouldn't spawn near it if an enemy is within range of it - they should instead spawn at their original spawn in the back during this situation. They should only spawn near the control point when no enemies are within range of it.

2) The countdown timer should freeze when an enemy is within range of the control point.

3) The countdown timer should freeze when no teammates are within range of the control point.

Re: [GAME MODE] King of the hill

Posted: Tue Jul 02, 2013 3:08 am
by Jdrew
izzy wrote:
Testing on aloha.pk king of the hill @ [aos]aos://1379434439:24887[/aos]

Server status page: http://aos075.aloha.pk:24886/
Glad to see aloha is spicing it up a bit Blue_Tongue

Re: [GAME MODE] King of the hill

Posted: Tue Jul 02, 2013 7:24 am
by thepolm3
will do izzy;
And thanks for the aloha thing; I've always wanted a gamemode on their servers

Re: [GAME MODE] King of the hill 1.1

Posted: Tue Jul 02, 2013 6:05 pm
by thepolm3
Added the spawn thing... but I was thinking;
If you do the anti-advance thing then surely its just like any other tc tent just slower...
Is that what you want? cause I can do that...
But in addition to, not as a replacement for, this script
Also, in the aloha server the time limit needs to be set to about 3-5 minutes; that should make it more fun
The problem with the gamemode is that it plays like infiltration, but without the team disadvantage that blue would usually have... therefore the captured team needs to be handicapped in some way. Ideas?