Ratio 1.2 *Now With Headshot K/D*

Intended for use on live public servers.
10 posts Page 1 of 1
LinktersHD
Deuced Up
Posts: 124
Joined: Thu Nov 01, 2012 12:27 pm


Infogulch and I figured out how to add Headshot K/D within the ratio.py.
Basically it will tell you:
%s kills, %s deaths, %s headshot, %s melee, %s grenade
Anyway here is the download link to it:
https://dl.dropbox.com/u/87474659/Scripts/ratio.py
And here is the code:
Code: Select all
"""
K/D ratio script.

Author: LinktersHD, Infogulch, Yourself
Maintainer: mat^2
"""

from commands import get_player, add
from pyspades.constants import *

# True if you want to include the headshot-death ratio in the ratio
# NOTE: this makes the message overflow into two lines
HEADSHOT_RATIO = True

# "ratio" must be AFTER "votekick" in the config.txt script list
RATIO_ON_VOTEKICK = True
IRC_ONLY = False

def ratio(connection, user=None):
    msg = "You have"
    if user != None:
        connection = get_player(connection.protocol, user)
        msg = "%s has"
        if connection not in connection.protocol.players:
            raise KeyError()
        msg %= connection.name
    if connection not in connection.protocol.players:
        raise KeyError()
    
    kills = connection.ratio_kills
    deaths = float(max(1,connection.ratio_deaths))
    headshotkills = connection.ratio_headshotkills
    meleekills = connection.ratio_meleekills
    grenadekills = connection.ratio_grenadekills
    
    msg += " a kill-death ratio of %.2f" % (kills/deaths)
    if HEADSHOT_RATIO:
        msg += ", headshot-death ratio of %.2f" % (headshotkills/deaths)
    msg += " (%s kills, %s deaths, %s headshot, %s melee, %s grenade)." % (kills, connection.ratio_deaths, headshotkills, meleekills, grenadekills)
    return msg

add(ratio)

def apply_script(protocol, connection, config):
    class RatioConnection(connection):
        ratio_kills = 0
        ratio_headshotkills = 0
        ratio_meleekills = 0
        ratio_grenadekills = 0
        ratio_deaths = 0
        
        def on_kill(self, killer, type, grenade):
            if killer is not None and self.team is not killer.team:
                if self != killer:
                    killer.ratio_kills += 1
                    killer.ratio_headshotkills += type == HEADSHOT_KILL
                    killer.ratio_meleekills    += type == MELEE_KILL
                    killer.ratio_grenadekills  += type == GRENADE_KILL
            
            self.ratio_deaths += 1
            return connection.on_kill(self, killer, type, grenade)
    
    class RatioProtocol(protocol):
        def on_votekick_start(self, instigator, victim, reason):
            result = protocol.on_votekick_start(self, instigator, victim, reason)
            if result is None and RATIO_ON_VOTEKICK:
                message = ratio(instigator, victim.name)
                if IRC_ONLY:
                    self.irc_say('* ' + message)
                else:
                    self.send_chat(message, irc = True)
            return result
    
    return RatioProtocol, RatioConnection
Last edited by LinktersHD on Sat Dec 15, 2012 9:56 pm, edited 1 time in total.
MrHaaax
Modder
Modder
Posts: 1360
Joined: Sun Nov 25, 2012 2:58 am


LinktersHD wrote:
Infogulch and Me figured out how to add Headshot K/D within the ratio.py.
Basically it will tell you:
%s kills, %s deaths, %s headshot, %s melee, %s grenade
Anyway here is the download link to it:
https://dl.dropbox.com/u/87474659/Scripts/ratio.py
And here is the code:
Code: Select all
"""
K/D ratio script.

Author: LinktersHD, Infogulch, Yourself
Maintainer: mat^2
"""

from commands import get_player, add
from pyspades.constants import *

# True if you want to include the headshot-death ratio in the ratio
# NOTE: this makes the message overflow into two lines
HEADSHOT_RATIO = True

