Scripts:OfftimePy

From BF2 Technical Information Wiki
Revision as of 15:32, 22 June 2018 by Pireax (talk | contribs) (Created page with "__TOC__ == What It Does == Allows you to have specific settings for when the number of players is below or equal to and above <code>sv.numPlayersNeededToStart</code>. For in...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

What It Does

Allows you to have specific settings for when the number of players is below or equal to and above sv.numPlayersNeededToStart. For instance you can turn friendly-fire off and have instant spawn time when there aren't enough players to start a game.

Installation

  1. Browse to admin/standard_admin in your bf2 server directory
  2. Edit __init__.py so it looks something like the code snippet below.
  3. Save the below code to admin/standard_admin/offtime.py.
  4. Make sure RCON is configured, then run your server. If "offtime.py loaded" comes up in your server console it should work from there.

Usage

Edit the two dictionaries and add the settings you'd like each for each game state. The keys should be strings that represent sv settings and the values should be strings.

Code

__init__.py

import offtime

offtime.init()


offtime.py

# offtime.py - allows different settings for both
# sv.numPlayersNeededToStart-related game states
# -- by dackz (http://dackz.net/)
import bf2
import host
from bf2 import g_debug

# change these to reflect the settings you want
settingsNotStarted = {
    'sv.soldierFriendlyFire': '0',
    'sv.soldierSplashFriendlyFire': '0',
    'sv.vehicleFriendlyFire': '0',
    'sv.vehicleSplashFriendlyFire': '0',
    'sv.spawnTime': '0',
    'sv.manDownTime': '0',
}

settingsStarted = {
    'sv.soldierFriendlyFire': '25',
    'sv.soldierSplashFriendlyFire': '25',
    'sv.vehicleFriendlyFire': '25',
    'sv.vehicleSplashFriendlyFire': '25',
    'sv.spawnTime': '13',
    'sv.manDownTime': '13',
}

def init():
    if g_debug: print 'initialising offtime script'

    host.registerGameStatusHandler(onGameStatusChanged)

    host.rcon_invoke('echo "offtime.py loaded"')

def onGameStatusChanged(status):
    if status == bf2.GameStatus.Playing:
        if bf2.playerManager.getNumberOfPlayers() < int(host.rcon_invoke('sv.numPlayersNeededToStart')):
            host.rcon_invoke('echo "offtime.py: setting offtime setings"')
            dictionary = settingsNotStarted
        else:
            host.rcon_invoke('echo "offtime.py: setting normal settings"')
            dictionary = settingsStarted

        for (setting, value) in dictionary.iteritems():
            host.rcon_invoke('%s %s' % (setting, value))