what is this script?

Discussion in 'BF2 Server Administration' started by exemaco, Apr 21, 2018.

  1. exemaco

    exemaco Member

  2. Wilson212

    Wilson212 Administrator Staff Member

    No clue
     
    exemaco likes this.
  3. exemaco

    exemaco Member

    NO COMMANDERS! Players: 1 < 11
     
  4. exemaco

    exemaco Member

    this script count the number of players on the server
     
  5. SharK

    SharK Member

    Script here...
    Code:
    # Commander Kill System
    
    # Module: comdis.py
    # Author: REW
    # Version: 1.0
    
    
    import bf2
    import host
    import mm_utils
    from bf2.stats.constants import *
    from bf2 import g_debug
    
    #debug flag
    sks_debug = False # for verbose server console messages
    
    #variable settings; intervals are in seconds
    minP = 10 # max players for 'no commanders' mode
    killInterval = 5 # time before a commander is killed
    msgInterval = 90 # time between warning messages
    
    #timers
    msgTimer = None
    
    #queue lists
    killList = []
    
    __version__ = 1.0
    
    __required_modules__ = {
      'modmanager': 1.2
    }
    
    __supports_reload__ = True
    
    __description__ = "ModManager Commander Killer v%s" % __version__
    
    class ComDis( object ):
    
      def __init__( self, modManager ):
      # ModManager reference
      self.mm = modManager
      self.__state = 0
       
      # Initialize the kill system i.e. register game hooks.
      def init( self ):
      if 0 == self.__state:
      host.registerHandler('PlayerSpawn', self.onPlayerSpawn, 1)
      #host.registerHandler('EnterVehicle', self.onEnterVehicle, 1)
      host.registerHandler('ChangedCommander', self.onChangedCommander, 1)
      host.registerGameStatusHandler(self.onGameStatusChanged)
      self.__state = 1
    
      def onChangedCommander(self, team, oldCmd, newCmd):
      self.CheckForCommander()
       
      # On spawn, checks if the player is a commander.
      # Player is added to kill list if player is a commander.
      def onPlayerSpawn(self, p, vehicle):
      self.CheckForCommander()
       
      # On enter vehicle, checks if the any player is a commander.
      # Player is added to kill list if player is a commander.
      def onEnterVehicle( self, p, vehicle, freeSoldier):
      self.CheckForCommander()
    
      def CheckForCommander( self ):
      global sks_debug
      global killList, killInterval, minP
      players = bf2.playerManager.getPlayers()
      numP = bf2.playerManager.getNumberOfPlayers()
      for pl in players:
      if pl.isCommander() and numP <= minP:
      # Add the player if not in kill list
      if killList.count(pl.index) == 0:
      killList.append(pl.index)
       
      # Set timer for kill
      bf2.Timer(self.onKillTimer, killInterval, 1)
       
      # Issue kill warning
      mm_utils.msg_server( "§3= SCRIPT: §C1001%s§C1001, §C1001NO COMMANDERS§C1001! You will §C1001DIE§C1001 in §C1001%s§C1001 sec! =" % ( pl.getName(), killInterval ))
    
       
      # Sends out warning messages
      def onMsgTimer(self, data):
      global sks_debug
      global minP
      numP = bf2.playerManager.getNumberOfPlayers()
      commander1 = bf2.playerManager.getCommander(1)
      commander2 = bf2.playerManager.getCommander(2)
      #if ((commander1 != None) or (commander2 != None)) and (numP <= minP):
      if (numP <= minP):
      mm_utils.msg_server( "= SCRIPT: §C1001NO COMMANDERS§C1001 or you will §C1001DIE§C1001! Players: §C1001%s§C1001<§C1001%s§C1001 =" % ( numP, minP+1 ) )
       
      # Processes the kill list queue. The next player in queue
      # is checked again and killed if a commander.
      def onKillTimer(self, data):
      global sks_debug
      global killList
      global minP
       
      # Process the next player in queue.
      p = bf2.playerManager.getPlayerByIndex(killList.pop(0))
      numP = bf2.playerManager.getNumberOfPlayers()
      # Player is still a commander, kill him.
      if p.isCommander() and p.isValid() and p.isAlive() and (numP <= minP):
      #host.rcon_invoke("admin.kickPlayer " + str(p.index))
      vehicle = p.getVehicle()
      rootVehicle = getRootParent(vehicle)
      if getVehicleType(rootVehicle.templateName) == VEHICLE_TYPE_SOLDIER:
      rootVehicle.setDamage(0)
      # This should kill them !
      else:
      rootVehicle.setDamage(0.01)
      # a vehicle will likely explode within 0.3 sec killing entire crew,
      # not so sure about base defenses though
      p.score.score = p.score.score - 5
      mm_utils.msg_server( "= SCRIPT: commander §C1001%s§C1001 was punished by \'Commander Killer\' script =" % ( p.getName() ) )
    
      # Handles clean up and initialization between rounds.
      def onGameStatusChanged(self, status):
      global killList
      global msgInterval, msgTimer
       
      if status == bf2.GameStatus.Playing:
       
      # Set the warning timer.
      msgTimer = bf2.Timer(self.onMsgTimer, msgInterval, 1)
      msgTimer.setRecurring(msgInterval)
       
      elif status == bf2.GameStatus.PreGame:
       
      # Destroy any timers
      msgTimer.destroy()
      msgTimer = None
       
      # Blank the list.
      killList = []
       
      elif status == bf2.GameStatus.EndGame:
      pass
    
    
      def shutdown( self ):
      """Shutdown and stop processing."""
       
      # Unregister our handlers
      host.unregisterGameStatusHandler( self.onGameStatusChanged )
       
      # Unregister our game handlers
      # Flag as shutdown as there is currently way to do this
      self.__state = 2
    
    def mm_load( modManager ):
      """Creates your object."""
      return ComDis( modManager )
    
     
    MrNiceGuy and exemaco like this.

Share This Page