Page 1 of 2

[SCRIPT] Intelimap 1.2

Posted: Tue May 28, 2013 12:38 pm
by thepolm3
Welcome to intelimap!
This is
TB_ wrote:
a script that changes the map based on how many players who are online
Idea by TB_: More info HERE
script:
Code: Select all
"""
thepolm3
idea @ TB_
"""

from twisted.internet.task import LoopingCall
from map import check_rotation
from commands import add
from random import randint

def intelimap(connection):
    connection.protocol.overruled=not connection.protocol.ovveruled
    return ("intelimap is" + ["ON","OFF"][connection.protocol.ovveruled] + "This round")

add(intelimap)
threshold=[]
def apply_script(protocol, connection, config):
    class MapProtocol(protocol):
        overruled=False
        
        def check_next_map(self):
            if not self.overruled:
                nop=len(self.players)
                for i in range(len(threshold)-1):
                    if threshold[i] == threshold[i+1]:
                        for a in range(i,len(threshold)-1):
                            if threshold[a] != threshold[i]:
                                break
                        if threshold[a-1]<= nop < threshold[a]:
                            mapindex=randint(i,a-1)
                            break
                        else:
                            i=a
                    elif threshold[i] <= nop < threshold[i+1]:
                        mapindex=i
                        break
                else:
                    mapindex=len(threshold)-1
                self.planned_map=check_rotation([self.get_map_rotation()[mapindex]])[0]

        def on_command(self,command,sender):
            if command=="map" and sender.admin:
                self.overruled=True
            protocol.on_command(self,command,sender)

        def on_map_change(self,map):
            global threshold
            self.overruled=False
            threshold=config.get("map_threshold",[])
            if threshold==[]:
                nop=self.max_players
                rot=self.get_map_rotation()
                step=nop/len(rot)
                for i in range(len(rot)):
                    threshold.append(i*step)
            checking=LoopingCall(self.check_next_map)
            checking.start(1)
            protocol.on_map_change(self,map)

    return MapProtocol, connection

To set up a custom rotation put the line "map_threshold" in config.txt
Code: Select all
    "maps" : ["hallway","platform","skullisland","pinpoint","classicgen","random","hallway"],
    "map_threshold" : [0,0,0,4,8,12,16],
so if these were in your config, when the map advances with 14 players it is random, with 3 it is a random [hallway, platform, skullisland], with 17 it is hallway and with 9 it is classicgen

Edit: Made the random feature a reality!
Edit: Fixed the reality!

Re: [script] Intelimap

Posted: Tue May 28, 2013 1:26 pm
by danhezee
Looking forward to testing this.

Re: [script] Intelimap

Posted: Tue May 28, 2013 2:11 pm
by TB_
Oh my god, I just came back from school. I thought this would take a few days. o.o
Is it possible to have several maps per "step"? Like when it reaches the level where its 12 players, it'll randomly choose between several maps like the stash, rocket island, standoff etc.. ?

And btw, what happens when a mod forces map change to a certain map? This script is best for when the mods aren't constantly watching over the server. So maybe a simple command to enable and disable it would be a good idea? So they can enable it when they aren't watching over the server, and disable it whe nthey are. Blue_Happy1

Re: [script] Intelimap

Posted: Tue May 28, 2013 2:51 pm
by thepolm3
the thing about the random thing is that it uses the existing map rotation in config for simplicity. If you want a pseudo-random one put your intervals close together. E.g [hallway,pinpoint,eggmap],[0,1,2]
enable/disable added ;)

Re: [SCRIPT] Intelimap

Posted: Sun Jun 02, 2013 2:06 pm
by Ninja_pig_pro
Okay what we need is a server that uses thepolm3's scripts.

Re: [SCRIPT] Intelimap

Posted: Sun Jun 02, 2013 2:30 pm
by thepolm3
Icecraft ftw

Re: [SCRIPT] Intelimap

Posted: Sun Jun 02, 2013 4:42 pm
by IceCream
thepolm3 wrote:
Icecraft ftw
thepolm3 ftw :3

Re: [SCRIPT] Intelimap

Posted: Sun Jun 02, 2013 7:44 pm
by TB_
hey thepolm, what is the timer set to?
Like, when it hits 8 players, how long does it have to hae 8 players before it changes to classicgen?

Re: [SCRIPT] Intelimap

Posted: Sun Jun 02, 2013 7:48 pm
by thepolm3
ah, you misunderstand. The way it works is to set the NEXT map based on the number of players, so either when the intel cap is reached or when the timer runs out. YOu understand that the map would just be too complex if it was fixed when a certain number of players join

Re: [SCRIPT] Intelimap

Posted: Mon Jun 03, 2013 2:37 am
by colorpinpoint
Line 13 had a syntax error. Supposed to be:

return ("intelimap is ['ON', 'OFF'][connection.protocol.ovveruled] This round")

instead of:
return ("intelimap is" ["ON","OFF"][connection.protocol.ovveruled] "This round")

Re: [SCRIPT] Intelimap

Posted: Mon Jun 03, 2013 7:24 am
by thepolm3
sorry, but actually it should be
return ("intelimap is" + ["ON","OFF"][connection.protocol.ovveruled] + "This round")
sorry to correct your correction, and thanks for drawing my attention to it

Re: [script] Intelimap

Posted: Tue Jun 04, 2013 4:10 pm
by Kamikaze_Blargle
thepolm3 wrote:
the thing about the random thing is that it uses the existing map rotation in config for simplicity. If you want a pseudo-random one put your intervals close together. E.g [hallway,pinpoint,eggmap],[0,1,2]
Wouldn't you be able to put:
Code: Select all
    "maps" : ["pinpoint", "hallway", "classicgen", "random", "hallway"],
    "map_threshold" : [0,1,1,2,2] 
Where if the playercount is 1, it would choose either hallway or classicgen...
or if it was 2, it would choose either random or hallway.
Would this work? :/

Re: [SCRIPT] Intelimap

Posted: Tue Jun 04, 2013 4:31 pm
by thepolm3
that, my friend, will be an implementation

Re: [SCRIPT] Intelimap

Posted: Tue Jun 04, 2013 4:39 pm
by Kamikaze_Blargle
kk then, im a little new to scripting <3

Re: [SCRIPT] Intelimap

Posted: Tue Jun 04, 2013 5:05 pm
by thepolm3
Kamikaze_Blargle wrote:
kk then, im a little new to scripting <3
Here we go! Now everyone's happy!