Created
October 17, 2011 08:34
-
-
Save iamgreaser/1292206 to your computer and use it in GitHub Desktop.
pyspades /ratio, as a script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# KDR script because Enari said so --GM | |
import commands | |
def ratio(connection, user=None): | |
if user != None: | |
connection = commands.get_player(connection.protocol, user) | |
if connection not in connection.protocol.players: | |
raise KeyError() | |
ratio = connection.ratio_kills/float(max(1,connection.ratio_deaths)) | |
ratio_msg = "You have a kill-death ratio of %.2f" % ratio | |
return ('%s (%s kills, %s deaths).' % | |
(ratio_msg, connection.ratio_kills, connection.ratio_deaths)) | |
commands.add(ratio) | |
def apply_script(protocol, connection, config): | |
class RatioConnection(connection): | |
ratio_kills = 0 | |
ratio_deaths = 0 | |
def on_kill(self, killer): | |
ret = connection.on_kill(self, killer) | |
if ret: | |
return ret | |
if killer is not None and self.team is not killer.team: | |
if self != killer: | |
killer.ratio_kills += 1 | |
self.ratio_deaths += 1 | |
return protocol, RatioConnection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment