[SCRIPT] matchmode

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


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
Attachments
matchmode.py
(1.65 KiB) Downloaded 206 times
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


Updated for mixed 1.4
danhezee
Former Admin / Co-founder
Former Admin / Co-founder
Posts: 1710
Joined: Wed Oct 03, 2012 12:09 am


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


It will work with intelimap, but not intelimode
Lostmotel
League Participant
League Participant
Posts: 298
Joined: Sun Nov 18, 2012 1:09 pm


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.
5 posts Page 1 of 1 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 38 guests