Page 1 of 2

Killcam

Posted: Mon Dec 14, 2015 1:20 pm
by Painkiller
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

Posted: Sat Dec 19, 2015 4:16 pm
by Painkiller
Nobody a Idia ?

Posted: Sun Dec 20, 2015 3:40 pm
by satoon101
I'm not sure this is even possible from a plugin standpoint.

Posted: Sun Dec 20, 2015 6:51 pm
by necavi
Yes this is possible, you'll have to attach the player's camera to another entity, likely and enable a screen overlay that makes everything black and white, it won't look terribly good but it might work.

Re: Killcam

Posted: Fri Apr 10, 2020 3:07 pm
by Painkiller
Hello Python team and community,


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

Posted: Fri Apr 10, 2020 3:49 pm
by VinciT
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

Posted: Fri Apr 10, 2020 9:36 pm
by VinciT
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 :smile: :

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)

Re: Killcam

Posted: Sat Apr 11, 2020 7:54 am
by Painkiller
Thanks VinciT.

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

Posted: Sat Apr 11, 2020 3:06 pm
by VinciT
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:

Syntax: Select all

def __init__(self, index):
"""Initializes the object."""
super().__init__(index)
self.mono = False

Re: Killcam

Posted: Mon Apr 13, 2020 8:53 am
by Painkiller
ok thanks

Re: Killcam

Posted: Mon Nov 09, 2020 2:42 am
by daren adler
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

Posted: Tue Nov 10, 2020 8:44 pm
by VinciT
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'
Fixed the issue and added a way to disable the automatic respawn - set KILLCAM_DURATION to 0 to get the behavior you want.
The updated plugin can be found in this post.

Re: Killcam

Posted: Tue Nov 10, 2020 8:56 pm
by daren adler
OK i will check it out :smile: . Thank you again :cool: :cool: :cool:

Re: Killcam

Posted: Tue Nov 10, 2020 10:14 pm
by daren adler
daren adler wrote:OK i will check it out :smile: . Thank you again :cool: :cool: :cool:


**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. :cool:

Re: Killcam

Posted: Wed Nov 11, 2020 6:16 pm
by PEACE
Hey All ,

I tried this and it works good with auto respawn on

Re: Killcam

Posted: Wed Nov 11, 2020 10:40 pm
by VinciT
daren adler wrote:
daren adler wrote:OK i will check it out :smile: . Thank you again :cool: :cool: :cool:


**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. :cool:
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. :wink:

Re: Killcam

Posted: Wed Nov 11, 2020 10:52 pm
by daren adler
VinciT wrote:
daren adler wrote:
daren adler wrote:OK i will check it out :smile: . Thank you again :cool: :cool: :cool:


**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. :cool:
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. :wink:


ok :smile:

Re: Killcam

Posted: Fri Nov 13, 2020 11:11 pm
by VinciT
daren adler wrote:ok :smile:
Grab the updated plugin and tell me if it works for you.

Re: Killcam

Posted: Fri Nov 13, 2020 11:32 pm
by daren adler
OK will do. Works great :smile: Thank you :cool: :cool:

Re: Killcam

Posted: Mon Nov 16, 2020 5:23 am
by PEACE
I like it to and using it as well....
Thanks VinciT :)