def onPlayerChangeTeams(p, humanHasSpawned):
	
	if not bf2.serverSettings.getAutoBalanceTeam(): return

	# dont teamswitch alive players, or they will have the wrong teams kit 
	if p.isAlive(): return
	
	if host.sgl_getIsAIGame() and not (host.ss_getParam('gameMode') == "gpm_coop"):
		if humanHasSpawned: return
		if p.isAIPlayer(): return
			
		# handling aiplayer team change autobalance when round not started
		team = p.getTeam()	
		aiplayer = 0	
	
		for tp in bf2.playerManager.getPlayers():		
			if aiplayer == 0 and tp.getTeam() == team and tp.isAIPlayer(): 
				aiplayer = tp
				break
		
		if aiplayer: 
			if p.getTeam() == 1: aiplayer.setTeam(2)
			else: aiplayer.setTeam(1)
									
	else:
		# checking to see if player is allowed to change teams
		team1 = 0
		team2 = 0
		for tp in bf2.playerManager.getPlayers():	
			if tp.getTeam() == 1: team1 += 1
			else: team2 += 1
		if abs(team1 - team2) > 1:
			if p.getTeam() == 1: p.setTeam(2)
			else: p.setTeam(1)
def onPlayerChangeTeams(p, humanHasSpawned):

    if not bf2.serverSettings.getAutoBalanceTeam(): return

    # dont teamswitch alive players, or they will have the wrong teams kit
    if p.isAlive(): return

    if host.sgl_getIsAIGame() and not (host.ss_getParam('gameMode')
                                       == "gpm_coop"):
        if humanHasSpawned: return
        if p.isAIPlayer(): return

        # handling aiplayer team change autobalance when round not started
        team = p.getTeam()
        aiplayer = 0

        for tp in bf2.playerManager.getPlayers():
            if aiplayer == 0 and tp.getTeam() == team and tp.isAIPlayer():
                aiplayer = tp
                break

        if aiplayer:
            if p.getTeam() == 1: aiplayer.setTeam(2)
            else: aiplayer.setTeam(1)

    else:
        # checking to see if player is allowed to change teams
        team1 = 0
        team2 = 0
        for tp in bf2.playerManager.getPlayers():
            if tp.getTeam() == 1: team1 += 1
            else: team2 += 1
        if abs(team1 - team2) > 1:
            if p.getTeam() == 1: p.setTeam(2)
            else: p.setTeam(1)
Beispiel #3
0
def init():
	# events hook
	try:
		host.registerGameStatusHandler(onGameStatusChanged)
		if host.sgl_getIsAIGame() == 1:
			host.sh_setEnableCommander(0)
		else:
			host.sh_setEnableCommander(1)

		if g_debug: print "gpm_sl.py initialized"
	except Error, e:
		print "init faield "+ str(e)
Beispiel #4
0
def init():
    # events hook
    host.registerGameStatusHandler(onGameStatusChanged)
    if host.sgl_getIsAIGame() == 1:
        host.sh_setEnableCommander(1)
    else:
        host.sh_setEnableCommander(1)

    host.registerHandler("TimeLimitReached", onTimeLimitReached, 1)

    if g_debug:
        print "gpm_cq.py initialized"
Beispiel #5
0
def init():
    # events hook
    global g_plugin
    host.registerGameStatusHandler(onGameStatusChanged)
    if host.sgl_getIsAIGame() == 1:
        host.sh_setEnableCommander(1)
    else:
        host.sh_setEnableCommander(1)
        
    host.registerHandler('TimeLimitReached', onTimeLimitReached, 1)
    
    if g_debug: print "gpm_cq.py initialized"
    g_plugin = game.gameplayPlugin.pluginsystem()
