View Single Post
Author Message
StrikerMan780
AlliedModders Donor
Join Date: Jul 2009
Location: Canada
Old 12-01-2009 , 17:22   [REQ] Port of ES Ragequit Plugin
Reply With Quote #1

I'm trying to cut down on the number of Server Plugins installed to my Dedicated server, and trying to drop using Matties Eventscripts completely, due to instability. So far, I've dropped Mani Admin Plugin, and things work a little better. But, I haven't dropped ES yet, as there are some eventscripts that I just can't live without. The ES Ragequit plugin is one of them, and one of the only ragequit plugins that work with every game.

The ones I searched on sourcemod.net, only work with TF2 or Left 4 Dead... Not what I need. I need something that will work with anything, like HL2DM.

The plugin checks for time between death, and conditions of quitting. If a person quits within a certain amount of time, it plays the sound "R-R-R-R-Ragequit!" The only CVar for this is ragequit_max_delay. Defaults to 10. This basically sets the amount of time between dying, and quitting to have it register as a ragequit. Oh, btw, timeouts and crashes do not count as ragequits in this plugin at all.

Here is the code of the plugin, if anyone is interested: Credit goes to ojii, the original creator of the plugin.
Code:
#===============================================================================
# Config Start
#===============================================================================

ragequit_max_delay = 10.0 # this is a server var now!

#===============================================================================
# Config End
#===============================================================================

__version__ = '1.3'

import es
import gamethread
import time

debug = lambda x: es.dbgmsg(1, '[RQ] %s' % x)

max_delay = es.ServerVar('ragequit_max_delay',
                         ragequit_max_delay,
                         "Amount of seconds between death and disconnect.")

es.ServerVar('ragequit_ver', __version__).makepublic()

class RageQueue(dict):
    """
    A self-emptying dictionary :D
    """
    def __setitem__(self, victim, killer):
        debug('setting item %s in RageQueue' % victim)
        if dict.__contains__(self, victim):
            gamethread.cancelDelayed('ragequit_%s' % victim)
        else:
            dict.__setitem__(self, victim, killer)
        gamethread.delayedname(float(max_delay),
                               'ragequit_%s' % victim,
                               self.__delitem__,
                               (victim,))
                               
    def __delitem__(self, item):
        debug('deleting item %s from RageQueue' % item)
        if dict.__contains__(self, item):
            dict.__delitem__(self, item)
rage_queue = RageQueue()

names = {}

def load():
    """
    w00t we get loaded! 
    """
    es.loadevents('declare', 'addons/eventscripts/ragequit/events.res')
    downloadables()
    debug("loaded (v %s)" % __version__)
    
def es_map_start(ev):
    """
    New map! Let's hope this gonna be fun!
    """
    es.loadevents('declare', 'addons/eventscripts/ragequit/events.res')
    downloadables()
    
def downloadables():
    """
    Add downloadables
    """
    debug("added sound/ragequit/ragequit.mp3 to downloadables")
    es.stringtable('downloadables', 'sound/ragequit/ragequit.mp3')

def player_connect(ev):
    """
    A new player connected! Let's remember their names!
    """
    names[ev['userid']] = ev['name']
    
def player_changename(ev):
    """
    A player changed their name! Let's not forget it!
    """
    names[ev['userid']] = ev['newname']

def player_death(ev):
    """
    Oh no! Looks like this poor little guy died! Let's hope he stays calm and
    doesn't rush out of here in rage!
    """
    debug('a player died: %s' % ev['userid'])
    rage_queue[ev['userid']] = [('string', 'victimsteamid', ev['es_steamid']),
                                ('string', 'attackersteamid', ev['es_attackersteamid']),
                                ('int', 'attackeruserid', ev['attacker']),
                                ('string', 'weapon', ev['weapon']),
                                ('int', 'headshot', ev['headshot']),
                                ('float', 'timestamp', time.time())]
    
def player_disconnect(ev):
    """
    Hmm, looks like someone doesn't want to play anymore... Let's find out why!
    """
    debug('a player disconnected: %s' % ev['userid'])
    if ev['userid'] in rage_queue:
        debug('player in rage queue')
        if ev['reason'].lower().startswith('disconnect by user'):
            debug('disconnect by user')
            info = rage_queue[ev['userid']]
            del rage_queue[ev['userid']]
            ragequit(names[ev['userid']], info)
        else:
            debug('ragequit, but not by user')
    else:
        debug('player left calmly')
        
def ragequit(name, info):
    """
    Some people just can't stay calm... That guy just left in rage!
    """
    debug('ragequit')
    users = es.getUseridList()
    if users:
        debug(" %s has left in rage" % name)
        es.msg('#multi', '#lightgreen%s#default has left in #lightgreenrage!' % name)
        es.emitsound('player', users[0], 'ragequit/ragequit.mp3', 1.0, 0.0)
    else:
        debug("%s has left in rage, but there's noone here to care about it." % name)
    # fire event, we fire the event in any case, for addons which wanna track it
    debug('firing event')
    es.event('initialize', 'ragequit')
    for evtype, key, value in info:
        es.event('set%s' % evtype, 'ragequit', key, value)
    es.event('fire', 'ragequit')
I can understand what the code does by reading it, but I just simply do not have the skill or knowledge to create sourcemod plugins. Goes right over my head, and I'm always short on time, so I hadn't got the chance yet to learn sourcemod coding. The extent of my scripting knowledge is limited to making scripts for a far simpler game. (Skulltag/ZDoom).

Last edited by StrikerMan780; 12-04-2009 at 20:44.
StrikerMan780 is offline