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

Half-Life 2 Deathmatch - God mode

Postby daren adler » Fri Mar 12, 2021 7:30 pm

Hello game scripters :grin: , was wondering if i could get a scripts made for godmode for 45 sec. I use the script killmessages viewtopic.php?f=37&t=1359 . I would like it if god mode would turn on when the 12th kill in a row happens.
Thank You & have a great weekend. :cool: :cool:
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 » Fri Mar 12, 2021 7:45 pm

Hi try this script, it should give you 45seconds god mod, when kill 12 in row.

Syntax: Select all

from players.entity import Player
from players.helpers import index_from_userid
from events import Event
from messages import SayText2

players = {}

@Event('map_start')
def map_start(args):
players.clear()

@Event('player_spawn')
def player_spawn(args):
userid = args.get_int('userid')
if not userid in players:
players[userid] = 0

@Event('player_death')
def player_death(args):
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
players[userid] = 0
players[attacker] += 1
if players[attacker] == 12:
godmode(attacker)

def godmode(userid):
player = Player(index_from_userid(userid))
player.set_godmode(True)
SayText2('\x04You have now godmode for 45seconds!').send(player.index)
player.delay(45, unset, (userid,))

def unset(userid):
player = Player(index_from_userid(userid))
player.set_godmode(False)
SayText2('\x04Your godmode is now off!').send(player.index)
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 » Fri Mar 12, 2021 8:34 pm

Thank you for the script, i will give it a try. :grin: :grin: update-- I get no god mode after the 12th in a row kill, Its gives no errors. I am a windows.
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 » Mon Mar 15, 2021 1:13 pm

It shouldn't matter if windows or linux.
Try this, its updated code:

Syntax: Select all

from players.entity import Player
from players.helpers import index_from_userid
from events import Event
from messages import SayText2

players = {}

@Event('map_start')
def map_start(args):
players.clear()

@Event('player_spawn')
def player_spawn(args):
userid = args.get_int('userid')
if not userid in players:
players[userid] = 0

@Event('player_death')
def player_death(args):
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
players[userid] = 0
players[attacker] += 1
value = getValue(players[attacker])
if value == 12:
Player(index_from_userid(attacker)).delay(0.1, godmode, (attacker,))

def godmode(userid):
player = Player(index_from_userid(userid))
player.set_godmode(True)
SayText2('\x04You have now godmode for 45seconds!').send(player.index)
player.delay(45, unset, (userid,))

def unset(userid):
player = Player(index_from_userid(userid))
player.set_godmode(False)
SayText2('\x04Your godmode is now off!').send(player.index)

def getValue(i):
if i in _values:
return _values[i]
return None

_values = {12: '12'}
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 » Mon Mar 15, 2021 6:17 pm

Thank you for trying but i still get no god mode after 12th kill, again thank you for trying, it still gives no errors either.
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: Half-Life 2 Deathmatch - God mode

Postby Kami » Mon Mar 15, 2021 6:50 pm

Hey daren, you can give this a try.

Syntax: Select all

from players.entity import Player
from events import Event
from players.dictionary import PlayerDictionary
from messages import SayText2

class StreakPlayer(Player):

def __init__(self, index):
super().__init__(index)
self.consecutive_kills = 0

streak_players = PlayerDictionary(StreakPlayer)

@Event('player_death')
def player_death(ev):
victim = streak_players.from_userid(ev['userid'])
attacker = streak_players.from_userid(ev['attacker'])
victim.consecutive_kills = 0
attacker.consecutive_kills += 1
if attacker.consecutive_kills == 12:
attacker.consecutive_kills = 0
attacker.set_godmode(True)
attacker.delay(45.0,_reset_godmode,(attacker,))
SayText2(f"{attacker.name} has reached 12 kills and is in godmode now!").send()

def _reset_godmode(player):
player.set_godmode(False)
SayText2(f"{player.name} is no longer in godmode!").send()


You can edit the messages to your likings :)
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 » Mon Mar 15, 2021 9:45 pm

Ok, thank you, i will give it a try. :cool: :cool: Update, Yep works great and no errors, again thank you so much. I also have a sm_nukem and was wondering if it could be added or another script for the 24th killstreak, heres the sourcemod plugin i use for the nukem effects -> https://forums.alliedmods.net/showthread.php?p=609299
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Half-Life 2 Deathmatch - God mode

Postby L'In20Cible » Tue Mar 16, 2021 2:48 am

Kami wrote:Hey daren, you can give this a try.

Syntax: Select all

from players.entity import Player
from events import Event
from players.dictionary import PlayerDictionary
from messages import SayText2

class StreakPlayer(Player):

def __init__(self, index):
super().__init__(index)
self.consecutive_kills = 0

streak_players = PlayerDictionary(StreakPlayer)

@Event('player_death')
def player_death(ev):
victim = streak_players.from_userid(ev['userid'])
attacker = streak_players.from_userid(ev['attacker'])
victim.consecutive_kills = 0
attacker.consecutive_kills += 1
if attacker.consecutive_kills == 12:
attacker.consecutive_kills = 0
attacker.set_godmode(True)
attacker.delay(45.0,_reset_godmode,(attacker,))
SayText2(f"{attacker.name} has reached 12 kills and is in godmode now!").send()

def _reset_godmode(player):
player.set_godmode(False)
SayText2(f"{player.name} is no longer in godmode!").send()


You can edit the messages to your likings :)


Here's few points to consider:

  • You don't need a PlayerDictionary, if you use caching for your player class.
  • Your _reset_godmode would fit better as a method in your player class instead of being a global function.
  • Deaths caused by world damage (fall damage, etc.) will produce a ValueError.

For example:

Syntax: Select all

from players.entity import Player
from events import Event
from messages import SayText2

class StreakPlayer(Player):
caching = True # Uses caching

def __init__(self, index):
super().__init__(index)
self.consecutive_kills = 0

