from commands import add

def handicap(self, value):
    if float(value) > 1 or float(value) < -1: return "Nah dont cheat and set your damage multiplier between -1 and 1 :P"
    self.handicap_value = float(value)
    u = int(self.handicap_value*100)
    if float(value) < 0: self.send_chat("lol wanna heal the enemy eh?")
    return "Damage output set to %i%%" % u
add(handicap)

def apply_script(protocol, connection, config):
    class Handiconnection(connection):
        handicap_value = 1.0
        def on_hit(self, hit_amount, hit_player, type, grenade):
			value = connection.on_hit(self, hit_amount, hit_player, type, grenade) #call all other scripts and store any new values.
			if value != None: 	#another script returned something other than None
				return value 	#if another script has modified the value, return that value.
			elif self.team == hit_player.team: #prevents team healing and self healing. All self-hits should be caught here.
				return value 	#means no change, identical to returning None in this instance
			newDamage = int(hit_amount * self.handicap_value) #calculate new damage. convert it to an integer which provides rounding
			return newDamage	#return an over-ridden damage value 
    return protocol, Handiconnection
