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: 561
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
Image

Image
User avatar
Painkiller
Senior Member
Posts: 561
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

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

Nobody a Idia ?
Image

Image
User avatar
satoon101
Project Leader
Posts: 2616
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: 561
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: 175
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: 175
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 events import Event
from players.entity import Player
from players.dictionary import PlayerDictionary


KILLCAM_DURATION = 3
KILLCAM_SOUND_FX = 'effects/ministrider_fire1.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

def toggle_monochrome(self, duration=0):
"""Enables or disables the black and white screen overlay effect.

Args:
duration (float): How long should the effect last? (in seconds)
"""
self.mono = not self.mono
# Trick the player into thinking cheats are enabled.
self.send_convar_value('sv_cheats', 1)
# 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))

# Should the effect be turned off after a while?
if duration:
self.delay(duration, self.toggle_monochrome)

def killcam(self, target_handle, duration):
self.observer_target = target_handle
self.observer_mode = 2
self.play_sound(KILLCAM_SOUND_FX)
self.toggle_monochrome(duration)
# Respawn the player after a delay, thus disabling the killcam.
self.delay(duration, self.spawn)


player_instances = PlayerDictionary(PlayerK)


@Event('player_death')
def player_death(event):
userid_a = event['attacker']
userid_v = event['userid']

# Suicide or world (falling, drowning) death?
if userid_a in (userid_v, 0):
return

victim = player_instances.from_userid(userid_v)
victim.delay(0.5, victim.killcam, (
player_instances.from_userid(userid_a).inthandle, KILLCAM_DURATION))
ImageImageImageImageImage
User avatar
Painkiller
Senior Member
Posts: 561
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: 175
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: 561
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: Killcam

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

ok thanks

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 5 guests