hl2dm crossbow arrows with a fire flame.

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

Please request only one plugin per thread.
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: hl2dm crossbow arrows with a fire flame.

Postby VinciT » Sun Oct 11, 2020 4:51 pm

daren adler wrote:I get this now

Code: Select all

2020-10-10 16:26:58 - sp   -   EXCEPTION   
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\entities\dictionary.py", line 135, in _on_networked_entity_deleted
    self.on_automatically_removed(index)
  File "..\addons\source-python\plugins\fiery_bolts\fiery_bolts.py", line 30, in on_automatically_removed
    self[index].detach_effects()
  File "..\addons\source-python\plugins\fiery_bolts\fiery_bolts.py", line 185, in detach_effects
    self.trail.clear_parent()
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 216, in __getattr__
    value = getattr(instance, attr)
  File "..\addons\source-python\packages\source-python\entities\classes.py", line 542, in fget
    return InputFunction(desc, make_object(BaseEntity, pointer))

I think I was a little overzealous with the detachment of effects. The detach_effects() call inside the start_touch hook was probably unnecessary - so I went ahead and removed it. Get the updated plugin and tell me if you get the same error again. :smile:
ImageImageImageImageImage
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: hl2dm crossbow arrows with a fire flame.

Postby daren adler » Sun Oct 11, 2020 5:37 pm

VinciT wrote:
daren adler wrote:I get this now

Code: Select all

2020-10-10 16:26:58 - sp   -   EXCEPTION   
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\entities\dictionary.py", line 135, in _on_networked_entity_deleted
    self.on_automatically_removed(index)
  File "..\addons\source-python\plugins\fiery_bolts\fiery_bolts.py", line 30, in on_automatically_removed
    self[index].detach_effects()
  File "..\addons\source-python\plugins\fiery_bolts\fiery_bolts.py", line 185, in detach_effects
    self.trail.clear_parent()
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 216, in __getattr__
    value = getattr(instance, attr)
  File "..\addons\source-python\packages\source-python\entities\classes.py", line 542, in fget
    return InputFunction(desc, make_object(BaseEntity, pointer))

I think I was a little overzealous with the detachment of effects. The detach_effects() call inside the start_touch hook was probably unnecessary - so I went ahead and removed it. Get the updated plugin and tell me if you get the same error again. :smile:


Ok i will,,thank you. update NO errors, thank you
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: hl2dm crossbow arrows with a fire flame.

Postby daren adler » Thu Oct 15, 2020 3:45 am

I am not getting errors no more :cool: . What i would like to know is, "how could i have the fire not burn as long on a player?" I am asking becouse when you are set on fire from a bot and you killed him, but the fire would not go out even after i went and found health lying around on the map, but the fire kept burning and burning untill u die from it, just asking if the fire could not burn as long. Thank you :smile:
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: hl2dm crossbow arrows with a fire flame.

Postby VinciT » Thu Oct 15, 2020 5:45 pm

Sure thing, I've added two options you can change to your liking:

Syntax: Select all

# ../fiery_bolts/fiery_bolts.py

# Python
import random

# Source.Python
from engines.precache import Model
from engines.sound import Sound
from entities.constants import (EntityStates, RenderMode, RenderEffects,
MoveType, WORLD_ENTITY_INDEX)
from entities.dictionary import EntityDictionary
from entities.entity import Entity
from entities.helpers import index_from_pointer
from entities.hooks import EntityPreHook, EntityCondition
from events import Event
from listeners import OnNetworkedEntityCreated, OnEntityOutput
from players.entity import Player
from stringtables import string_tables


# How long should entities burn for after being hit by a bolt? (in seconds)
BURN_DURATION = 10
# Should the player stop burning after they pick up a health item? (True/False)
EXTINGUISH_ON_PICKUP = True


# Material/sprite used for the trail.
TRAIL_MODEL = Model('materials/sprites/laser.vmt')


class Bolts(EntityDictionary):
"""Modified EntityDictionary class for storing Bolt instances."""

def on_automatically_removed(self, index):
"""Called when an index is automatically removed."""
self[index].detach_effects()


class BoltEffects(EntityDictionary):
"""Class used for cleaning up after the particle and trail effects."""

def on_automatically_removed(self, index):
"""Called when an index is automatically removed."""
effect = self[index]

try:
# Try to get the Bolt instance the effect was parented to.
bolt = bolts.from_inthandle(effect.parent_inthandle)
except (KeyError, OverflowError):
# KeyError: Bolt instance no longer exists.
# OverflowError: Invalid parent_inthandle (-1).
return

# Remove the reference to the removed effect from the Bolt instance.
setattr(
object=bolt,
name='flame' if 'particle' in effect.classname else 'trail',
value=None
)


# Dictionary used to store Bolt instances.
bolts = Bolts(None)

# Dictionary used to store Entity instances for 'info_particle_system' and
# 'env_sprite_trail' entities.
bolt_effects = BoltEffects(None)


is_crossbow_bolt = EntityCondition.equals_entity_classname('crossbow_bolt')
_healing_items = ('item_healthkit', 'item_healthvial')


@Event('player_death')
def player_death(event):
"""Called when a player dies."""
player = Player.from_userid(event['userid'])
# Was the player on fire prior to dying?
if player.get_property_int('m_fFlags') & EntityStates.ONFIRE:
# Extinguish them.
player.ignite_lifetime(0)