Beispiel #6
0
    def onPlayerChangeTeams(self, p, humanHasSpawned):
        """Ensure the player isnt unbalancing the teams."""
        if 1 != self.__state:
            return

        self.mm.debug(2, "AB: change")

        if not bf2.serverSettings.getAutoBalanceTeam():
            return

        # dont teamswitch alive players, or they will have the wrong teams kit
        if p.isAlive():
            return

        if host.sgl_getIsAIGame() and (
                self.mm.isBattleField2142()
                or not (host.ss_getParam('gameMode') == "gpm_coop")):
            if humanHasSpawned or p.isAIPlayer():
                return

            # handling aiplayer team change autobalance when round not started
            team = p.getTeam()
            aiplayer = 0

            for tp in bf2.playerManager.getPlayers():
                if aiplayer == 0 and tp.getTeam() == team and tp.isAIPlayer():
                    aiplayer = tp
                    break

            if aiplayer:
                if p.getTeam() == 1:
                    aiplayer.setTeam(2)
                else:
                    aiplayer.setTeam(1)

        else:
            # checking to see if player is allowed to change teams

            team1 = 0
            team2 = 0
            for tp in bf2.playerManager.getPlayers():
                if tp.getTeam() == 1:
                    team1 += 1
                else:
                    team2 += 1

            if abs(team1 - team2) > 1:
                if p.getTeam() == 1:
                    p.setTeam(2)
                else:
                    p.setTeam(1)
Beispiel #7
0
def init():
    # events hook
    global g_plugin
    host.registerGameStatusHandler(onGameStatusChanged)
    if host.sgl_getIsAIGame() == 1:
        host.sh_setEnableCommander(1)
    else:
        host.sh_setEnableCommander(1)
        
    host.registerHandler('TimeLimitReached', onTimeLimitReached, 1)
    
    # Reset ticket loss values
    game.gameplayPlugin.setDefaultTicketLossPerMin(1, game.gameplayPlugin.DEFAULT_TICKET_LOSS_PER_MIN)
    game.gameplayPlugin.setDefaultTicketLossPerMin(2, game.gameplayPlugin.DEFAULT_TICKET_LOSS_PER_MIN)
    
    if g_debug: print "gpm_cq.py initialized"
    g_plugin = game.gameplayPlugin.pluginsystem()
Beispiel #8
0
    def round_start(self, hooker):
        if host.sgl_getIsAIGame():
            return
    
        # register events
        hooker.register('PlayerKilled', self.onPlayerKilled)
        hooker.register('PlayerDeath', self.onPlayerDeath)
        hooker.register('EnterVehicle', self.onEnterVehicle)
        hooker.register('ExitVehicle', self.onExitVehicle)
        hooker.register('PickupKit', self.onPickupKit)
        hooker.register('DropKit', self.onDropKit)
        hooker.register('ControlPointChangedOwner', self.onCPStatusChange)
        hooker.register('PlayerScore', self.onPlayerScore)
        hooker.register('PlayerSpawn', self.onPlayerSpawn)
        hooker.register('PlayerConnect', self.onPlayerConnect)

        currentDate = datetime.datetime.today()
        dateString = ""
        dateString = time.strftime("%y%m%d_%H%M", currentDate.timetuple())

        if dateString != "":
            fileName = bf2.gameLogic.getModDir() + "/logs/" + bf2.gameLogic.getMapName() + "_" + dateString + "_faLog.txt"
        else:
            fileName = bf2.gameLogic.getModDir() + "/logs/" + bf2.gameLogic.getMapName() + "_faLog.txt"

        print "log file: ", fileName

        try:
            self.logfile = file (fileName, 'w')
        except Exception:
            print "Couldnt open fragalyzer self.logfile: ", fileName
            return

        self.startTime = int(self.date())
        timeString = str(self.startTime)
        startDate = time.strftime("%Y.%m.%d,%H:%M", currentDate.timetuple())
        if self.logfile: self.logfile.write("INIT LevelName=" + bf2.gameLogic.getMapName() + " self.startTime=" + timeString + " StartDate=" + startDate + " Filename=" + fileName + "\n")

        if self.logfile: self.logfile.flush()
        print "Fragalyzer logging enabled."

        # Connect already connected players if reinitializing
        for p in bf2.playerManager.getPlayers():
            self.onPlayerConnect(p)
def onPlayerDeath(p, vehicle):

    if not bf2.serverSettings.getAutoBalanceTeam(): return

    if p.isSquadLeader(): return
    if p.isCommander(): return

    if (host.ss_getParam('gameMode') == "gpm_coop") and p.isAIPlayer():
        return

    # dont use autobalance when its suicide/changes team
    if p.getSuicide():
        p.setSuicide(0)
        return

    aiPlayerBalance = 0
    team1 = 0
    team2 = 0
    for tp in bf2.playerManager.getPlayers():
        if tp.getTeam() == 1:
            team1 += 1
        else:
            team2 += 1
        if tp.isAIPlayer():
            aiPlayerBalance += 1
        else:
            aiPlayerBalance -= 1

    if host.sgl_getIsAIGame():
        if not (host.ss_getParam('gameMode') == "gpm_coop"):
            if not (aiPlayerBalance < 0):
                if not p.isAIPlayer():
                    return

    team2 = team2 * bf2.serverSettings.getTeamRatioPercent() / 100.0

    if (p.getTeam() == 1):
        if (team2 + 1) < team1:
            p.setTeam(2)
    elif (p.getTeam() == 2):
        if (team1 + 1) < team2:
            p.setTeam(1)
def onPlayerDeath(p, vehicle):		
	
	if not bf2.serverSettings.getAutoBalanceTeam(): return
	
	if p.isSquadLeader(): return		
	if p.isCommander(): return	
	
	if (host.ss_getParam('gameMode') == "gpm_coop") and p.isAIPlayer():
		return
	
	# dont use autobalance when its suicide/changes team
	if p.getSuicide(): 
		p.setSuicide(0)
		return
	
	aiPlayerBalance = 0
	team1 = 0
	team2 = 0
	for tp in bf2.playerManager.getPlayers():	
		if tp.getTeam() == 1:
			team1 += 1
		else:
			team2 += 1
		if tp.isAIPlayer():
			aiPlayerBalance += 1
		else:
			aiPlayerBalance -= 1					
	
	if host.sgl_getIsAIGame():
		if not (host.ss_getParam('gameMode') == "gpm_coop"):
			if not (aiPlayerBalance < 0):		
				if not p.isAIPlayer():
					return
	
	team2 = team2 * bf2.serverSettings.getTeamRatioPercent() / 100.0

	if (p.getTeam() == 1):
		if (team2+1) < team1:
			p.setTeam(2)			
	elif (p.getTeam() == 2):
		if (team1+1) < team2:
			p.setTeam(1)			
Beispiel #11
0
    def maplistLogic(self, playerConnected=False):
        playerCount = 0

        if host.sgl_getIsAIGame():
            for player in bf2.playerManager.getPlayers():
                if not player.isAIPlayer():
                    playerCount += 1
        else:
            playerCount = bf2.playerManager.getNumberOfPlayers()

        if not playerConnected:
            playerCount -= 1

        for treshhold in self.__maplists.keys():
            if playerCount >= treshhold:
                self.__nextMapList = treshhold

        if self.__currentMapList != self.__nextMapList:
            if self.__lastAnnouncedMapList != self.__nextMapList:
                mm_utils.msg_server("New maplist set: " +
                                    self.__maplists[self.__nextMapList])
                self.__lastAnnouncedMapList = self.__nextMapList

            if self.__force:
                if self.__shuffle:
                    maps = readMaps(self.__maplistPath +
                                    self.__maplists[self.__nextMapList])
                    maps = shuffleMaps(
                        maps, "gpm_ti")  # TODO: Create modmanager setting
                    loadMaps(maps)
                else:
                    host.rcon_invoke("maplist.configFile " +
                                     self.__maplistPath +
                                     self.__maplists[self.__nextMapList])
                    host.rcon_invoke("maplist.load")
                host.rcon_invoke("admin.runNextLevel")
                self.__currentMapList = self.__nextMapList
