It appears you have not registered with our community. To register please click here ...
__version__ = '1.0'__author__ = 'Bakes'import b3, reimport b3.eventsimport threadingimport randomimport time#--------------------------------------------------------------------------------------------------class RtvPlugin(b3.plugin.Plugin): _adminPlugin = None _voteActive = False _voteLastActive = None activeclients = {} voteallowed = True maps = [] randomizedmaps = {} votedclients = {} def onStartup(self): self.registerEvent(b3.events.EVT_CLIENT_SAY) self.registerEvent(b3.events.EVT_GAME_ROUND_START) """\ Initialize plugin settings """ file = open(self.config.get('settings', 'maplist'), 'r') for line in file: self.maps.append(line) # get the admin plugin so we can register commands self._adminPlugin = self.console.getPlugin('admin') if not self._adminPlugin: # something is wrong, can't start without admin plugin self.error('Could not find admin plugin') return False self.debug('Started') def onEvent(self, event): if event.type == b3.events.EVT_CLIENT_SAY: self.debug(self._adminPlugin.parseUserCmd(event.data)[0]) if self._adminPlugin.parseUserCmd(event.data)[0].startswith('rtv'): if event.client.maxLevel > self.config.getint('settings', 'minlevel'): if self.voteallowed: try: failed = True self.debug('failed set to false') if not self.activeclients[event.client.id]: self.debug('This was not meant to happen') except KeyError: self.debug('failed set to true') failed = False if failed == False: self.debug('Rocking the Vote?') self.rockthevote(event.client, event.data) else: event.client.message('You have already voted') return False else: event.client.message('You do not have permission to use rockthevote') elif event.type == b3.events.EVT_GAME_ROUND_START: self.debug('Round Started') def allowvote(self): self.voteallowed = True def rockthevote(self, client, data): if not self._voteActive: self.activeclients[client.id] = True if (float(len(self.activeclients))/float(len(self.console.clients.getList()))) > float(self.config.getint('settings', 'rtv_threshold_percent')/100): self.console.say('The vote is being rocked!') self.activeclients = {} self.randomizedmaps = {} random.shuffle(self.maps) i = 0 for map in self.maps: map = map.strip() if i > 4: break else: self.randomizedmaps[map] = 0 i = i + 1 self.console.say('Vote for a new map! The choices are:') for map in self.randomizedmaps: self.console.say('^1'+map) self._voteActive = True timer = threading.Timer(self.config.getint('settings', 'time_to_vote'), self.activatemap) timer.start() self.console.say('Please type ^1rtv ^2mapname ^7to vote for a new map! You have %s seconds' % self.config.get('settings', 'time_to_vote')) else: self.activeclients[client.id] = True mapname = self._adminPlugin.parseUserCmd(data)[1] if not mapname: client.message('You must specify a mapname when voting!') else: try: self.debug(mapname) if self.randomizedmaps[mapname]: self.debug('Client entered an acceptable map') except KeyError: #else: string = '' client.message('You must select a valid map, the options are:') for map in self.randomizedmaps: string = string+map+', ' client.message(string) return False self.randomizedmaps[mapname] = self.randomizedmaps[mapname] + 1 client.message('Your vote was ^2successful') def activatemap(self): self.debug('map activating') best = 0 bestmap = None for map in self.randomizedmaps: if self.randomizedmaps[map] > best: best = self.randomizedmaps[map] bestmap = map self._voteActive = False self.activeclients = {} if best > 0: self.console.say('New map has been selected! Rotating to %s' % bestmap) time.sleep(3) self.console.write('map %s' % bestmap) self.debug('Map Change, so setting vote allowed false until map has been played for a bit') self.voteallowed = False t = threading.Timer(self.config.getint('settings','time_before_rtv'), self.allowvote) t.start() else: self.console.say('Noone voted!') self._voteActive = False
b3/extplugins/conf/maplist.txt 15 15 1 50
if s is map:
if s == map: