Page 1 of 1

[SCRIPT] matchmode

Posted: Sun Jul 21, 2013 5:38 pm
by thepolm3
This script matches the mode of the game depending upon the map extensions.
SOOO an arena map with arena:True in its map extensions will set the gamemode automatically to arena.
If it detects multiple game modes (e.g arena:True, koth:True, onectf:True) It will randomly choose between the modes
You can set a definite mode by putting "game_mode":"arena" in order to ovveride or for new scripts
Now enough dilly dallying; Here is the code
Code: Select all
"""
switches to arena for an arena map, for example
thepolm3
"""
from random import randint

def get_map_extensions(map):
    extensions = {}
    try:
        f = open("maps/"+str(map)+".txt")
        exec(f.read())
        f.close()
    except Exception, e:
        print(e)
    return extensions

def apply_script(protocol,connection,config):

        class MatchModeProtocol(protocol):
            oldmode = None

            def on_mode_advance(self,mode,map):
                extensions = get_map_extensions(map)
                if extensions:
                    game_modes = config.get("game_modes",[])
                    modes = []
                    for extension in extensions:
                        if extension.lower() == "game_mode":
                            if type(extensions[extension])==list:
                                modes = extensions[extension]
                            else:
                                return extensions["game_mode"]
                        elif extension.lower() in game_modes:
                            if extensions[extension.lower()]:
                                modes.append(extension)
                    if modes:
                        return modes[randint(0,len(modes)-1)]
                if "on_mode_advance" in dir(protocol):
                    returned = protocol.on_mode_advance(self,mode,map)
                    if returned:
                        return returned
                if self.oldmode:
                    returned = self.oldmode
                    self.oldmode = None
                    return returned
        return MatchModeProtocol,connection

Re: [SCRIPT] matchmode

Posted: Mon Jul 22, 2013 9:49 pm
by thepolm3
Updated for mixed 1.4

Re: [SCRIPT] matchmode

Posted: Sun Sep 08, 2013 3:35 pm
by danhezee
Will this work with intelimap or intelimode? I want to set up a mixed.py server that runs certain gamemodes based off map extensions only if there are enough players.

Re: [SCRIPT] matchmode

Posted: Sun Sep 08, 2013 8:11 pm
by thepolm3
It will work with intelimap, but not intelimode

Re: [SCRIPT] matchmode

Posted: Tue Oct 01, 2013 4:02 pm
by Lostmotel
There appears to be a problem with either this script or mixed.py. Servers with both scripts worked fine on my localhost pyspades server. But there is an error on a pysnip VPS which causes the scripts to stop working properly (the server switches between 2 gamemodes without checking the map extension file).
The error appears as a single line when the server gets started: invalid syntax (<string>, line 1)

Edit: The problem seems to be restricted to pysnip servers which have been compiled from source.