Killcam

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Killcam

Postby Painkiller » 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
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Postby Painkiller » Sat Dec 19, 2015 4:16 pm

Nobody a Idia ?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Dec 20, 2015 3:40 pm

I'm not sure this is even possible from a plugin standpoint.
Image
necavi
Developer
Posts: 129
Joined: Wed Jan 30, 2013 9:51 pm

Postby necavi » Sun Dec 20, 2015 6:51 pm

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.
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: Killcam

Postby Painkiller » Fri Apr 10, 2020 3:07 pm

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()
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Killcam

Postby VinciT » Fri Apr 10, 2020 3:49 pm

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))
ImageImageImageImageImage
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Killcam

Postby VinciT » Fri Apr 10, 2020 9:36 pm

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)
Last edited by VinciT on Fri Nov 13, 2020 11:09 pm, edited 2 times in total.
ImageImageImageImageImage
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: Killcam

Postby Painkiller » Sat Apr 11, 2020 7:54 am

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
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Killcam

Postby VinciT » Sat Apr 11, 2020 3:06 pm

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
ImageImageImageImageImage
User avatar
Painkiller
Senior Member
Posts: 725
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: Killcam

Postby Painkiller » Mon Apr 13, 2020 8:53 am

ok thanks
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: Killcam

Postby daren adler » Mon Nov 09, 2020 2:42 am

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'
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Killcam

Postby VinciT » Tue Nov 10, 2020 8:44 pm

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

Re: Killcam

Postby daren adler » Tue Nov 10, 2020 8:56 pm

OK i will check it out :smile: . Thank you again :cool: :cool: :cool:
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: Killcam

Postby daren adler » Tue Nov 10, 2020 10:14 pm

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:
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: Killcam

Postby PEACE » Wed Nov 11, 2020 6:16 pm

Hey All ,

I tried this and it works good with auto respawn on
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Killcam

Postby VinciT » Wed Nov 11, 2020 10:40 pm

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

Re: Killcam

Postby daren adler » Wed Nov 11, 2020 10:52 pm

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:
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Killcam

Postby VinciT » Fri Nov 13, 2020 11:11 pm

daren adler wrote:ok :smile:
Grab the updated plugin and tell me if it works for you.
ImageImageImageImageImage
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: Killcam

Postby daren adler » Fri Nov 13, 2020 11:32 pm

OK will do. Works great :smile: Thank you :cool: :cool:
User avatar
PEACE
Member
Posts: 50
Joined: Mon Oct 12, 2020 1:13 pm

Re: Killcam

Postby PEACE » Mon Nov 16, 2020 5:23 am

I like it to and using it as well....
Thanks VinciT :)

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 19 guests