def _reset_godmode(self):
self.set_godmode(False)
SayText2(f"{self.name} is no longer in 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.set_godmode(True)
attacker.delay(45.0, attacker._reset_godmode)
SayText2(f"{attacker.name} has reached 12 kills and is in godmode 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 » Tue Mar 16, 2021 5:19 am

Got this error

Code: Select all

2021-03-15 23:42:30 - sp   -   EXCEPTION   
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\events\listener.py", line 92, in fire_game_event
    callback(game_event)
  File "..\addons\source-python\plugins\godmode\godmode.py", line 17, in player_death
    attacker = streak_players.from_userid(ev['attacker'])
  File "..\addons\source-python\packages\source-python\players\dictionary.py", line 50, in from_userid
    return self[index_from_userid(userid)]

ValueError: Conversion from "Userid" (0) to "Index" failed
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: Half-Life 2 Deathmatch - God mode

Postby Kami » Tue Mar 16, 2021 10:22 am

Hey daren, that problem should be solved with L'In20Cible's version.

Thanks for the tips! I didn't know about the caching, that will be very useful for the future!
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 » Tue Mar 16, 2021 5:41 pm

OK Thank you :cool: :cool: :cool:
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 » Mon Mar 29, 2021 2:57 am

I am getting no errors to show on this one :grin:
I am using yours L'In20Cible, and sometimes the godmode sometimes dont work and sometimes it does. please help.
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Half-Life 2 Deathmatch - God mode

Postby VinciT » Mon Mar 29, 2021 3:47 am

I can think of one thing which could be causing this - you're getting 12 kills before the old godmode expires, so the first delayed reset (45 seconds) cancels the second godmode. Try this and tell us if you have the same issue:

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


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)

def _reset_godmode(self):
self.set_godmode(False)
SayText2(f"{self.name} is no longer in 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"{attacker.name} has reached 12 kills and is in godmode now!").send()
ImageImageImageImageImage
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 » Mon Mar 29, 2021 4:12 pm

OK, Will give it a try, Thank you. Thanks again, it works great.
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 » Sat Mar 12, 2022 4:19 am

Hello scripters :grin: . Is there a way to add a beacon on while the player is in god mode on here ?. Here is a beacon i would like to have please.

Code: Select all

def beacon(attacker):
    x,y,z = es.getplayerlocation(attacker)
    r = random.randint(0,255)
    g = random.randint(0,255)
    b = random.randint(0,255)
    effectlib.drawCircle((x,y,z + 10),radius=80,steps=12,halo="sprites/greenglow1.vmt",model="sprites/greenglow1.vmt",seconds=0.7,width=10,endwidth=10,red=r,green=g,blue=b)
    r2 = random.randint(0,255)
    g2 = random.randint(0,255)
    b2 = random.randint(0,255)
    effectlib.drawCircle((x,y,z + 30),radius=60,steps=12,halo="sprites/greenglow1.vmt",model="sprites/greenglow1.vmt",seconds=0.7,width=10,endwidth=10,red=r2,green=g2,blue=b2)
    r3 = random.randint(0,255)
    g3 = random.randint(0,255)
    b3 = random.randint(0,255)
    effectlib.drawCircle((x,y,z + 50),radius=40,steps=12,halo="sprites/greenglow1.vmt",model="sprites/greenglow1.vmt",seconds=0.7,width=10,endwidth=10,red=r3,green=g3,blue=b3)
    es.emitsound('player', attacker, 'buttons/blip2.wav', 1.0, 0.7)
    try:
        if not playerlib.getPlayer(attacker).isdead:
            gamethread.delayedname(1, 'beacon_loop', beacon, (attacker))
    except:
        pass
I know the beacon is from es, but did not know how to show it. Thank you and have a great weekend :cool: :cool: .
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 Mar 17, 2022 9:11 am

daren adler wrote:Hello scripters :grin: . Is there a way to add a beacon on while the player is in god mode on here ?. Here is a beacon i would like to have please.

Code: Select all

def beacon(attacker):
    x,y,z = es.getplayerlocation(attacker)
    r = random.randint(0,255)
    g = random.randint(0,255)
    b = random.randint(0,255)
    effectlib.drawCircle((x,y,z + 10),radius=80,steps=12,halo="sprites/greenglow1.vmt",model="sprites/greenglow1.vmt",seconds=0.7,width=10,endwidth=10,red=r,green=g,blue=b)
    r2 = random.randint(0,255)
    g2 = random.randint(0,255)
    b2 = random.randint(0,255)
    effectlib.drawCircle((x,y,z + 30),radius=60,steps=12,halo="sprites/greenglow1.vmt",model="sprites/greenglow1.vmt",seconds=0.7,width=10,endwidth=10,red=r2,green=g2,blue=b2)
    r3 = random.randint(0,255)
    g3 = random.randint(0,255)
    b3 = random.randint(0,255)
    effectlib.drawCircle((x,y,z + 50),radius=40,steps=12,halo="sprites/greenglow1.vmt",model="sprites/greenglow1.vmt",seconds=0.7,width=10,endwidth=10,red=r3,green=g3,blue=b3)
    es.emitsound('player', attacker, 'buttons/blip2.wav', 1.0, 0.7)
    try:
        if not playerlib.getPlayer(attacker).isdead:
            gamethread.delayedname(1, 'beacon_loop', beacon, (attacker))
    except:
        pass
I know the beacon is from es, but did not know how to show it. Thank you and have a great weekend :cool: :cool: .


How long the beacon should be?
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 Mar 17, 2022 2:35 pm

cssbestrpg wrote:
daren adler wrote:Hello scripters :grin: . Is there a way to add a beacon on while the player is in god mode on here ?. Here is a beacon i would like to have please.

Code: Select all

def beacon(attacker):
    x,y,z = es.getplayerlocation(attacker)
    r = random.randint(0,255)
    g = random.randint(0,255)
    b = random.randint(0,255)
    effectlib.drawCircle((x,y,z + 10),radius=80,steps=12,halo="sprites/greenglow1.vmt",model="sprites/greenglow1.vmt",seconds=0.7,width=10,endwidth=10,red=r,green=g,blue=b)
    r2 = random.randint(0,255)
    g2 = random.randint(0,255)
    b2 = random.randint(0,255)
    effectlib.drawCircle((x,y,z + 30),radius=60,steps=12,halo="sprites/greenglow1.vmt",model="sprites/greenglow1.vmt",seconds=0.7,width=10,endwidth=10,red=r2,green=g2,blue=b2)
    r3 = random.randint(0,255)
    g3 = random.randint(0,255)
    b3 = random.randint(0,255)
    effectlib.drawCircle((x,y,z + 50),radius=40,steps=12,halo="sprites/greenglow1.vmt",model="sprites/greenglow1.vmt",seconds=0.7,width=10,endwidth=10,red=r3,green=g3,blue=b3)
    es.emitsound('player', attacker, 'buttons/blip2.wav', 1.0, 0.7)
    try:
        if not playerlib.getPlayer(attacker).isdead:
            gamethread.delayedname(1, 'beacon_loop', beacon, (attacker))
    except:
        pass
I know the beacon is from es, but did not know how to show it. Thank you and have a great weekend :cool: :cool: .


How long the beacon should be?

its 45 sec.
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 Mar 17, 2022 2:55 pm

So the one beacon duration is 45 seconds?
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 Mar 17, 2022 5:56 pm

cssbestrpg wrote:So the one beacon duration is 45 seconds?


yes,,the killstreak on every 12th kill. 12, 24, 36 and 48 and the godmode last 45 seconds each time you get godmode.

attacker.grant_godmode(duration=45)
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 Mar 17, 2022 6:14 pm

Try this one(untested):

Syntax: Select all

# ../killstreak_god/killstreak_god.py

# Python
import random
from time import time

# Source.Python
from engines.sound import engine_sound
from events import Event
from messages import SayText2
from players.entity import Player
from players.helpers import index_from_userid
from effects import TempEntity
from engines.precache import Model
from mathlib import Vector
from filters.recipients import RecipientFilter

effect_model = Model('sprites/greenglow1.vmt')

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)

def _reset_godmode(self):
self.set_godmode(False)
SayText2(f"{self.name} is no longer in 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)
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
beamRing(attacker, 0, 350, 10, 45, 3, 2, r, g, b)
emitsound(attacker, 'buttons/blip2.wav', 1.0, 0.7)
SayText2(f"{attacker.name} has reached 12 kills and is in godmode now!").send()

def emitsound(userid, sound, volume, attenuation):
engine_sound.precache_sound(sound)
index = index_from_userid(userid)
engine_sound.emit_sound(RecipientFilter(), index, 0, sound, volume, attenuation)

def beamRing(userid, startRadius, endRadius, zplus, lifeTime, width, amplitude, r, g, b, a=255):
x,y,z = getPlayerLocation(userid)
tempEnt = TempEntity('BeamRingPoint')

tempEnt.red = r
tempEnt.green = g
tempEnt.blue = b
tempEnt.alpha = a

tempEnt.center = Vector(x, y, z + zplus)
tempEnt.start_radius = startRadius
tempEnt.end_radius = endRadius

tempEnt.life_time = lifeTime
tempEnt.start_width = width
tempEnt.end_width = width
tempEnt.amplitude = amplitude

tempEnt.halo_index = effect_model
tempEnt.model_index = effect_model

tempEnt.create()

def getPlayerLocation(userid):
x,y,z = Player.from_userid(userid).get_key_value_string('origin').split(' ')
return (float(x), float(y), float(z))

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 21 guests