Killcam
Posted: Mon Dec 14, 2015 1:20 pm
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
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.
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()
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))
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)
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
Syntax: Select all
def __init__(self, index):
"""Initializes the object."""
super().__init__(index)
self.mono = False
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'
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'
daren adler wrote:OK i will check it out. Thank you again
![]()
![]()
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.
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.
Grab the updated plugin and tell me if it works for you.daren adler wrote:ok