Colored Smoke

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Colored Smoke

Postby BackRaw » Tue Sep 23, 2014 6:12 pm

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?
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Tue Sep 23, 2014 7:46 pm

If it was possible with EventScripts, it's possible with Source.Python.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Tue Sep 23, 2014 8:05 pm

The effects package provides two methods to spawn smoke. But you could also create an env_smoke or a smokegrenade.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Wed Sep 24, 2014 7:23 am

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?
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Sep 24, 2014 8:54 am

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.
qazuar
Junior Member
Posts: 16
Joined: Fri Jun 20, 2014 9:05 am

Postby qazuar » Wed Sep 24, 2014 7:05 pm

server_tools.remove_entity seems to crash on CSGO, atleast in my case it does.
Hedgehog
Member
Posts: 62
Joined: Sun Nov 03, 2013 8:54 pm

Postby Hedgehog » Wed Sep 24, 2014 7:28 pm

Instead of server_tools.remove_entity you should use

Syntax: Select all

entity.Kill()

because it's more stable (at least n CS:S).
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Sep 24, 2014 7:46 pm

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)
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Sep 24, 2014 7:59 pm

Hedgehog wrote:Instead of server_tools.remove_entity you should use

Syntax: Select all

entity.Kill()

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.
qazuar
Junior Member
Posts: 16
Joined: Fri Jun 20, 2014 9:05 am

Postby qazuar » Thu Sep 25, 2014 4:19 pm

Setting the hammerid seems to solve the problem, no more crashing.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Thu Sep 25, 2014 4:24 pm

Alright, then the SDK is lying. I will fix that later tonight, thanks for testing!

EDIT: Done.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Thu Sep 25, 2014 9:30 pm

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.
My Github repositories:

Source.Python: https://github.com/backraw

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 128 guests