Killcam
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Killcam
I want to create a kill cam for hl2dm, where you see a picture of the enemy that killed you with a black and white filter"
Thanks in Advance
Painkiller
Thanks in Advance
Painkiller
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Killcam
Hello Python team and community,
This version is currently running.
2020-04-10 14:06:59 - sp - EXCEPTION
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/listeners/tick.py", line 80, in _tick
self.pop(0).execute()
File "../addons/source-python/packages/source-python/listeners/tick.py", line 161, in execute
return self.callback(*self.args, **self.kwargs)
File "../addons/source-python/plugins/killcam/killcam.py", line 24, in activate_cam
target = inthandle_from_userid(attacker)
ValueError: Conversion from "Userid" (0) to "IntHandle" failed.
This version is currently running.
Syntax: Select all
from events import Event
from players.entity import Player
from players.helpers import inthandle_from_userid
from engines.sound import Sound
from filters.recipients import RecipientFilter
from listeners.tick import Delay
@Event("player_activate")
def _player_activate(game_event):
userid = game_event.get_int('userid')
@Event("player_death")
def _player_death(game_event):
userid = game_event.get_int('userid')
attacker = game_event.get_int('attacker')
if userid != attacker:
Delay(0.5, activate_cam, (userid, attacker))
def activate_cam(userid, attacker):
player = Player.from_userid(userid)
target = inthandle_from_userid(attacker)
player.observer_target = target
player.observer_mode = 2
Sound('effects/ministrider_fire1.wav').play(player.index)
Delay(3, end_cam, (userid, ))
def end_cam(userid):
Player.from_userid(userid).spawn()
Re: Killcam
Changing the _player_death() function to this should fix that:
Syntax: Select all
def _player_death(game_event):
userid = game_event.get_int('userid')
attacker = game_event.get_int('attacker')
if attacker not in (userid, 0):
Delay(0.5, activate_cam, (userid, attacker))
Re: Killcam
I noticed you also asked for the screen to go black and white in your original request. I've added that.. and rewrote the plugin, here you go
:

