[GAME MODE] MIXED 1.4

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


So what this script does is allow you to change the game modes in game!
I've been working on it since forever!
Btw, some scripts are incompatible so I have modified them

Command: /gamemode [modename]

Lines to add to config.txt;
"game_modes" : [#1,#2,#3],
e.g
Code: Select all
"game_modes" : [
        "tow",
        "hardpoint",
        "moba",
        "rush",
        "irpg",
        "koth",
        "zombies",
        "babel",
        "push",
        "ded",
        "arena",
        "tdm",
        "build",
        "dug",
        "itower",
        "onectf",
        "rctf",
        "sabotage",
        "tracks",
        "infiltration"],
and you also need to add
"random_modes" : true/false/None,

true means that your gamemodes will rotate randomly (unless you have another script like intelimap)
false means that your gamemodes will rotate one after another, in the order you specify
None (or if you omit this setting) means that your gamemodes will not rotate, and will stay on whichever one you type with /gamemode

happy mixing!
Code: Select all
#mixed.py by thepolm3
"""mixes up gamemodes"""
#ftw

#new gamemodes go in config.txt as game_modes = ["mode1","mode2"] etc

from pyspades.constants import *
from commands import add, admin, alias
from twisted.internet.task import LoopingCall
from random import randint

game_modes=[]
GAME_MODES=[]

def get_real_modes():
    global GAME_MODES
    for mode in game_modes:
        exec("import "+mode)
        GAME_MODES.append(eval(mode))

GMCS = []
GMPS = []
@admin
@alias("gm")

def gamemode(connection, mode):
    if mode.lower() in game_modes or mode.lower() in ["tc","ctf"]:
        connection.protocol.set_gamemode(mode.lower())
        print("Gamemode set to "+mode.upper())
    else:
        return "Invalid mode"

add(gamemode)
    

def apply_script(protocol,connection,config):
    global GMCS,GMPS,game_modes
    
    game_modes = config.get("game_modes",game_modes)
    get_real_modes()
    
    protocol_class, connection_class = protocol,connection
    for mode in GAME_MODES:
        protocol_class, connection_class = mode.apply_script(protocol,
            connection, config)
        GMPS.append(protocol_class)
        GMCS.append(connection_class)
    
    class MixedConnection(connection): pass
    for con in GMCS:
        class MixedConnection(MixedConnection, con):
            pass

    class MixedProtocol(protocol): pass
    for pro in GMPS:
        class MixedProtocol(MixedProtocol, pro):
            pass

    class MixedProtocol(MixedProtocol):
        game_mode = CTF_MODE
        mode_transition = False
        current_mode = "ctf"
        olds = []
        gmc , gmp , old_gmp = connection,protocol,protocol

        def set_gamemode(self, mode, advance = True, superquick = False): #only supply advance as false when calling from inside "on_advance"
            if self.mode_transition:
                return
            else:
                self.mode_transition = True
            if advance:
                try:
                    mode = self.on_mode_change(self,mode) or mode
                except Exception:
                    pass

            name = config.get("name","Deuceserver")
            if " - " in name:
                name = name.split(" - ")
                if name[len(name)-1] in game_modes or name[len(name)-1] in ["ctf","tc"]:
                    name[len(name)-1] = mode
                else:
                    name.append(mode)
                name = " - ".join(name)
                
            else: name+=" - "+mode
            config['name'] = name
            if self.map:
                self.update_format()
            
            self.old_gmp = self.gmp
            if advance:
                if superquick:
                    self.advance_rotation()
                else:
                    self.advance_rotation('New gamemode: '+mode+". ")
            if mode in ["tc","ctf"]:
                self.game_mode = [TC_MODE,CTF_MODE][mode=="ctf"]
                self.gmp,self.gmc = protocol,connection
            else:
                self.game_mode = GMPS[game_modes.index(mode)].game_mode
                self.gmp,self.gmc = GMPS[game_modes.index(mode)],GMCS[game_modes.index(mode)]
            self.current_mode = mode

        def on_advance(self, map):
            if not self.mode_transition:
                rotating = config.get("random_modes",None)
                mode = self.current_mode
                next_mode = mode
                if mode in ["tc","ctf"]:
                    if game_modes:
                        if rotating == False: next_mode = game_modes[0]
                        elif rotating == True: next_mode = game_modes[randint(0,len(game_modes)-1)]
                    else:
                        if rotating == False: next_mode = ["tc","ctf"][mode=="tc"]
                        elif rotating == True: next_mode = ["tc","ctf"][randint(0,1)]
                else:
                    if rotating == False: next_mode = game_modes[(game_modes.index(mode)+1)%len(game_modes)]
                    elif rotating == True: next_mode = game_modes[randint(0,len(game_modes)-1)]
                if "on_mode_advance" in dir(self):
                    next_mode = protocol.on_mode_advance(self,next_mode,map) or next_mode
                print("Loading mode '"+next_mode+"'...")
                self.send_chat("New gamemode; "+next_mode)
                self.set_gamemode(next_mode,False)
            ret = self.old_gmp.on_advance(self, map)
            self.old_gmp = self.gmp
            return ret
    
        def on_map_change(self, map):
            self.mode_transition = False
            return self.gmp.on_map_change(self, map)

        def on_map_leave(self):
            return self.old_gmp.on_map_leave(self)
        #end of script









































        #all beyond this point is placeholders for the gamemode switchers
        def add_ban(self,ip, reason, duration, name = None):
            return self.gmp.add_ban(self,ip, reason, duration, name)

        def advance_rotation(self, message = None):
            return self.gmp.advance_rotation(self, message)

        def call_end(self, delay, func, *arg, **kw):
            return self.gmp.call_end(self, delay, func, *arg, **kw)

        def cancel_vote(self, connection = None):
            return self.gmp.cancel_vote(self,connection)

        def get_advance_time(self):
            return self.gmp.get_advance_time(self)

        def get_cp_entities(self):
            return self.gmp.get_cp_entities(self)

        def get_fog_color(self):
            return self.gmp.get_fog_color(self)

        def get_map(self, rot_info):
            return self.gmp.get_map(self, rot_info)

        def get_map_rotation(self):
            return self.gmp.get_map_rotation(self)

        def get_mode_mode(self):
            return self.gmp.get_mode_mode(self)

        def get_mode_name(self):
            return self.gmp.get_mode_name(self)

        def get_name(self, name):
            return self.gmp.get_name(self, name)

        def get_random_location(self, force_land = True, zone = (0, 0, 512, 512)):
            return self.gmp.get_random_location(self, force_land, zone)

        def got_master_connection(self, client):
            return self.gmp.got_master_connection(self, client)

        def irc_say(self, msg, me = False):
            return self.gmp.irc_say(self, msg, me)

        def is_indestructable(self, x,y,z):
            return self.gmp.is_indestructable(self, x,y,z)

        def master_disconnected(self, client = None):
            return self.gmp.master_disconnected(self, client = None)

        def on_ban(self, connection, reason, duration):
            return self.gmp.on_ban(self, connection, reason, duration)

        def on_ban_attempt(self, connection, reason, duration):
            return self.gmp.on_ban_attempt(self, connection, reason, duration)

        def on_base_spawn(self, x, y, z, base, entity_id):
            return self.gmp.on_base_spawn(self, x, y, z, base, entity_id)

        def on_connect(self,connection):
            return self.gmp.on_connect(self, connection)

        def on_cp_capture(self, cp):
            return self.gmp.on_cp_capture(self, cp)

        def on_disconnect(self,connection):
            return self.gmp.on_disconnect(self,connection)

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

        def on_game_end(self):
            return self.gmp.on_game_end(self)

        def on_update_entity(self, entity):
            return self.gmp.on_update_entity(self, entity)

        def on_world_update(self):
            return self.gmp.on_world_update(self)

        def reconnect_master(self):
            return self.gmp.reconnect_master(self)

        def remove_ban(self, ip):
            return self.gmp.remove_ban(self, ip)

        def reset_game(self, player = None, territory = None):
            return self.gmp.reset_game(self, player, territory)

        def reset_tc(self):
            return self.gmp.reset_tc(self)

        def save_bans(self):
            return self.gmp.save_bans(self)
        
        def send_chat(self, value, global_message = True, sender = None, team = None, irc = False):
            return self.gmp.send_chat(self, value, global_message, sender,team, irc)

        def send_tip(self):
            return self.gmp.send_tip(self)

        def set_fog_color(self, colour):
            return self.gmp.set_fog_color(self, colour)

        def set_map_name(self, rot_info):
            return self.gmp.set_map_name(self, rot_info)

        def set_time_limit(self, time_limit = None, additive = False):
            return self.gmp.set_time_limit(self, time_limit, additive)

        def undo_last_ban(self):
            return self.gmp.undo_last_ban(self)
        
    class MixedConnection(MixedConnection):
        #taken straight from server.py

        def add_score(self,score):
            return self.protocol.gmc.add_score(self,score)

        def ban(self,reason = None, duration = None):
            return self.protocol.gmc.ban(self,reason,duration)

        def capture_flag(self):
            return self.protocol.gmc.capture_flag(self)

        def check_refill(self):
            return self.protocol.gmc.check_refill(self)

        def disconnect(self):
            return self.protocol.gmc.disconnect(self)

        def drop_flag(self):
            return self.protocol.gmc.drop_flag(self)

        def get_location(self):
            return self.protocol.gmc.get_location(self)

        def grenade_exploded(self,grenade):
            return self.protocol.gmc.grenade_exploded(self,grenade)

        def is_location_free(self, x,y,z):
            return self.protocol.gmc.is_location_free(self, x,y,z)

        def is_valid_position(self,x,y,z,distance = None):
            return self.protocol.gmc.is_valid_position(self,x,y,z,distance)

        def kick(self,reason = None,silent = None):
            return self.protocol.gmc.kick(self,reason,silent)

        def refill(self, local = False):
            return self.protocol.gmc.refill(self, local)

        def reset(self):
            return self.protocol.gmc.reset(self)

        def send_chat(self, value, global_message = None):
            return self.protocol.gmc.send_chat(self, value, global_message)

        def take_flag(self):
            return self.protocol.gmc.take_flag(self)

        def spawn(self, pos=None):
            return self.protocol.gmc.spawn(self,pos)

        def respawn(self):
            return self.protocol.gmc.respawn(self)

        def get_respawn_time(self):
            return self.protocol.gmc.get_respawn_time(self)

        def get_spawn_location(self):
            return self.protocol.gmc.get_spawn_location(self)

        def on_respawn(self, pos):
            return self.protocol.gmc.on_respawn(self, pos)

        def on_connect(self):
            return self.protocol.gmc.on_connect(self)

        def on_disconnect(self):
            return self.protocol.gmc.on_disconnect(self)

        def on_user_login(self, name, login):
            return self.protocol.gmc.on_user_login(self, name, login)

        def on_join(self):
            return self.protocol.gmc.on_join(self)
        
        def on_login(self, name):
            return self.protocol.gmc.on_login(self, name)
        
        def on_spawn(self, pos):
            return self.protocol.gmc.on_spawn(self, pos)

        def on_spawn_location(self, pos):
            return self.protocol.gmc.on_spawn_location(self, pos)
        
        def on_chat(self, value, global_message):
            return self.protocol.gmc.on_chat(self, value, global_message)
            
        def on_command(self, command, parameters):
            return self.protocol.gmc.on_command(self, command, parameters)
        
        def on_hit(self, hit_amount, hit_player, hit_icon, grenade):
            return self.protocol.gmc.on_hit(self, hit_amount, hit_player, hit_icon, grenade)
        
        def on_kill(self, killer, type, weapon):
            return self.protocol.gmc.on_kill(self, killer, type, weapon)
        
        def on_team_join(self, team):
            return self.protocol.gmc.on_team_join(self,team)

        def on_team_leave(self):
            return self.protocol.gmc.on_team_leave(self)
        
        def on_tool_set_attempt(self, tool):
            return self.protocol.gmc.on_tool_set_attempt(self, tool)
        
        def on_tool_changed(self, tool):
            return self.protocol.gmc.on_tool_changed(self, tool)
        
        def on_grenade(self, time_left):
            return self.protocol.gmc.on_grenade(self, time_left)
        
        def on_grenade_thrown(self, grenade):        
            return self.protocol.gmc.on_grenade_thrown(self, grenade)
        
        def on_block_build_attempt(self, x, y, z):
            return self.protocol.gmc.on_block_build_attempt(self, x, y, z)
        
        def on_block_build(self, x, y, z):
            return self.protocol.gmc.on_block_build(self, x, y, z)
        
        def on_line_build_attempt(self, points):
            return self.protocol.gmc.on_line_build_attempt(self,points)
        
        def on_line_build(self, points):
            return self.protocol.gmc.on_line_build(self,points)
        
        def on_chat_sent(self, chat, global_message):
            return self.protocol.gmc.on_chat_sent(self,chat, global_message)
        
        def on_block_destroy(self, x, y, z, mode):
            return self.protocol.gmc.on_block_destroy(self, x, y, z, mode)
            
        def on_block_removed(self, x, y, z):
            return self.protocol.gmc.on_block_removed(self, x,  y, z)
        
        def on_refill(self):
            return self.protocol.gmc.on_refill(self)
        
        def on_color_set_attempt(self, color):
            return self.protocol.gmc.on_color_set_attempt(self, color)
        
        def on_color_set(self, color):
            return self.protocol.gmc.on_color_set(self, color)

        def on_color_set_attempt(self, color):
            return self.protocol.gmc.on_color_set_attempt(self,color)

        def on_flag_take(self):
            return self.protocol.gmc.on_flag_take(self)
        
        def on_flag_capture(self):
            return self.protocol.gmc.on_flag_capture(self)
        
        def on_flag_drop(self):
            return self.protocol.gmc.on_flag_drop(self)
        
        def on_hack_attempt(self, reason):
            return self.protocol.gmc.on_hack_attempt(self, reason)

        def on_position_update(self):
            return self.protocol.gmc.on_position_update(self)
        
        def on_input_update(self):
            return self.protocol.gmc.on_input_update(self)
        
        def on_orientation_update(self, x, y, z):
            return self.protocol.gmc.on_orientation_update(self,x,y,z)

        def on_position_update(self):
            return self.protocol.gmc.on_position_update(self)

        def on_animation_update(self, jump, crouch, sneak, sprint):
            return self.protocol.gmc.on_animation_update(self, jump, crouch, sneak, sprint)

        def on_weapon_set(self, value):
            return self.protocol.gmc.on_weapon_set(self, value)
        
        def on_fall(self, damage):
            return self.protocol.gmc.on_fall(self, damage)
        
        def on_reset(self):
           return self.protocol.gmc.on_reset(self)
    
    return MixedProtocol,MixedConnection
DOWNLOAD FOR SCRIPTS

EDIT: Updated downloads, fixed bugs and made it settable via the config
EDIT: now you can cross change between ctf and tc
EDIT: massive update including mode rotation, all *touch wood* bugs fixed and better support for plugin scripts!
EDIT: Better functionality for plugins and fixed numerous bugs
Last edited by thepolm3 on Mon Jul 22, 2013 10:03 pm, edited 9 times in total.
Defero200
Deuce
Posts: 8
Joined: Tue Apr 16, 2013 1:07 pm


AWESOME!!!!!!
Ily polmi <3

:DDD
YAAY
:DDD
xD
HAPPY
:D

- Defero
YAAY
Jdrew
Mapper
Mapper
Posts: 4808
Joined: Tue Oct 30, 2012 10:48 pm


good job!
StarDust
League Participant
League Participant
Posts: 205
Joined: Sun Nov 11, 2012 12:37 pm


very good script, thanks thepolm3
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


jdrew wrote:
good job!
What is up with that second from right kid...
What is he doing? Dancing? Growing?

So anyway, I un-excited the post
Nikolas147
3 Years of Ace of Spades
3 Years of Ace of Spades
Posts: 12
Joined: Wed Dec 19, 2012 5:13 pm


You can make one /votegamemode?
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


oh my god, you actually did it!!
And I Started thinking it was impossible, amazing work polm, best script so far!
colorpinpoint
League Champs
League Champs
Posts: 60
Joined: Tue Nov 06, 2012 11:06 pm


Haven't tested all the game modes but babel has a few problems. First there are 2 intels instead of 1 intel and the babel color is the same as ground color. Don't know if their is specfically a mixed.py or the actual babel script.

Picture:
Image

Edit: Tried infiltration and got this error:
http://bpaste.net/raw/vEX9CcDBoY8Bj9RDtLxn/

Also just a tip is to specify which maps use which game modes.


Extra edit: Game modes don't work at all. Video for example of push: http://youtu.be/Ap3UFAkDZN8
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


babel is my own version. You can change things like that in the script
I will fix the other errors you specefied
EDIT FIXED
Lostmotel
League Participant
League Participant
Posts: 298
Joined: Sun Nov 18, 2012 1:09 pm


wow great work! Blue_Surprised2 Blue_BigSmile
Is it also possible to change the gamemodes via map extensions with this script?
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


No... I'm gonna do a few add-ons like intelimode, mappedmode and votemode
Lostmotel
League Participant
League Participant
Posts: 298
Joined: Sun Nov 18, 2012 1:09 pm


alright Blue_Happy3
colorpinpoint
League Champs
League Champs
Posts: 60
Joined: Tue Nov 06, 2012 11:06 pm


thepolm3 wrote:
babel is my own version. You can change things like that in the script
I will fix the other errors you specefied
EDIT FIXED
Still doesn't work. http://youtu.be/IcRFAX3ActQ
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


Thats working fine?
There is no problem there.
ALSO updated
colorpinpoint
League Champs
League Champs
Posts: 60
Joined: Tue Nov 06, 2012 11:06 pm


thepolm3 wrote:
Thats working fine?
There is no problem there.
ALSO updated
The game mode is supposed to be push, not ctf.
44 posts Page 1 of 3 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 0 guests