[HL2:DM] effects.py

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Painkiller
Senior Member
Posts: 477
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

[HL2:DM] effects.py

Postby Painkiller » Tue Jul 09, 2019 6:31 pm

I noticed a mistake in the logs.
Maybe there's a solution?


Code: Select all

2019-07-09 20:25:03 - 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/supermod/modules/effects.py", line 260, in dissolve_delay
    inthandle = PlayerEntity(index_from_userid(userid)).ragdoll

ValueError: Conversion from "Userid" (3) to "Index" failed.




Syntax: Select all

import random

from entities import ServerNetworkable

from entities.entity import Entity
import core
from entities.helpers import edict_from_index
from entities.helpers import pointer_from_index
from entities.helpers import index_from_pointer
from entities.helpers import basehandle_from_index
from entities.helpers import index_from_inthandle

from entities.factories import factory_dictionary

from players.entity import Player as PlayerEntity
from players.helpers import index_from_userid
from players.helpers import playerinfo_from_index
from players.helpers import playerinfo_from_userid
from players.helpers import inthandle_from_userid
from entities.constants import DissolveType
from entities.constants import INVALID_ENTITY_INTHANDLE

from events import Event

from messages import Fade
from messages import Shake

from colors import Color

from effects.base import TempEntity
from engines.server import engine_server
from engines.precache import Model

from filters.recipients import RecipientFilter
from filters.players import PlayerIter
from filters.entities import EntityIter

from listeners import OnLevelInit
from listeners import OnEntityCreated
from listeners import OnEntityDeleted
from listeners.tick import Delay, Repeat

from mathlib import Vector
import math


from supermod import functions
from supermod.cfg.modelreplacement import modelreplacement
from supermod.cfg.weapons import weapons
from supermod.supermod import settings

from stringtables import string_tables
import core
beacons = {}

in_map_change = False
core.console_message("\n[Supermod] Effects loaded!")
spark_sounds = [
'ambient/energy/spark1.wav',
'ambient/energy/spark2.wav',
'ambient/energy/spark3.wav',
'ambient/energy/spark4.wav',
'ambient/energy/spark5.wav',
'ambient/energy/spark6.wav'
]

def unload():
for beacon in beacons:
beacons[beacon].stop()

@OnLevelInit
def map_start(mapname):
global in_map_change
in_map_change = True
#for beacon in beacons:
#beacons[beacon].stop()

@Event('player_disconnect')
def player_disconnect(game_event):
userid = game_event.get_int('userid')
if userid in beacons:
beacons[userid].stop()

@Event('player_spawn')
def player_spawn(game_event):
global in_map_change
if in_map_change:
userid = game_event.get_int('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
if not player.dead:
in_map_change = False


class Beacon(object):
def __init__(self, userid, r=255, g=0, b=0, a=255):
self.userid = userid
self.r = r
self.g = g
self.b = b
self.a = a
self.player = playerinfo_from_userid(userid)
self.repeat = Repeat(self.effect)
self.repeat.start(0.7, math.inf)

def effect(self):
loc = self.player.origin
loc.z += 5

blitz_model_index = engine_server.precache_model('sprites/laserbeam.vmt')
blitz_halo_index = engine_server.precache_model('sprites/laserbeam.vmt')

for player in PlayerIter('human'):
index = player.index
steamid = player.steamid
if steamid not in settings or settings[steamid]['effects'] == 1:
eff = TempEntity('BeamRingPoint')
eff.alpha = self.a
eff.blue = self.b
eff.green = self.g
eff.red = self.r
eff.center = loc
eff.amplitude = 1
eff.end_with = 5
eff.start_width = 0.7
eff.life_time = 0.7
eff.start_radius = 300
eff.end_radius = 0.1
eff.model_index = blitz_model_index
eff.halo_index = blitz_halo_index
eff.create()

functions.emitsound(index_from_userid(self.userid), 'buttons/blip1.wav', 0.3, 0.7)

def stop(self):
self.repeat.stop()
del beacons[self.userid]

def create_beacon(userid, r=255, g=0, b=0, a=255):
if userid in beacons:
beacons[userid].stop()
beacons[userid] = Beacon(userid, r, g, b, a)

@Event('player_death')
def player_death(game_event):
userid = game_event.get_int('userid')
if userid in beacons:
beacons[userid].stop()

def blitz(index):
player = playerinfo_from_index(index)
vec1 = player.origin
vec2 = player.origin
vec1.z += 500
vec2.z += 5
functions.emitsound(index, 'npc/strider/fire.wav', 1.0, 0.6)

blitz_model_index = engine_server.precache_model('sprites/laserbeam.vmt')
blitz_halo_index = engine_server.precache_model('sprites/laserbeam.vmt')

for player in PlayerIter('human'):
index = player.index
steamid = player.steamid
if steamid not in settings or settings[steamid]['effects'] == 1:
#TempEntity('BeamPoints', (0, vec2, vec1, blitz_model_index, blitz_halo_index, 0, 1, 1, 3, 3, 3, 100, 113, 208, 255, 255, 0)).create()
eff = TempEntity('BeamPoints')
eff.alpha = 255
eff.blue = 255
eff.green = 208
eff.red = 113
eff.start_point = vec1
eff.amplitude = 3
eff.end_with = 3
eff.start_width = 3
eff.life_time = 3
eff.speed = 1
eff.end_point = vec2
eff.halo_index = blitz_halo_index
eff.model_index = blitz_model_index
eff.frame_rate = 1
eff.create()
sparks(index, player, vec2)
Delay(0.1, sparks, (index, player, vec2))
Delay(0.2, sparks, (index, player, vec2))
Delay(0.3, sparks, (index, player, vec2))
Delay(0.4, sparks, (index, player, vec2))
Delay(0.5, sparks, (index, player, vec2))
Delay(0.6, sparks, (index, player, vec2))
Delay(0.7, sparks, (index, player, vec2))
Delay(0.8, sparks, (index, player, vec2))
Delay(0.9, sparks, (index, player, vec2))
Delay(1.0, sparks, (index, player, vec2))

def sparks(index, player, pos, magnitude=20, length=5, dir=Vector(0,0,0), sound=False):
temp_ent = TempEntity('Sparks')
temp_ent.magnitude = magnitude
temp_ent.trail_length = length
temp_ent.direction = dir
temp_ent.origin = pos
temp_ent.create()

if sound:
sound = random.choice(spark_sounds)
functions.emitsound(index, sound, 0.5, 0.8)

def env_ar2(userid, material):
index = index_from_userid(userid)
player = PlayerEntity(index)
entity = Entity.create('env_ar2explosion')
entity.origin = player.origin
entity.set_key_value_string('material', material)
entity.call_input('Explode')
entity.remove()

def create_explosion(material, origin):
entity = Entity.create('env_ar2explosion')
entity.origin = origin
entity.set_key_value_string('material', material)
entity.call_input('Explode')
entity.remove()

def env_blood(userid, color=0):
player = PlayerEntity(index_from_userid(userid))
entity = Entity.create('env_blood')
origin = player.origin
origin.z += 60
entity.origin = origin
entity.set_key_value_int('spawnflags', 121)
entity.set_key_value_int('color', color)
entity.set_key_value_string('amount', '25')
#entity.set_key_value_int('flags', 2)
entity.call_input('EmitBlood')
entity.remove()

def white_fade(userid, seconds=2):
index = index_from_userid(userid)
functions.fade(index, color=Color(239, 239, 239, 150), hold_time=seconds, duration=1)
Fade(duration=1, hold_time=seconds, color=Color(239, 239, 239, 150)).send(index)

def shake(userid, magnitude, seconds):
index = index_from_userid(userid)
Shake(amplitude=magnitude, duration=seconds).send(index)

def ignite_ragdoll(userid):
inthandle = PlayerEntity(index_from_userid(userid)).ragdoll
if inthandle == INVALID_ENTITY_INTHANDLE:
return
entity = Entity(index_from_inthandle(inthandle))
entity.target_name = 'ragdoll_{0}'.format(userid)
entity.call_input('Ignite')
core.console_message('TESTTESTTEST')
Delay(10, dissolve_delay, (userid, 3))

def dissolve_ragdoll(userid, mode=1, seconds=1):
Delay(1.0, dissolve_delay, (userid, mode))

def dissolve_delay(userid, current_type):
"""Dissolve/remove the player's ragdoll."""
# Get the ragdoll entity
inthandle = PlayerEntity(index_from_userid(userid)).ragdoll
if inthandle == INVALID_ENTITY_INTHANDLE:
return
entity = Entity(index_from_inthandle(inthandle))


# Set the target name for the player's ragdoll
entity.target_name = 'ragdoll_{0}'.format(userid)

# Get the dissolver entity
dissolver_entity = Entity.find_or_create('env_entity_dissolver')

# Should a random dissolve type be chosen?

# Set the magnitude
dissolver_entity.magnitude = 1

# Set the dissolve type
dissolver_entity.dissolve_type = current_type

# Dissolve the ragdoll
dissolver_entity.dissolve('ragdoll_{0}'.format(userid))

def point_hurt(userid, damage, seconds=3):
player = PlayerEntity(index_from_userid(userid))
entity = Entity.create('point_hurt')
entity.origin = player.origin
entity.set_key_value_float('DamageRadius', 500)
entity.set_key_value_float('DamageDelay', 1)
entity.set_key_value_int('Damage', damage)
entity.set_key_value_int('DamageType', 8)
entity.call_input('TurnOn')
Delay(seconds, entity.remove)

def headshot_effect(userid):
player = PlayerEntity(index_from_userid(userid))
origin = Vector(player.origin.x, player.origin.y, player.origin.z + 70)

glow_sprite('exae/headshot/headshot_gore1.vmt', origin)
Delay(0.1, glow_sprite, ('exae/headshot/headshot_gore2.vmt', origin))
Delay(0.15, glow_sprite, ('exae/headshot/headshot_gore3.vmt', origin))
Delay(0.2, glow_sprite, ('exae/headshot/headshot_gore4.vmt', origin))
Delay(0.25, glow_sprite, ('exae/headshot/headshot_gore5.vmt', origin))
Delay(0.3, glow_sprite, ('exae/headshot/headshot_gore6.vmt', origin))
Delay(0.35, glow_sprite, ('exae/headshot/headshot_gore7.vmt', origin))
Delay(0.4, glow_sprite, ('exae/headshot/headshot_gore8.vmt', origin))
Delay(0.45, glow_sprite, ('exae/headshot/headshot_gore9.vmt', origin))
Delay(0.5, glow_sprite, ('exae/headshot/headshot_gore10.vmt', origin))
Delay(0.55, glow_sprite, ('exae/headshot/headshot_gore11.vmt', origin))

#if player.model.path == "models/police.mdl":
#handle = inthandle_from_userid(userid)
#for index in EntityIter('player_ragdoll'):
#entity = Entity(index)
#if entity.get_property_int('m_hPlayer') == handle:
#entity.set_model(Model('models/headless_body/metrocop.mdl'))

def glow_sprite(material, origin, life=0.1, size=0.2, brightness=255):
model_index = engine_server.precache_model(material)
for player in PlayerIter('human'):
index = player.index
eff = TempEntity("GlowSprite")
eff.brightness = brightness
eff.scale = size
eff.model_index = model_index
eff.life_time = life
eff.origin = origin
eff.create()


def death_effect(victim, attacker, weapon):
if weapon not in weapons:
dissolve_ragdoll(victim, random.randint(0,3), 6)
return

if 'effects' not in weapons[weapon]:
return

if 'dissolve' in weapons[weapon]['effects'] and weapons[weapon]['effects']['dissolve'] == 1:
dissolve_ragdoll(victim, random.randint(0,3), 6)

if 'ignite' in weapons[weapon]['effects'] and weapons[weapon]['effects']['ignite'] == 1:
ignite_ragdoll(victim)

if 'blood' in weapons[weapon]['effects'] and weapons[weapon]['effects']['blood'] == 1:
env_blood(victim)

if 'fire_ball' in weapons[weapon]['effects'] and weapons[weapon]['effects']['fire_ball'] == 1:
point_hurt(victim, 5, 6)
env_ar2(victim, 'effects/fire_cloud2.vmt')

if 'white_fade' in weapons[weapon]['effects'] and weapons[weapon]['effects']['white_fade'] == 1:
white_fade(victim, 2)

if 'shake' in weapons[weapon]['effects'] and weapons[weapon]['effects']['shake'] == 1:
distance = functions.distance(index_from_userid(victim), index_from_userid(attacker))
magnitude = (150 - distance) / 3
shake(attacker, magnitude, 5)

if 'material' in weapons[weapon]['effects'] and weapons[weapon]['effects']['material']:
env_ar2(victim, weapons[weapon]['effects']['material'])

if 'particle' in weapons[weapon]['effects'] and weapons[weapon]['effects']['particle']:
player = PlayerEntity(index_from_userid(victim))
create_particle(weapons[weapon]['effects']['particle'], player, False)

if 'emit_sound' in weapons[weapon]['effects'] and weapons[weapon]['effects']['emit_sound']:
if isinstance(weapons[weapon]['effects']['emit_sound'], list):
sound = random.choice(weapons[weapon]['effects']['emit_sound'])
functions.emitsound(index_from_userid(victim), sound, 1, 0.8)
else:
functions.emitsound(index_from_userid(victim), weapons[weapon]['effects']['emit_sound'], 1, 0.8)



@OnEntityCreated
def on_entity_created(entity):
if entity == -1:
return

classname = entity.classname
if classname == 'npc_antlion':
entity.remove()
if classname == 'env_explosion':
Delay(0.1, create_particle, ('fire_large_01', entity, False))


@OnEntityDeleted
def on_entity_deleted(base_entity):
global in_map_change
if base_entity == -1 or in_map_change:
return

try:
entity = base_entity
except:
return


if entity.classname in ('grenade_frag', 'grenade_mp5_contact', 'grenade_tripmine', 'grenade_satchel', 'grenade_rpg'):
create_particle('fire_large_01', entity, False)
create_particle('explosion_huge_burning_chunks', entity, False)

elif entity.classname == 'prop_combine_ball':
ent = Entity(entity.index)
create_explosion('particle/orbsmoke3.vtf', ent.origin)



def create_particle(particle, entity, attach=False):
p = Entity.create('info_particle_system')
p.set_key_value_string('effect_name', str(particle))
ent = Entity(entity.index)
p.origin = ent.origin
p.set_property_ushort('m_iEffectIndex', string_tables.ParticleEffectNames.add_string(particle))
if attach:
p.set_parent(parent, 0)
p.call_input('SetParentAttachment', 'forward')
p.call_input('Start')
Delay(1, p.remove)

def check_players(entity):
for player in PlayerIter('alive'):
#distance = functions.get_distance(entity.origin, player.origin)
#if distance > 6:
#continue
functions.overlay(player.index, 'particle/lens2.vmt')
Delay(1.3, functions.overlay, (player.index, 'particle/lens3.vmt'))
Delay(2.0, functions.overlay, (player.index, 'particle/lens4.vmt'))

def set_properties(entity):
try:

for model in modelreplacement[entity.classname]:
if model == entity.model.path:
entity.set_model(Model(modelreplacement[entity.classname][model]))
except:
pass
User avatar
Sam
Junior Member
Posts: 8
Joined: Tue Jul 03, 2018 3:00 pm
Location: Russian Federation
Contact:

Re: [HL2:DM] effects.py

Postby Sam » Sat Aug 03, 2019 9:50 pm

Syntax: Select all

import random

from entities import ServerNetworkable

from entities.entity import Entity
import core
from entities.helpers import edict_from_index
from entities.helpers import pointer_from_index
from entities.helpers import index_from_pointer
from entities.helpers import basehandle_from_index
from entities.helpers import index_from_inthandle

from entities.factories import factory_dictionary

from players.entity import Player as PlayerEntity
from players.helpers import index_from_userid
from players.helpers import playerinfo_from_index
from players.helpers import playerinfo_from_userid
from players.helpers import inthandle_from_userid
from entities.constants import DissolveType
from entities.constants import INVALID_ENTITY_INTHANDLE

from events import Event

from messages import Fade
from messages import Shake

from colors import Color

from effects.base import TempEntity
from engines.server import engine_server
from engines.precache import Model

from filters.recipients import RecipientFilter
from filters.players import PlayerIter
from filters.entities import EntityIter

from listeners import OnLevelInit
from listeners import OnEntityCreated
from listeners import OnEntityDeleted
from listeners.tick import Delay, Repeat

from mathlib import Vector
import math


from supermod import functions
from supermod.cfg.modelreplacement import modelreplacement
from supermod.cfg.weapons import weapons
from supermod.supermod import settings

from stringtables import string_tables
import core
beacons = {}

in_map_change = False
core.console_message("\n[Supermod] Effects loaded!")
spark_sounds = [
'ambient/energy/spark1.wav',
'ambient/energy/spark2.wav',
'ambient/energy/spark3.wav',
'ambient/energy/spark4.wav',
'ambient/energy/spark5.wav',
'ambient/energy/spark6.wav'
]

avaibles = set()

def unload():
for beacon in beacons:
beacons[beacon].stop()

@OnLevelInit
def map_start(mapname):
global in_map_change
in_map_change = True
#for beacon in beacons:
#beacons[beacon].stop()

@Event('player_disconnect')
def player_disconnect(game_event):
global avaibles
userid = game_event.get_int('userid')
tmp_avaibles = avaibles.copy()
for i in tmp_avaibles:
if i == userid:
avaibles.remove()
if userid in beacons:
beacons[userid].stop()

@Event('player_spawn')
def player_spawn(game_event):
global in_map_change
if in_map_change:
userid = game_event.get_int('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
if not player.dead:
in_map_change = False

@Event('player_activate')
def player_activate(game_event):
global avaibles
userid = game_event.get_int('userid')
avaibles.add(userid)

def UserID_Avaible(uid):
tmp_avaibles = avaibles.copy()
for i in tmp_avaibles:
if i == userid:
return True
return False

class Beacon(object):
def __init__(self, userid, r=255, g=0, b=0, a=255):
self.userid = userid
self.r = r
self.g = g
self.b = b
self.a = a
self.player = playerinfo_from_userid(userid)
self.repeat = Repeat(self.effect)
self.repeat.start(0.7, math.inf)

def effect(self):
loc = self.player.origin
loc.z += 5

blitz_model_index = engine_server.precache_model('sprites/laserbeam.vmt')
blitz_halo_index = engine_server.precache_model('sprites/laserbeam.vmt')

for player in PlayerIter('human'):
index = player.index
steamid = player.steamid
if steamid not in settings or settings[steamid]['effects'] == 1:
eff = TempEntity('BeamRingPoint')
eff.alpha = self.a
eff.blue = self.b
eff.green = self.g
eff.red = self.r
eff.center = loc
eff.amplitude = 1
eff.end_with = 5
eff.start_width = 0.7
eff.life_time = 0.7
eff.start_radius = 300
eff.end_radius = 0.1
eff.model_index = blitz_model_index
eff.halo_index = blitz_halo_index
eff.create()

functions.emitsound(index_from_userid(self.userid), 'buttons/blip1.wav', 0.3, 0.7)

def stop(self):
self.repeat.stop()
del beacons[self.userid]

def create_beacon(userid, r=255, g=0, b=0, a=255):
if userid in beacons:
beacons[userid].stop()
beacons[userid] = Beacon(userid, r, g, b, a)

@Event('player_death')
def player_death(game_event):
userid = game_event.get_int('userid')
if userid in beacons:
beacons[userid].stop()

def blitz(index):
player = playerinfo_from_index(index)
vec1 = player.origin
vec2 = player.origin
vec1.z += 500
vec2.z += 5
functions.emitsound(index, 'npc/strider/fire.wav', 1.0, 0.6)

blitz_model_index = engine_server.precache_model('sprites/laserbeam.vmt')
blitz_halo_index = engine_server.precache_model('sprites/laserbeam.vmt')

for player in PlayerIter('human'):
index = player.index
steamid = player.steamid
if steamid not in settings or settings[steamid]['effects'] == 1:
#TempEntity('BeamPoints', (0, vec2, vec1, blitz_model_index, blitz_halo_index, 0, 1, 1, 3, 3, 3, 100, 113, 208, 255, 255, 0)).create()
eff = TempEntity('BeamPoints')
eff.alpha = 255
eff.blue = 255
eff.green = 208
eff.red = 113
eff.start_point = vec1
eff.amplitude = 3
eff.end_with = 3
eff.start_width = 3
eff.life_time = 3
eff.speed = 1
eff.end_point = vec2
eff.halo_index = blitz_halo_index
eff.model_index = blitz_model_index
eff.frame_rate = 1
eff.create()
sparks(index, player, vec2)
Delay(0.1, sparks, (index, player, vec2))
Delay(0.2, sparks, (index, player, vec2))
Delay(0.3, sparks, (index, player, vec2))
Delay(0.4, sparks, (index, player, vec2))
Delay(0.5, sparks, (index, player, vec2))
Delay(0.6, sparks, (index, player, vec2))
Delay(0.7, sparks, (index, player, vec2))
Delay(0.8, sparks, (index, player, vec2))
Delay(0.9, sparks, (index, player, vec2))
Delay(1.0, sparks, (index, player, vec2))

def sparks(index, player, pos, magnitude=20, length=5, dir=Vector(0,0,0), sound=False):
temp_ent = TempEntity('Sparks')
temp_ent.magnitude = magnitude
temp_ent.trail_length = length
temp_ent.direction = dir
temp_ent.origin = pos
temp_ent.create()

if sound:
sound = random.choice(spark_sounds)
functions.emitsound(index, sound, 0.5, 0.8)

def env_ar2(userid, material):
index = index_from_userid(userid)
player = PlayerEntity(index)
entity = Entity.create('env_ar2explosion')
entity.origin = player.origin
entity.set_key_value_string('material', material)
entity.call_input('Explode')
entity.remove()

def create_explosion(material, origin):
entity = Entity.create('env_ar2explosion')
entity.origin = origin
entity.set_key_value_string('material', material)
entity.call_input('Explode')
entity.remove()

def env_blood(userid, color=0):
player = PlayerEntity(index_from_userid(userid))
entity = Entity.create('env_blood')
origin = player.origin
origin.z += 60
entity.origin = origin
entity.set_key_value_int('spawnflags', 121)
entity.set_key_value_int('color', color)
entity.set_key_value_string('amount', '25')
#entity.set_key_value_int('flags', 2)
entity.call_input('EmitBlood')
entity.remove()

def white_fade(userid, seconds=2):
index = index_from_userid(userid)
functions.fade(index, color=Color(239, 239, 239, 150), hold_time=seconds, duration=1)
Fade(duration=1, hold_time=seconds, color=Color(239, 239, 239, 150)).send(index)

def shake(userid, magnitude, seconds):
index = index_from_userid(userid)
Shake(amplitude=magnitude, duration=seconds).send(index)

def ignite_ragdoll(userid):
inthandle = PlayerEntity(index_from_userid(userid)).ragdoll
if inthandle == INVALID_ENTITY_INTHANDLE:
return
entity = Entity(index_from_inthandle(inthandle))
entity.target_name = 'ragdoll_{0}'.format(userid)
entity.call_input('Ignite')
core.console_message('TESTTESTTEST')
Delay(10, dissolve_delay, (userid, 3))

def dissolve_ragdoll(userid, mode=1, seconds=1):
Delay(1.0, dissolve_delay, (userid, mode))

def dissolve_delay(userid, current_type):
"""Dissolve/remove the player's ragdoll."""
# Get the ragdoll entity
if UserID_Avaible(userid):
inthandle = PlayerEntity(index_from_userid(userid)).ragdoll
if inthandle == INVALID_ENTITY_INTHANDLE:
return
entity = Entity(index_from_inthandle(inthandle))


# Set the target name for the player's ragdoll
entity.target_name = 'ragdoll_{0}'.format(userid)

# Get the dissolver entity
dissolver_entity = Entity.find_or_create('env_entity_dissolver')

# Should a random dissolve type be chosen?

# Set the magnitude
dissolver_entity.magnitude = 1

# Set the dissolve type
dissolver_entity.dissolve_type = current_type

# Dissolve the ragdoll
dissolver_entity.dissolve('ragdoll_{0}'.format(userid))

def point_hurt(userid, damage, seconds=3):
player = PlayerEntity(index_from_userid(userid))
entity = Entity.create('point_hurt')
entity.origin = player.origin
entity.set_key_value_float('DamageRadius', 500)
entity.set_key_value_float('DamageDelay', 1)
entity.set_key_value_int('Damage', damage)
entity.set_key_value_int('DamageType', 8)
entity.call_input('TurnOn')
Delay(seconds, entity.remove)

def headshot_effect(userid):
player = PlayerEntity(index_from_userid(userid))
origin = Vector(player.origin.x, player.origin.y, player.origin.z + 70)

glow_sprite('exae/headshot/headshot_gore1.vmt', origin)
Delay(0.1, glow_sprite, ('exae/headshot/headshot_gore2.vmt', origin))
Delay(0.15, glow_sprite, ('exae/headshot/headshot_gore3.vmt', origin))
Delay(0.2, glow_sprite, ('exae/headshot/headshot_gore4.vmt', origin))
Delay(0.25, glow_sprite, ('exae/headshot/headshot_gore5.vmt', origin))
Delay(0.3, glow_sprite, ('exae/headshot/headshot_gore6.vmt', origin))
Delay(0.35, glow_sprite, ('exae/headshot/headshot_gore7.vmt', origin))
Delay(0.4, glow_sprite, ('exae/headshot/headshot_gore8.vmt', origin))
Delay(0.45, glow_sprite, ('exae/headshot/headshot_gore9.vmt', origin))
Delay(0.5, glow_sprite, ('exae/headshot/headshot_gore10.vmt', origin))
Delay(0.55, glow_sprite, ('exae/headshot/headshot_gore11.vmt', origin))

#if player.model.path == "models/police.mdl":
#handle = inthandle_from_userid(userid)
#for index in EntityIter('player_ragdoll'):
#entity = Entity(index)
#if entity.get_property_int('m_hPlayer') == handle:
#entity.set_model(Model('models/headless_body/metrocop.mdl'))

def glow_sprite(material, origin, life=0.1, size=0.2, brightness=255):
model_index = engine_server.precache_model(material)
for player in PlayerIter('human'):
index = player.index
eff = TempEntity("GlowSprite")
eff.brightness = brightness
eff.scale = size
eff.model_index = model_index
eff.life_time = life
eff.origin = origin
eff.create()


def death_effect(victim, attacker, weapon):
if weapon not in weapons:
dissolve_ragdoll(victim, random.randint(0,3), 6)
return

if 'effects' not in weapons[weapon]:
return

if 'dissolve' in weapons[weapon]['effects'] and weapons[weapon]['effects']['dissolve'] == 1:
dissolve_ragdoll(victim, random.randint(0,3), 6)

if 'ignite' in weapons[weapon]['effects'] and weapons[weapon]['effects']['ignite'] == 1:
ignite_ragdoll(victim)

if 'blood' in weapons[weapon]['effects'] and weapons[weapon]['effects']['blood'] == 1:
env_blood(victim)

if 'fire_ball' in weapons[weapon]['effects'] and weapons[weapon]['effects']['fire_ball'] == 1:
point_hurt(victim, 5, 6)
env_ar2(victim, 'effects/fire_cloud2.vmt')

if 'white_fade' in weapons[weapon]['effects'] and weapons[weapon]['effects']['white_fade'] == 1:
white_fade(victim, 2)

if 'shake' in weapons[weapon]['effects'] and weapons[weapon]['effects']['shake'] == 1:
distance = functions.distance(index_from_userid(victim), index_from_userid(attacker))
magnitude = (150 - distance) / 3
shake(attacker, magnitude, 5)

if 'material' in weapons[weapon]['effects'] and weapons[weapon]['effects']['material']:
env_ar2(victim, weapons[weapon]['effects']['material'])

if 'particle' in weapons[weapon]['effects'] and weapons[weapon]['effects']['particle']:
player = PlayerEntity(index_from_userid(victim))
create_particle(weapons[weapon]['effects']['particle'], player, False)

if 'emit_sound' in weapons[weapon]['effects'] and weapons[weapon]['effects']['emit_sound']:
if isinstance(weapons[weapon]['effects']['emit_sound'], list):
sound = random.choice(weapons[weapon]['effects']['emit_sound'])
functions.emitsound(index_from_userid(victim), sound, 1, 0.8)
else:
functions.emitsound(index_from_userid(victim), weapons[weapon]['effects']['emit_sound'], 1, 0.8)



@OnEntityCreated
def on_entity_created(entity):
if entity == -1:
return

classname = entity.classname
if classname == 'npc_antlion':
entity.remove()
if classname == 'env_explosion':
Delay(0.1, create_particle, ('fire_large_01', entity, False))


@OnEntityDeleted
def on_entity_deleted(base_entity):
global in_map_change
if base_entity == -1 or in_map_change:
return

try:
entity = base_entity
except:
return


if entity.classname in ('grenade_frag', 'grenade_mp5_contact', 'grenade_tripmine', 'grenade_satchel', 'grenade_rpg'):
create_particle('fire_large_01', entity, False)
create_particle('explosion_huge_burning_chunks', entity, False)

elif entity.classname == 'prop_combine_ball':
ent = Entity(entity.index)
create_explosion('particle/orbsmoke3.vtf', ent.origin)



def create_particle(particle, entity, attach=False):
p = Entity.create('info_particle_system')
p.set_key_value_string('effect_name', str(particle))
ent = Entity(entity.index)
p.origin = ent.origin
p.set_property_ushort('m_iEffectIndex', string_tables.ParticleEffectNames.add_string(particle))
if attach:
p.set_parent(parent, 0)
p.call_input('SetParentAttachment', 'forward')
p.call_input('Start')
Delay(1, p.remove)

def check_players(entity):
for player in PlayerIter('alive'):
#distance = functions.get_distance(entity.origin, player.origin)
#if distance > 6:
#continue
functions.overlay(player.index, 'particle/lens2.vmt')
Delay(1.3, functions.overlay, (player.index, 'particle/lens3.vmt'))
Delay(2.0, functions.overlay, (player.index, 'particle/lens4.vmt'))

def set_properties(entity):
try:

for model in modelreplacement[entity.classname]:
if model == entity.model.path:
entity.set_model(Model(modelreplacement[entity.classname][model]))
except:
pass


Added `UserID_Avaible` function.
Added `player_activate` function.
Added `avaibles` table.
And other.

To get access to data other than UserID, it is necessary that the player be loaded. Also, a player’s exit from the server may be a mistake, and in the meantime, the script considers that it is still on the server. (My english is bad)
It's a trap!
User avatar
L'In20Cible
Project Leader
Posts: 1154
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [HL2:DM] effects.py

Postby L'In20Cible » Sat Aug 03, 2019 10:18 pm

Sam wrote:To get access to data other than UserID, it is necessary that the player be loaded. Also, a player’s exit from the server may be a mistake, and in the meantime, the script considers that it is still on the server. (My english is bad)

This could have been fixed by replacing the following:

Syntax: Select all

def dissolve_ragdoll(userid, mode=1, seconds=1):
Delay(1.0, dissolve_delay, (userid, mode))

With:

Syntax: Select all

def dissolve_ragdoll(userid, mode=1, seconds=1):
PlayerEntity.from_userid(userid).delay(1.0, dissolve_delay, (userid, mode))

PlayerEntity.delay takes care of canceling any pending delays tied to that specific player when it becomes unavailable (disconnect, map change, etc.).

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 3 guests