Half-Life 2 Deathmatch - God mode

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: Half-Life 2 Deathmatch - God mode

Postby cssbestrpg » Wed Apr 06, 2022 4:53 pm

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()
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: Half-Life 2 Deathmatch - God mode

Postby daren adler » Wed Apr 06, 2022 6:28 pm

OK Will give it a try, thank you,
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: Half-Life 2 Deathmatch - God mode

Postby daren adler » Thu Apr 07, 2022 2:39 pm

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.
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: Half-Life 2 Deathmatch - God mode

Postby cssbestrpg » Thu Apr 07, 2022 5:53 pm

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()
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: Half-Life 2 Deathmatch - God mode

Postby daren adler » Thu Apr 07, 2022 7:23 pm

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:

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 14 guests