[GAME MODE] King of the hill 1.2

29 posts Page 1 of 2 First unread post
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


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
Attachments
koth.py
(4.4 KiB) Downloaded 718 times
Last edited by thepolm3 on Fri Jul 05, 2013 3:34 pm, edited 4 times in total.
KillerShot


Awesome!
What we really need is servers to run all your gamemodes you make! Green_Wink1
LinktersHD
Deuced Up
Posts: 124
Joined: Thu Nov 01, 2012 12:27 pm


Hey,

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

Nice Scripts. Where did you learn to Python?
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


I learned to code python @ http://www.codecademy.com/tracks/python
LinktersHD
Deuced Up
Posts: 124
Joined: Thu Nov 01, 2012 12:27 pm


Ok the server is up, It's called "Operation Metro | Rush".
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


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
Jdrew
Mapper
Mapper
Posts: 4808
Joined: Tue Oct 30, 2012 10:48 pm


wow code acaemy, I didn't expect that. Can you set the points with map extinctions?
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


So it's a team-based king of a hill, right?
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


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
Last edited by thepolm3 on Tue Jun 25, 2013 4:57 pm, edited 1 time in total.
LinktersHD
Deuced Up
Posts: 124
Joined: Thu Nov 01, 2012 12:27 pm


Oh, wrong topic. But i just realized that, thanks for letting me know. Forgot about it.
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


np :)
izzy
Head Admin / Co-founder
Head Admin / Co-founder
Posts: 474
Joined: Tue Oct 09, 2012 8:16 pm


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.
Jdrew
Mapper
Mapper
Posts: 4808
Joined: Tue Oct 30, 2012 10:48 pm


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


will do izzy;
And thanks for the aloha thing; I've always wanted a gamemode on their servers
Last edited by thepolm3 on Tue Jul 02, 2013 6:07 pm, edited 1 time in total.
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


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?
29 posts Page 1 of 2 First unread post
Return to “Game Modes”

Who is online

Users browsing this forum: No registered users and 5 guests