Page 1 of 1

HL2DM - Grenade trails

Posted: Wed Dec 09, 2020 2:36 am
by daren adler
Hello scripters :smile: . Could i get a Grenade trail that the color of the trail changes color every now and then?. Thank you for your help on all the scripts i get from here :cool: :cool: :cool:

Re: HL2DM - Grenade trails

Posted: Wed Dec 09, 2020 3:41 am
by satoon101
This plugin does the trail, and it should work for HL2DM, but not necessarily with the changing color feature:

viewtopic.php?f=7&t=1806

Do you mean the same trail mid arch changes color or just player 1 throws a nade and it has 1 trail color, then later throws another with a different color?

The script should be easily expanded, but I haven't really done much in SP in quite some time.

Re: HL2DM - Grenade trails

Posted: Wed Dec 09, 2020 4:22 am
by daren adler
satoon101 wrote:This plugin does the trail, and it should work for HL2DM, but not necessarily with the changing color feature:

viewtopic.php?f=7&t=1806

Do you mean the same trail mid arch changes color or just player 1 throws a nade and it has 1 trail color, then later throws another with a different color?

The script should be easily expanded, but I haven't really done much in SP in quite some time.


this way yes -- throws a nade and it has 1 trail color, then later throws another with a different color.

Re: HL2DM - Grenade trails

Posted: Wed Dec 09, 2020 4:40 am
by VinciT
I remember making something like this for Painkiller a few months back. I believe this should work:

Syntax: Select all

# ../nade_trail/nade_trail.py

# Python
from colorsys import hsv_to_rgb
from random import choice

# Source.Python
from colors import Color
from engines.precache import Model
from entities.entity import Entity
from listeners import OnNetworkedEntitySpawned


pretty_colors = []
glow_replacement = Model('sprites/physcannon_blueglow.vmt')


def load():
"""Called when the plugin gets loaded."""
pretty_colors.extend(get_pretty_colors(amount=10))


def change_trail_color(grenade, color_raw):
"""Changes the color of the 'npc_grenade_frag' glow and trail.

Args:
grenade (Entity): Entity instance of the 'npc_grenade_frag'.
color_raw (int): Long (raw) color code.
"""
glow = Entity.from_inthandle(grenade.main_glow)
# The default sprite ('sprites/redglow1.vmt') is almost always going to
# look red, so let's replace it.
glow.model = glow_replacement
trail = Entity.from_inthandle(grenade.glow_trail)
# Change the colors of the 'glow' and the 'trail'.
glow.set_network_property_int('m_clrRender', color_raw)
trail.set_network_property_int('m_clrRender', color_raw)


@OnNetworkedEntitySpawned
def on_networked_entity_spawned(entity):
"""Called when a new networked entity has been spawned."""
# Is this a grenade?
if 'npc_grenade_frag' in entity.classname:
# The grenade isn't fully initialized, delay the change for a frame.
entity.delay(
0, change_trail_color, (entity, choice(pretty_colors).raw))


class ColorEx(Color):
"""Extended Color class."""

def __init__(self, r, g, b, a=255):
"""Initializes the object."""
super().__init__(r, g, b, a)

raw = r + (g << 8) + (b << 16) + (a << 24)
self.raw = raw - 2**32 if raw >= 2**31 else raw


def get_pretty_colors(amount):
"""Returns a list of vibrant colors.

Args:
amount (int): How many colors should be generated?

Returns:
list of ColorEx: A list containing ColorEx instances.
"""
colors = []
step = 1 / amount

for hue in range(0, amount):
colors.append(
ColorEx(*(int(255 * x) for x in hsv_to_rgb(step * hue, 1, 1))))

return colors

Re: HL2DM - Grenade trails

Posted: Wed Dec 09, 2020 8:00 am
by daren adler
VinciT wrote:I remember making something like this for Painkiller a few months back. I believe this should work:

Syntax: Select all

# ../nade_trail/nade_trail.py

# Python
from colorsys import hsv_to_rgb
from random import choice

# Source.Python
from colors import Color
from engines.precache import Model
from entities.entity import Entity
from listeners import OnNetworkedEntitySpawned


pretty_colors = []
glow_replacement = Model('sprites/physcannon_blueglow.vmt')


def load():
"""Called when the plugin gets loaded."""
pretty_colors.extend(get_pretty_colors(amount=10))


def change_trail_color(grenade, color_raw):
"""Changes the color of the 'npc_grenade_frag' glow and trail.

Args:
grenade (Entity): Entity instance of the 'npc_grenade_frag'.
color_raw (int): Long (raw) color code.
"""
glow = Entity.from_inthandle(grenade.main_glow)
# The default sprite ('sprites/redglow1.vmt') is almost always going to
# look red, so let's replace it.
glow.model = glow_replacement
trail = Entity.from_inthandle(grenade.glow_trail)
# Change the colors of the 'glow' and the 'trail'.
glow.set_network_property_int('m_clrRender', color_raw)
trail.set_network_property_int('m_clrRender', color_raw)


@OnNetworkedEntitySpawned
def on_networked_entity_spawned(entity):
"""Called when a new networked entity has been spawned."""
# Is this a grenade?
if 'npc_grenade_frag' in entity.classname:
# The grenade isn't fully initialized, delay the change for a frame.
entity.delay(
0, change_trail_color, (entity, choice(pretty_colors).raw))


class ColorEx(Color):
"""Extended Color class."""

def __init__(self, r, g, b, a=255):
"""Initializes the object."""
super().__init__(r, g, b, a)

raw = r + (g << 8) + (b << 16) + (a << 24)
self.raw = raw - 2**32 if raw >= 2**31 else raw


def get_pretty_colors(amount):
"""Returns a list of vibrant colors.

Args:
amount (int): How many colors should be generated?

Returns:
list of ColorEx: A list containing ColorEx instances.
"""
colors = []
step = 1 / amount

for hue in range(0, amount):
colors.append(
ColorEx(*(int(255 * x) for x in hsv_to_rgb(step * hue, 1, 1))))

return colors



OK, thank you very much :cool: . ill get on it tomarow bud, again thanks alot :smile: :smile: Great work.