Skip to content

Instantly share code, notes, and snippets.

@iamgreaser
Created October 17, 2011 08:06
Show Gist options
  • Save iamgreaser/1292179 to your computer and use it in GitHub Desktop.
Save iamgreaser/1292179 to your computer and use it in GitHub Desktop.
patch for /ratio for pyspades
diff -r 359d9d545a79 feature_server/commands.py
--- a/feature_server/commands.py Sun Oct 16 00:45:02 2011 +0200
+++ b/feature_server/commands.py Mon Oct 17 21:01:40 2011 +1300
@@ -239,6 +239,19 @@
raise KeyError()
return ('Your current kill streak is %s. Best is %s kills.' %
(connection.streak, connection.best_streak))
+
+def ratio(connection):
+ if connection not in connection.protocol.players:
+ raise KeyError()
+ if connection.deaths == 0:
+ ratio_msg = "You have a kill-death ratio of %s" % (
+ "0.00000" if connection.kills == 0 else "INFINITY")
+ else:
+ ratio = connection.kills/float(connection.deaths)
+ ratio_msg = "You have a kill-death ratio of %.5f" % ratio
+ return ('%s (%s kills, %s deaths).' %
+ (ratio_msg, connection.kills, connection.deaths))
+
@admin
def lock(connection, value):
team = get_team(connection, value)
@@ -730,6 +743,7 @@
fly,
invisible,
streak,
+ ratio,
reset_game,
toggle_master,
change_map,
diff -r 359d9d545a79 feature_server/run.py
--- a/feature_server/run.py Sun Oct 16 00:45:02 2011 +0200
+++ b/feature_server/run.py Mon Oct 17 21:01:40 2011 +1300
@@ -121,6 +121,7 @@
killing = True
streak = 0
best_streak = 0
+ deaths = 0
last_chat = None
chat_time = 0
chat_count = 0
@@ -263,6 +264,7 @@
def on_kill(self, killer):
self.streak = 0
+ self.deaths += 1
self.airstrike = False
if killer is None or self.team is killer.team:
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment