Author Topic: Python script help needed.  (Read 13937 times)

mRokita

  • Autococker
  • Posts: 598
Re: Python script help needed.
« Reply #20 on: October 08, 2016, 04:25:14 PM »
hTml's script doesnt work when you use "set timestamp_date 1", because the RegEx doesnt fit then.

Just saw it in a quick lookup.
Ye, there was no timestamp_date cvar when i was writing this thing

mRokita

  • Autococker
  • Posts: 598
Re: Python script help needed.
« Reply #21 on: April 02, 2018, 01:40:17 PM »
The old script is now deprecated, use the new DPLib

install it using PIP:

python3 -m pip install --upgrade DPLib

Code: [Select]
from asyncio import sleep

from dplib.server import Server

s = Server(hostname='127.0.0.1', port=27911, logfile=r'C:\Games\Paintball2\pball\qconsole27911.log', rcon_password='hello')

map_settings = {
    'airtime': {
        'command': 'set elim 10;set timelimit 10;',
        'message': '{C}9Special settings for airtime {C}Aenabled'
    },
    'shazam33': {
        'command': 'set elim 10;set timelimit 10;',
        'message': '{C}9Special settings for shazam33 {C}Aenabled'
    },
    'default_settings': {
        'command': 'set elim 20;set timelimit 20;',
        'message': '{C}9No special settings for map {I}<mapname>{I}, using defaults'
    }
}

@s.event
def on_mapchange(mapname):
    if mapname not in map_settings:
        settings = map_settings['default_settings']
    else:
        settings = map_settings[mapname]
    command = settings.get('command', None)
    message = settings.get('message', None)
    if message:
        message = mapname.join(message.split('<mapname>'))
    if command:
        for c in command.split(';'):
            s.rcon(c)
    if message:
        yield from sleep(3)
        s.say(message)

s.run()
https://mrokita.github.io/DPLib/gettingstarted.html#map-settings