@OnNetworkedEntityCreated
def on_networked_entity_created(entity):
"""Called when a networked entity gets created."""
if 'crossbow_bolt' not in entity.classname:
return

# Create a Bolt instance.
bolt = Bolt(entity.index)
# Some properties are still uninitialized - delay the creation of the
# flame effect for a single frame.
bolt.delay(0, bolt.flame_on)


@OnEntityOutput
def on_entity_output(output, activator, caller, value, delay):
"""Called when an entity fires an output."""
if output != 'OnPlayerTouch':
return

# Was one of the healing items (item_healthkit, item_healthvial) picked up?
if caller.classname in _healing_items and EXTINGUISH_ON_PICKUP:
# Is the player on fire?
if activator.get_property_int('m_fFlags') & EntityStates.ONFIRE:
activator.ignite_lifetime(0)


@EntityPreHook(is_crossbow_bolt, 'start_touch')
def start_touch_pre(stack_data):
try:
bolt = bolts[index_from_pointer(stack_data[0])]
except KeyError:
return

index = index_from_pointer(stack_data[1])
# Did the bolt hit the world?
if index == WORLD_ENTITY_INDEX:
return

try:
# Try to ignite the entity that was hit.
Entity(index).ignite_lifetime(BURN_DURATION)
except AttributeError:
pass


class Bolt(Entity):
"""Extended Entity class for manipulating the 'crossbow_bolt' entity.

Args:
index (int): A valid Entity index.
caching (bool): Check for a cached instance?

Attributes:
flame (Entity): Instance of the 'info_particle_system' entity.
trail (Entity): Instance of the 'env_sprite_trail' entity.
sound (Sound): Looping sound used for the projectile.
"""
# Alternative particle effects:
# burning_engine_fire
# burning_gib_01
# burning_gib_01_follower1
# burning_gib_01_follower2
# fire_medium_02_nosmoke
# fire_small_02
# fire_small_03
effect_name = 'fire_small_01'
# Colors used for the bolt trail.
trail_colors = ('255 162 2', '255 95 12', '255 129 33', '255 100 0')

def __init__(self, index, caching=True):
"""Initializes the object."""
super().__init__(index, caching)

self.flame = None
self.trail = None
self.sound = Sound(
sample=f'ambient/fire/fire_small_loop{random.randint(1, 2)}.wav',
index=index,
attenuation=0.85
)

# Add the Bolt instance to the dictionary.
bolts[index] = self

def flame_on(self):
"""Creates the fire particle effect, as well as the sprite trail."""
self.flame = Entity.create('info_particle_system')
self.flame.effect_name = Bolt.effect_name
self.flame.effect_index = string_tables.ParticleEffectNames.add_string(
Bolt.effect_name)

self.flame.origin = self.origin
self.flame.set_parent(self)
self.flame.start()
# Save the 'info_particle_system' instance in a dictionary.
bolt_effects[self.flame.index] = self.flame

self.trail = create_sprite_trail(
origin=self.origin,
sprite_path=TRAIL_MODEL.path,
start_width=15,
end_width=5,
color_str=random.choice(Bolt.trail_colors),
life_time=1
)

self.trail.set_parent(self)
# Save the 'env_sprite_trail' instance in a dictionary.
bolt_effects[self.trail.index] = self.trail

self.sound.play()

def detach_effects(self):
"""Detaches the particle effect and trail from the bolt."""
# Save the last known position of the bolt.
last_origin = self.origin

try:
# Try to detach the sprite trail.
self.trail.clear_parent()
self.trail.teleport(origin=last_origin)
# Freeze it in place.
self.trail.move_type = MoveType.NONE
# Remove it after a short delay.
self.trail.delay(1.5, self.trail.remove)
except AttributeError:
pass

try:
# Try to detach the particle effect.
self.flame.clear_parent()
self.flame.teleport(origin=last_origin)
self.flame.move_type = MoveType.NONE
self.flame.delay(1.2, self.flame.remove)
except AttributeError:
pass

# Stop the looping sound.
self.sound.stop()


def create_sprite_trail(
origin, sprite_path, start_width, end_width, color_str, life_time):
"""Creates an 'env_spritetrail' entity.

Args:
origin (Vector): Spawn position.
sprite_path (string): Path to the sprite material.
start_width (float): Starting width of the trail.
end_width (float): Ending width of the trail.
color_str (str): String containing the RGB values of the color.
(e.g. '255 255 255' for white)
life_time (float): How long does the trail last before it starts to
fade (in seconds)?

Returns:
Entity: The entity instance of the created 'env_spritetrail'.

"""
trail = Entity.create('env_spritetrail')
trail.sprite_name = sprite_path
trail.origin = origin

trail.life_time = life_time
trail.start_width = start_width
trail.end_width = end_width

trail.render_mode = RenderMode.TRANS_ADD
trail.render_amt = 255
trail.render_fx = RenderEffects.NONE
trail.set_key_value_string('rendercolor', color_str)
trail.spawn()

# Texture resolution of the trail.
trail.texture_res = 0.05
return trail
ImageImageImageImageImage
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: hl2dm crossbow arrows with a fire flame.

Postby daren adler » Thu Oct 15, 2020 11:22 pm

:smile: :smile: Thank you, works great. :grin:

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 15 guests