Syntax: Select all
# ../killstreak_god/killstreak_god.py
# Python
from time import time
# Source.Python
from events import Event
from messages import SayText2
from players.entity import Player
from colors import Color, GREEN, LIGHT_GREEN
class StreakPlayer(Player):
caching = True # Uses caching
def __init__(self, index):
super().__init__(index)
self.consecutive_kills = 0
self.reset_delay = None
def grant_godmode(self, duration):
"""Gives godmode to the player for the specified duration."""
try:
# Let's see if there's a reset delay.
running = self.reset_delay.running
except AttributeError:
running = False
# Well, is there?
if running:
# Update the execution with the newer duration.
self.reset_delay.exec_time = time() + duration
# Nope.
else:
self.set_godmode(True)
self.reset_delay = self.delay(duration, self._reset_godmode)
self.color = Color(0, 255, 0)
def _reset_godmode(self):
self.set_godmode(False)
self.color = Color(255, 255, 255)
SayText2(f"{GREEN}{self.name} {LIGHT_GREEN}is no longer in {GREEN}godmode!").send()
@Event('player_death')
def player_death(ev):
victim = StreakPlayer.from_userid(ev['userid'])
victim.consecutive_kills = 0
# Try to get the attacker, or exit the call if not a valid player
try:
attacker = StreakPlayer.from_userid(ev['attacker'])
except ValueError:
return
attacker.consecutive_kills += 1
if attacker.consecutive_kills == 12:
attacker.consecutive_kills = 0
attacker.grant_godmode(duration=45)
SayText2(f"{GREEN}{attacker.name} {LIGHT_GREEN}has reached {GREEN}12 kills {LIGHT_GREEN}and is in {GREEN}godmode {LIGHT_GREEN}now!").send()