Page 3 of 3

Re: Half-Life 2 Deathmatch - God mode

Posted: Wed Apr 06, 2022 4:53 pm
by cssbestrpg
This should do the trick:

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()

Re: Half-Life 2 Deathmatch - God mode

Posted: Wed Apr 06, 2022 6:28 pm
by daren adler
OK Will give it a try, thank you,

Re: Half-Life 2 Deathmatch - God mode

Posted: Thu Apr 07, 2022 2:39 pm
by daren adler
daren adler wrote:OK Will give it a try, thank you,
I tryed it and went in 3rd person view and i did not turn green. there is no errors to show.

Re: Half-Life 2 Deathmatch - God mode

Posted: Thu Apr 07, 2022 5:53 pm
by cssbestrpg
daren adler wrote:
daren adler wrote:OK Will give it a try, thank you,
I tryed it and went in 3rd person view and i did not turn green. there is no errors to show.

Try this one:

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):
self.color = Color(0 ,255, 0)
"""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)

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()

Re: Half-Life 2 Deathmatch - God mode

Posted: Thu Apr 07, 2022 7:23 pm
by daren adler
cssbestrpg wrote:
daren adler wrote:
daren adler wrote:OK Will give it a try, thank you,
I tryed it and went in 3rd person view and i did not turn green. there is no errors to show.

Try this one:

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):
self.color = Color(0 ,255, 0)
"""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)

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()


Yes, works great. thank you :grin: :grin: