



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.
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
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
Users browsing this forum: No registered users and 57 guests