Syntax: Select all
# ../killcam/killcam.py
# Source.Python
from commands.client import ClientCommand
from events import Event
from players.entity import Player
# Time (in seconds) until the player automatically respawns. (0 - disabled)
KILLCAM_DURATION = 3
KILLCAM_SOUND_FX = 'npc/strider/strider_minigun.wav'
screen_overlay = {
# Monochrome (black and white) screen overlay.
True: 'debug/yuv',
# Removes the current screen overlay.
False: '""'
}
class PlayerK(Player):
"""Modified Player class."""
def __init__(self, index, caching=True):
"""Initializes the object."""
super().__init__(index, caching)
self.mono = False
self.spawn_delay = None
def toggle_monochrome(self):
"""Enables or disables the black and white screen overlay effect."""
self.mono = not self.mono
try:
# Trick the player into thinking cheats are enabled.
self.send_convar_value('sv_cheats', 1)
except AttributeError:
return
# Enable or disable the black and white effect.
self.client_command(f'r_screenoverlay {screen_overlay[self.mono]}')
# Disable the fake cheats after a single frame.
self.delay(0, self.send_convar_value, ('sv_cheats', 0))
def show_killcam(self, target_handle, duration=0):
"""Switches the player's view to their killer.
Args:
target_handle (int): Inthandle of the killer.
duration (float): Time until the player automatically respawns.
"""
self.observer_target = target_handle
self.observer_mode = 2
self.play_sound(KILLCAM_SOUND_FX)
self.toggle_monochrome()
if duration > 0:
# Respawn the player after a delay, thus disabling the killcam.
self.spawn_delay = self.delay(duration, self.spawn, (True,))
def on_spawned(self):
"""Called when the player spawns."""
try:
self.spawn_delay.cancel()
except (AttributeError, ValueError):
# AttributeError: Delay doesn't exist.
# ValueError: Delay already executed the callback.
pass
# Is the black and white effect currently active for this player?
if self.mono:
# Disable it.
self.toggle_monochrome()
@Event('player_spawn')
def player_spawn(event):
"""Called when a player spawns."""
PlayerK.from_userid(event['userid']).on_spawned()
@Event('player_death')
def player_death(event):
"""Called when a player dies."""
userid_a = event['attacker']
userid_v = event['userid']
# Suicide or world (falling, drowning) death?
if userid_a in (userid_v, 0):
return
victim = PlayerK.from_userid(userid_v)
victim.delay(0.5, victim.show_killcam, (
PlayerK.from_userid(userid_a).inthandle, KILLCAM_DURATION))
@ClientCommand('spec_next')
def spec_next(command, index):
"""Called when a player presses left click while spectating."""
player = PlayerK(index)
# Is the player in spectate?
if player.team == 1:
# Don't go further.
return
player.spawn(force=True)
Last edited by VinciT on Fri Nov 13, 2020 11:09 pm, edited 2 times in total.
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Killcam
Thanks VinciT.
I have test it and become this.
I have test it and become this.
Code: Select all
2020-04-11 09:51:46 - 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/killcam/killcam.py", line 68, in player_death
victim = player_instances.from_userid(userid_v)
File "../addons/source-python/packages/source-python/players/dictionary.py", line 39, in from_userid
return self[index_from_userid(userid)]
File "../addons/source-python/packages/source-python/entities/dictionary.py", line 50, in __missing__
**self._kwargs)
File "../addons/source-python/plugins/killcam/killcam.py", line 26, in __init__
super().__init__(index, caching)
TypeError: __init__() takes 2 positional arguments but 3 were given
Re: Killcam
It seems your Source.Python is outdated. Try running the sp update server command or update it manually.
Edit: If you don't feel like updating for some reason, you can just change the __init__() function to this:
Edit: If you don't feel like updating for some reason, you can just change the __init__() function to this:
Syntax: Select all
def __init__(self, index):
"""Initializes the object."""
super().__init__(index)
self.mono = False
- Painkiller
- Senior Member
- Posts: 751
- Joined: Sun Mar 01, 2015 8:09 am
- Location: Germany
- Contact:
Re: Killcam
ok thanks
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Killcam
I get this now in killcam log. and if you could, could you make it so you have to use mouse button 1 to spawn? I am using the 2nd script on on this page, the one that gives black and white.
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\listeners\tick.py", line 80, in _tick
self.pop(0).execute()
File "..\addons\source-python\packages\source-python\listeners\tick.py", line 161, in execute
return self.callback(*self.args, **self.kwargs)
File "..\addons\source-python\packages\source-python\entities\_base.py", line 470, in _callback
callback(*args, **kwargs)
File "..\addons\source-python\plugins\killcam\killcam.py", line 51, in killcam
self.toggle_monochrome(duration)
File "..\addons\source-python\plugins\killcam\killcam.py", line 37, in toggle_monochrome
self.send_convar_value('sv_cheats', 1)
File "..\addons\source-python\packages\source-python\players\_base.py", line 669, in send_convar_value
self.client.net_channel.send_data(buffer)
AttributeError: 'NoneType' object has no attribute 'send_data'
Re: Killcam
Fixed the issue and added a way to disable the automatic respawn - set KILLCAM_DURATION to 0 to get the behavior you want.daren adler wrote:I get this now in killcam log. and if you could, could you make it so you have to use mouse button 1 to spawn? I am using the 2nd script on on this page, the one that gives black and white.Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\listeners\tick.py", line 80, in _tick
self.pop(0).execute()
File "..\addons\source-python\packages\source-python\listeners\tick.py", line 161, in execute
return self.callback(*self.args, **self.kwargs)
File "..\addons\source-python\packages\source-python\entities\_base.py", line 470, in _callback
callback(*args, **kwargs)
File "..\addons\source-python\plugins\killcam\killcam.py", line 51, in killcam
self.toggle_monochrome(duration)
File "..\addons\source-python\plugins\killcam\killcam.py", line 37, in toggle_monochrome
self.send_convar_value('sv_cheats', 1)
File "..\addons\source-python\packages\source-python\players\_base.py", line 669, in send_convar_value
self.client.net_channel.send_data(buffer)
AttributeError: 'NoneType' object has no attribute 'send_data'
The updated plugin can be found in this post.
- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Killcam
OK i will check it out
. Thank you again





- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Killcam
daren adler wrote:OK i will check it out. Thank you again
![]()
![]()
**update** I put it to 0 and i still have to hit w or a or d to spawn, (was hoping for mouse button 1) but if not thats ok,,i get no errors, thank you.

Re: Killcam
Hey All ,
I tried this and it works good with auto respawn on
I tried this and it works good with auto respawn on
Re: Killcam
Huh, that's odd.. On my server left click (+attack) respawns me. Heading out right now, when I come back I'll see if I can figure something out.daren adler wrote:daren adler wrote:OK i will check it out. Thank you again
![]()
![]()
**update** I put it to 0 and i still have to hit w or a or d to spawn, (was hoping for mouse button 1) but if not thats ok,,i get no errors, thank you.

- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Killcam
VinciT wrote:Huh, that's odd.. On my server left click (+attack) respawns me. Heading out right now, when I come back I'll see if I can figure something out.daren adler wrote:daren adler wrote:OK i will check it out. Thank you again
![]()
![]()
**update** I put it to 0 and i still have to hit w or a or d to spawn, (was hoping for mouse button 1) but if not thats ok,,i get no errors, thank you.
ok

- daren adler
- Senior Member
- Posts: 348
- Joined: Sat May 18, 2019 7:42 pm
Re: Killcam
OK will do. Works great
Thank you




Re: Killcam
I like it to and using it as well....
Thanks VinciT :)
Thanks VinciT :)
Who is online
Users browsing this forum: No registered users and 67 guests