# "ratio" must be AFTER "votekick" in the config.txt script list
RATIO_ON_VOTEKICK = True
IRC_ONLY = False

def ratio(connection, user=None):
    msg = "You have"
    if user != None:
        connection = get_player(connection.protocol, user)
        msg = "%s has"
        if connection not in connection.protocol.players:
            raise KeyError()
        msg %= connection.name
    if connection not in connection.protocol.players:
        raise KeyError()
    
    kills = connection.ratio_kills
    deaths = float(max(1,connection.ratio_deaths))
    headshotkills = connection.ratio_headshotkills
    meleekills = connection.ratio_meleekills
    grenadekills = connection.ratio_grenadekills
    
    msg += " a kill-death ratio of %.2f" % (kills/deaths)
    if HEADSHOT_RATIO:
        msg += ", headshot-death ratio of %.2f" % (headshotkills/deaths)
    msg += " (%s kills, %s deaths, %s headshot, %s melee, %s grenade)." % (kills, connection.ratio_deaths, headshotkills, meleekills, grenadekills)
    return msg

add(ratio)

def apply_script(protocol, connection, config):
    class RatioConnection(connection):
        ratio_kills = 0
        ratio_headshotkills = 0
        ratio_meleekills = 0
        ratio_grenadekills = 0
        ratio_deaths = 0
        
        def on_kill(self, killer, type, grenade):
            if killer is not None and self.team is not killer.team:
                if self != killer:
                    killer.ratio_kills += 1
                    killer.ratio_headshotkills += type == HEADSHOT_KILL
                    killer.ratio_meleekills    += type == MELEE_KILL
                    killer.ratio_grenadekills  += type == GRENADE_KILL
            
            self.ratio_deaths += 1
            return connection.on_kill(self, killer, type, grenade)
    
    class RatioProtocol(protocol):
        def on_votekick_start(self, instigator, victim, reason):
            result = protocol.on_votekick_start(self, instigator, victim, reason)
            if result is None and RATIO_ON_VOTEKICK:
                message = ratio(instigator, victim.name)
                if IRC_ONLY:
                    self.irc_say('* ' + message)
                else:
                    self.send_chat(message, irc = True)
            return result
    
    return RatioProtocol, RatioConnection
Good job.
The problem is, does Iceball use Python scripts anymore, so your effort won't be in vain.
LinktersHD
Deuced Up
Posts: 124
Joined: Thu Nov 01, 2012 12:27 pm


It's not the game client but the server software. Hopefully it will.
MrHaaax
Modder
Modder
Posts: 1360
Joined: Sun Nov 25, 2012 2:58 am


LinktersHD wrote:
It's not the game client but the server software. Hopefully it will.
I know that.
PS: Iceball will be using Lua, so get ready yerself for coding this stuff to Lua.
rakiru
Coder
Coder
Posts: 1349
Joined: Sun Nov 11, 2012 12:26 pm


I'm sure there will be both Iceball and Ace of Spades servers, and Iceball is far from complete at this point anyway.
Bobby Lemain
Deuced Up
Posts: 27
Joined: Wed Nov 28, 2012 8:45 am


Excellent work! Will be using this on Ace Combat 4
tallyyyyyy
Winter Celebration 2013
Winter Celebration 2013
Posts: 180
Joined: Sat Nov 10, 2012 1:04 am


*Infogulch and I

Did you miss first grade or something?
LinktersHD
Deuced Up
Posts: 124
Joined: Thu Nov 01, 2012 12:27 pm


No i didn't. I copied the post from the old forums which I made to here. Let me change it.
MrPanther
Deuce
Posts: 2
Joined: Mon Nov 26, 2012 6:29 pm


But theres another Problem: The Master Server doesnt take anymore Servers oline?! Blue_Surprised2
MaxyBlack
Deuce
Posts: 5
Joined: Wed Jun 19, 2013 9:11 am


Is it possible to store the data of users in database ?
10 posts Page 1 of 1
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 1 guest