HL2DM Sawblade Trail

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

Please request only one plugin per thread.
User avatar
daren adler
Member
Posts: 65
Joined: Sat May 18, 2019 7:42 pm
Contact:

HL2DM Sawblade Trail

Postby daren adler » Sun May 24, 2020 12:18 am

Hello SourcePython Team and Community,
Would it be possible to make a SP for me in my hl2dm server for my sawblades to have trails like you can have for the gernades?( a beam or smoke)
Would it be possible? Thank YOU in Advance.
User avatar
VinciT
Senior Member
Posts: 175
Joined: Thu Dec 18, 2014 2:41 am

Re: HL2DM Sawblade Trail

Postby VinciT » Wed Jun 03, 2020 10:29 pm

Hi daren, give this a try:

Syntax: Select all

# ../sawblade_trail/sawblade_trail.py

# Source.Python
from engines.precache import Model
from entities.constants import RenderEffects, RenderMode
from entities.dictionary import EntityDictionary
from entities.entity import Entity
from listeners import OnEntityOutput


SAW_MODEL = Model('models/props_junk/sawblade001a.mdl')
TRAIL_MODEL = Model('materials/sprites/bluelaser1.vmt')


class Sawblade(Entity):
"""Extended Entity class with basic trail capabilities."""

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

def initialize_trail(self):
if self.trail:
return

self.trail = create_sprite_trail(
self.origin, TRAIL_MODEL.path, 8, 1, '255 0 0', 0.5)
self.trail.set_parent(self, -1)

def remove_trail(self, delay=0):
if not self.trail:
return

self.trail.delay(delay, self.trail.remove)
self.trail = None


sawblade_instances = EntityDictionary(Sawblade)


@OnEntityOutput
def on_entity_output(output, activator, caller, value, delay):
# Is this not one of the outputs we're looking for?
if output not in ('OnPhysGunDrop', 'OnTakeDamage'):
return

# Don't go further if this entity doesn't have the sawblade model.
if caller.model.path != SAW_MODEL.path:
return

sawblade = sawblade_instances[caller.index]

# Was the entity dropped or thrown?
if output == 'OnPhysGunDrop':
# Check with how much force it was dropped/thrown. It's safe to say
# it was thrown if the force is relatively high.
if sawblade.physics_object.velocity[1].length >= 2000:
sawblade.initialize_trail()

# Did the entity hit something?
if output == 'OnTakeDamage':
# Don't remove the trail if the player does damage to the sawblade
# with their weapons.
if 'player' in activator.classname:
return

sawblade.remove_trail(delay=1)


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
Member
Posts: 65
Joined: Sat May 18, 2019 7:42 pm
Contact:

Re: HL2DM Sawblade Trail

Postby daren adler » Thu Jun 04, 2020 6:40 pm

OK i will give it a try, thank you so much. Yes i check it and works great,,,at first it didnot but it was becouse this models/exile_models/props_junk/sawblade001a.mdl is what i am using as a sawblade(made for me by someone) and this models/props_junk/sawblade001a.mdl is the normal one,,all i had to do was change it to the exile one and boom it worked like it should. Thank you for all your help.
User avatar
VinciT
Senior Member
Posts: 175
Joined: Thu Dec 18, 2014 2:41 am

Re: HL2DM Sawblade Trail

Postby VinciT » Thu Jun 04, 2020 7:24 pm

Nice! Glad you managed to make it work. :smile:
ImageImageImageImageImage

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 3 guests