Page 1 of 1
Colored Smoke
Posted: Tue Sep 23, 2014 6:12 pm
by BackRaw
Hi guys,
I remember using EventScripts it was possible to spawn smoke on the map (either an entity or the smokegrenade's smoke somehow) and change its color, I guess it was some kind of a toxic gas addon.
Can we do some type of this using SP yet?
Posted: Tue Sep 23, 2014 7:46 pm
by L'In20Cible
If it was possible with EventScripts, it's possible with Source.Python.
Posted: Tue Sep 23, 2014 8:05 pm
by Ayuto
The effects package provides two methods to spawn smoke. But you could also create an env_smoke or a smokegrenade.
Posted: Wed Sep 24, 2014 7:23 am
by BackRaw
Ayuto wrote:The effects package provides two methods to spawn smoke. But you could also create an env_smoke or a smokegrenade.
Cool. How would I go about detonating the smokegrenade and change the smoke's color?
Posted: Wed Sep 24, 2014 8:54 am
by L'In20Cible
The following code seems to work on Counter-Strike: Source.
Syntax: Select all
from events import Event
from players.helpers import playerinfo_from_userid
from tools import server_tools
from mathlib import Vector
from entities.entity import BaseEntity
from listeners.tick import tick_delays
def create_smoke(origin, fade_start=15, duration=20):
entity = BaseEntity(
server_tools.create_entity('env_particlesmokegrenade'))
entity.set_key_value_vector('origin', origin)
entity.set_prop_float('m_FadeStartTime', fade_start)
entity.set_prop_float('m_FadeEndTime', duration)
server_tools.spawn_entity(entity.index)
# The game is setting this to 0 the time to play the detonating sound and
# then, set it to 1 to render the smoke effect...
entity.set_prop_int('m_CurrentStage', 1)
# Here we should take care to store the delay and cancel it when the
# current round is ending to avoid removing an invalid entity...
tick_delays.delay(duration, server_tools.remove_entity, entity.index)
@Event
def player_jump(game_event):
origin = playerinfo_from_userid(
game_event.get_int('userid')).get_abs_origin()
# Create a smoke effect that start fading after 1 second and get removed
# after 5 seconds...
create_smoke(origin, 1, 5)
However, you cannot change the color of this entity. If you want a green colored smoke, you will have to reproduce the entire effect using env_smokestack or either simulate the color using a env_spotlight.
Posted: Wed Sep 24, 2014 7:05 pm
by qazuar
server_tools.remove_entity seems to crash on CSGO, atleast in my case it does.
Posted: Wed Sep 24, 2014 7:28 pm
by Hedgehog
Instead of server_tools.remove_entity you should use
because it's more stable (at least n CS:S).
Posted: Wed Sep 24, 2014 7:46 pm
by L'In20Cible
qazuar wrote:server_tools.remove_entity seems to crash on CSGO, atleast in my case it does.
Interesting. Could you please test the following and let me know if that fixes the crashes?
Syntax: Select all
entity.set_key_value_int('hammerid', entity.index)
server_tools.remove_entity(entity.index)
Posted: Wed Sep 24, 2014 7:59 pm
by L'In20Cible
Hedgehog wrote:Instead of server_tools.remove_entity you should use
because it's more stable (at least n CS:S).
It is not fully right. It was, on EventScripts cause it was relying on a client executing the cheat command ent_fire on a valid target name (which means no entity was killed if the name was not matching any entity while looking for it). But on SP, we are parsing the datamap of the entity and call the CBaseEntity::InputKill function dynamically and if you check that function, you will see that it does nothing else than noticing owner and calling UTIL_Remove (which is wrapped by IServerTools::RemoveEntity) on the given pointer.
Posted: Thu Sep 25, 2014 4:19 pm
by qazuar
Setting the hammerid seems to solve the problem, no more crashing.
Posted: Thu Sep 25, 2014 4:24 pm
by L'In20Cible
Alright, then the SDK is lying. I will fix that later tonight, thanks for testing!
EDIT: Done.
Posted: Thu Sep 25, 2014 9:30 pm
by BackRaw
L'In20Cible wrote:The following code seems to work on Counter-Strike: Source.
Syntax: Select all
from events import Event
from players.helpers import playerinfo_from_userid
from tools import server_tools
from mathlib import Vector
from entities.entity import BaseEntity
from listeners.tick import tick_delays
def create_smoke(origin, fade_start=15, duration=20):
entity = BaseEntity(
server_tools.create_entity('env_particlesmokegrenade'))
entity.set_key_value_vector('origin', origin)
entity.set_prop_float('m_FadeStartTime', fade_start)
entity.set_prop_float('m_FadeEndTime', duration)
server_tools.spawn_entity(entity.index)
# The game is setting this to 0 the time to play the detonating sound and
# then, set it to 1 to render the smoke effect...
entity.set_prop_int('m_CurrentStage', 1)
# Here we should take care to store the delay and cancel it when the
# current round is ending to avoid removing an invalid entity...
tick_delays.delay(duration, server_tools.remove_entity, entity.index)
@Event
def player_jump(game_event):
origin = playerinfo_from_userid(
game_event.get_int('userid')).get_abs_origin()
# Create a smoke effect that start fading after 1 second and get removed
# after 5 seconds...
create_smoke(origin, 1, 5)
However, you cannot change the color of this entity. If you want a green colored smoke, you will have to reproduce the entire effect using env_smokestack or either simulate the color using a env_spotlight.
Awesome! I'll look into it.