Beispiel #12
0
 def isAIGame(self):
     return host.sgl_getIsAIGame()
Beispiel #13
0
 def bf2_init(self, hooker):
     if host.sgl_getIsAIGame() != 1:
         print 'aiFixups: not an ai game, doing nothing'
         return
     self.go()
Beispiel #14
0
	def isAIGame(self): return host.sgl_getIsAIGame()

	def sendClientCommand(self, playerId, command, args): return host.sgl_sendPythonEvent(playerId, command, args)
Beispiel #15
0
 def isAIGame(self):
     return host.sgl_getIsAIGame()
Beispiel #16
0
	def isAIGame(self): return host.sgl_getIsAIGame()
	def getOverlayDir(self): return host.sgl_getOverlayDirectory()
Beispiel #17
0
    def onPlayerDeath(self, p, vehicle):
        """Autobalance a player that has died if required and allowed by the balance rules."""
        if 1 != self.__state:
            return

        if p == None:
            return

        if self.mm.isBattleField2142():
            # bf2142 specific
            if not p.isValid() or p.isAutoController():
                return
        else:
            # bf2 specific
            if (host.ss_getParam('gameMode') == "gpm_coop") and p.isAIPlayer():
                return

        if not bf2.serverSettings.getAutoBalanceTeam():
            return

        # dont use autobalance when its suicide/changes team
        if p.getSuicide():
            p.setSuicide(0)
            return

        if (not self.__config['allowCommander']) and p.isCommander():
            # dont autobalance the commander
            return

        squadid = p.getSquadId()
        teamid = p.getTeam()
        players = bf2.playerManager.getPlayers()

        if (not self.__config['allowSquadLeader']) and p.isSquadLeader():
            # only autobalance the squad leader if they are the only
            # member of that squad
            squad_members = 0
            for tp in players:
                if squadid == tp.getSquadId() and tp.index != p.index:
                    # we have other members in this squad dont autobalance
                    #self.mm.debug( 2, "AB: no ( squad leader with members )" )
                    return

        if (not self.__config['allowSquadMember']) and (squadid > 0):
            # only autobalance squad members if there are no none
            # squad members / commander on this team
            basic_players = 0
            for tp in players:
                if (0 == tp.getSquadId()) and (teamid == tp.getTeam()) and (
                        not p.isCommander()):
                    # none squad member / commander of this team
                    basic_players += 1

            if 0 != basic_players:
                # we have basic players in this team we
                # will balance them instead
                #self.mm.debug( 2, "AB: no ( basic players avail )" )
                return

        aiPlayerBalance = 0
        team1 = 0
        team2 = 0
        for tp in players:
            if tp.getTeam() == 1:
                team1 += 1
            else:
                team2 += 1

            if tp.isAIPlayer():
                aiPlayerBalance += 1
            else:
                aiPlayerBalance -= 1

        if host.sgl_getIsAIGame():
            if self.mm.isBattleField2142() or not (host.ss_getParam('gameMode')
                                                   == "gpm_coop"):
                if not (aiPlayerBalance < 0):
                    if not p.isAIPlayer():
                        return

        team2 = team2 * bf2.serverSettings.getTeamRatioPercent() / 100.0
        if (teamid == 1):
            if (team2 + 1) < team1:
                #self.mm.debug( 2, "AB: player '%s' -> team %d" % ( p.getName(), 2 ) )
                p.setTeam(2)
        elif (teamid == 2):
            if (team1 + 1) < team2:
                #self.mm.debug( 2, "AB: player '%s' -> team %d" % ( p.getName(), 1 ) )
                p.setTeam(1)
Beispiel #18
0
	def isAIGame(self): return host.sgl_getIsAIGame()
	def getOverlayDir(self): return host.sgl_getOverlayDirectory()