Half-Life 2 Deathmatch - God mode
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Half-Life 2 Deathmatch - God mode
Hello game scripters , 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.
Thank You & have a great weekend.
-
- Senior Member
- Posts: 310
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
Re: Half-Life 2 Deathmatch - God mode
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)
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
Thank you for the script, i will give it a try. update-- I get no god mode after the 12th in a row kill, Its gives no errors. I am a windows.
-
- Senior Member
- Posts: 310
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
Re: Half-Life 2 Deathmatch - God mode
It shouldn't matter if windows or linux.
Try this, its updated code:
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'}
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
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.
Re: Half-Life 2 Deathmatch - God mode
Hey daren, you can give this a try.
You can edit the messages to your likings :)
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 :)
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
Ok, thank you, i will give it a try. 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
- L'In20Cible
- Project Leader
- Posts: 1534
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: Half-Life 2 Deathmatch - God mode
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()
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
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
Re: Half-Life 2 Deathmatch - God mode
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!
Thanks for the tips! I didn't know about the caching, that will be very useful for the future!
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
OK Thank you
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
I am getting no errors to show on this one
I am using yours L'In20Cible, and sometimes the godmode sometimes dont work and sometimes it does. please help.
I am using yours L'In20Cible, and sometimes the godmode sometimes dont work and sometimes it does. please help.
Re: Half-Life 2 Deathmatch - God mode
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()
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
OK, Will give it a try, Thank you. Thanks again, it works great.
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
Hello scripters . 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.
I know the beacon is from es, but did not know how to show it. Thank you and have a great weekend .
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
-
- Senior Member
- Posts: 310
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
Re: Half-Life 2 Deathmatch - God mode
daren adler wrote:Hello scripters . 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.I know the beacon is from es, but did not know how to show it. Thank you and have a great weekend .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
How long the beacon should be?
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
cssbestrpg wrote:daren adler wrote:Hello scripters . 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.I know the beacon is from es, but did not know how to show it. Thank you and have a great weekend .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
How long the beacon should be?
its 45 sec.
-
- Senior Member
- Posts: 310
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
Re: Half-Life 2 Deathmatch - God mode
So the one beacon duration is 45 seconds?
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Half-Life 2 Deathmatch - God mode
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)
-
- Senior Member
- Posts: 310
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
Re: Half-Life 2 Deathmatch - God mode
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))
Who is online
Users browsing this forum: Bing [Bot] and 1 guest