cssbestrpg wrote:Try this one(untested):Syntax: Select all
# ../killstreak_god/killstreak_god.py
# Python
import random
from time import time
# Source.Python
from engines.sound import engine_sound
from events import Event
from messages import SayText2
from players.entity import Player
from players.helpers import index_from_userid
from effects import TempEntity
from engines.precache import Model
from mathlib import Vector
from filters.recipients import RecipientFilter
effect_model = Model('sprites/greenglow1.vmt')
class StreakPlayer(Player):
caching = True # Uses caching
def __init__(self, index):
super().__init__(index)
self.consecutive_kills = 0
self.reset_delay = None
def grant_godmode(self, duration):
"""Gives godmode to the player for the specified duration."""
try:
# Let's see if there's a reset delay.
running = self.reset_delay.running
except AttributeError:
running = False
# Well, is there?
if running:
# Update the execution with the newer duration.
self.reset_delay.exec_time = time() + duration
# Nope.
else:
self.set_godmode(True)
self.reset_delay = self.delay(duration, self._reset_godmode)
def _reset_godmode(self):
self.set_godmode(False)
SayText2(f"{self.name} is no longer in godmode!").send()
@Event('player_death')
def player_death(ev):
victim = StreakPlayer.from_userid(ev['userid'])
victim.consecutive_kills = 0
# Try to get the attacker, or exit the call if not a valid player
try:
attacker = StreakPlayer.from_userid(ev['attacker'])
except ValueError:
return
attacker.consecutive_kills += 1
if attacker.consecutive_kills == 12:
attacker.consecutive_kills = 0
attacker.grant_godmode(duration=45)
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
beamRing(attacker, 0, 350, 10, 45, 3, 2, r, g, b)
emitsound(attacker, 'buttons/blip2.wav', 1.0, 0.7)
SayText2(f"{attacker.name} has reached 12 kills and is in godmode now!").send()
def emitsound(userid, sound, volume, attenuation):
engine_sound.precache_sound(sound)
index = index_from_userid(userid)
engine_sound.emit_sound(RecipientFilter(), index, 0, sound, volume, attenuation)
def beamRing(userid, startRadius, endRadius, zplus, lifeTime, width, amplitude, r, g, b, a=255):
x,y,z = getPlayerLocation(userid)
tempEnt = TempEntity('BeamRingPoint')
tempEnt.red = r
tempEnt.green = g
tempEnt.blue = b
tempEnt.alpha = a
tempEnt.center = Vector(x, y, z + zplus)
tempEnt.start_radius = startRadius
tempEnt.end_radius = endRadius
tempEnt.life_time = lifeTime
tempEnt.start_width = width
tempEnt.end_width = width
tempEnt.amplitude = amplitude
tempEnt.halo_index = effect_model
tempEnt.model_index = effect_model
tempEnt.create()
def getPlayerLocation(userid):
x,y,z = Player.from_userid(userid).get_key_value_string('origin').split(' ')
return (float(x), float(y), float(z))
Nope, sorry no beacon when killed 12 in a row. and have this error
Code: Select all
[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\killstreak_god\killstreak_god.py", line 68, in player_death
beamRing(attacker, 0, 350, 10, 45, 3, 2, r, g, b)
File "..\addons\source-python\plugins\killstreak_god\killstreak_god.py", line 78, in beamRing
x,y,z = getPlayerLocation(userid)
File "..\addons\source-python\plugins\killstreak_god\killstreak_god.py", line 101, in getPlayerLocation
x,y,z = Player.from_userid(userid).get_key_value_string('origin').split(' ')
File "..\addons\source-python\packages\source-python\players\_base.py", line 109, in from_userid
return cls(index_from_userid(userid), caching=caching)
Boost.Python.ArgumentError: Python argument types in
_players._helpers.index_from_userid(StreakPlayer)
did not match C++ signature:
index_from_userid(unsigned int Userid)