IEffects library now available!!!

Official Announcements about Source.Python.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

IEffects library now available!!!

Postby satoon101 » Thu Aug 16, 2012 5:52 am

Development on the plugin is going strong. We now have the ability to use the IEffects class:
  • Beam:
    • Start (Vector)
    • End (Vector)
    • nModelIndex (index - use GameEngine.PrecacheModel)
    • mHaloIndex (index - use GameEngine.PrecacheModel)
    • frameStart (integer)
    • frameRate (integer)
    • flLife (float - seconds for the beam to remain)
    • width (integer)
    • endWidth (integer)
    • fadeLength (integer)
    • noise (integer)
    • red (integer 0-255)
    • green (integer 0-255)
    • blue (integer 0-255)
    • brightness (integer 0-255)
    • speed
  • Dust:
    • pos (Vector - position of the dust)
    • dir (Vector - direction of the dust)
    • size (float)
    • speed (float)
  • EnergySplash:
    • position (Vector)
    • direction (Vector)
    • bExplosive (bool)
  • MetalSparks:
    • position (Vector)
    • direction (Vector)
  • MuzzleFlash:
    • vecOrigin (Vector)
    • vecAngles (Vector)
    • flScale (float)
    • iType (integer)
  • Ricochet:
    • position (Vector)
    • direction (Vector)
  • Smoke:
    • origin (Vector)
    • modelIndex (index - use GameEngine.PrecacheModel)
    • scale (float)
    • framerate (float)
  • Sparks:
    • position (Vector)
    • nMagnitude (integer)
    • nTrailLength (integer)
    • pvecDir (Vector - direction)

Here is a simple DeathBeam script I tried out:

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
from Source import Misc
from Source import Player
# Core
from core import GameEngine
# Events
from events.decorator import Event


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
effects = Misc.GetEffects()
model = GameEngine.PrecacheModel('sprites/laserbeam.vmt')


# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event
def player_death(GameEvent):
victim = Player.PlayerOfUserid(GameEvent.GetInt('userid'))
killer = Player.PlayerOfUserid(GameEvent.GetInt('attacker'))

green = 0

if killer.GetTeamIndex() == 2:
red = 255
blue = 0
else:
red = 0
blue = 255

effects.Beam(victim.GetAbsOrigin(), killer.GetAbsOrigin(),
model, model, 0, 0, 20.0, 1, 1, 0, 0, red, green, blue, 255, 0)
Here is a pic of the results of that script:
http://steamcommunity.com/profiles/76561197970633142/screenshot/558698452561908099?tab=public

Do note, though, that while this is currently in the Misc structure, it will be moved out once we decide how to move forward with the structure on the C++ side. For future updates, if any functionality is in Misc, it is there for an undetermined time until it gets moved out, but it will be moved out at some point. If you create a script that uses Misc, be sure to keep up-to-date, so you know when you need to modify your script.

Note also, that the script above takes advantage of more new functionality available to us as of the latest updates. You can now use Player.PlayerOfUserid(<userid>) to get a userid's IPlayerInfo instance, Player.EdictOfUserid(<userid>) to get a userid's entity edict, and Player.PlayerOfIndex(<index>) to get a player's IPlayerInfo from their index.

Satoon
DreTaX14
Junior Member
Posts: 15
Joined: Fri Aug 17, 2012 5:05 pm

Postby DreTaX14 » Sat Aug 18, 2012 5:49 pm

satoon101 wrote:Development on the plugin is going strong. We now have the ability to use the IEffects class:
  • Beam:
    • Start (Vector)
    • End (Vector)
    • nModelIndex (index - use GameEngine.PrecacheModel)
    • mHaloIndex (index - use GameEngine.PrecacheModel)
    • frameStart (integer)
    • frameRate (integer)
    • flLife (float - seconds for the beam to remain)
    • width (integer)
    • endWidth (integer)
    • fadeLength (integer)
    • noise (integer)
    • red (integer 0-255)
    • green (integer 0-255)
    • blue (integer 0-255)
    • brightness (integer 0-255)
    • speed
  • Dust:
    • pos (Vector - position of the dust)
    • dir (Vector - direction of the dust)
    • size (float)
    • speed (float)
  • EnergySplash:
    • position (Vector)
    • direction (Vector)
    • bExplosive (bool)
  • MetalSparks:
    • position (Vector)
    • direction (Vector)
  • MuzzleFlash:
    • vecOrigin (Vector)
    • vecAngles (Vector)
    • flScale (float)
    • iType (integer)
  • Ricochet:
    • position (Vector)
    • direction (Vector)
  • Smoke:
    • origin (Vector)
    • modelIndex (index - use GameEngine.PrecacheModel)
    • scale (float)
    • framerate (float)
  • Sparks:
    • position (Vector)
    • nMagnitude (integer)
    • nTrailLength (integer)
    • pvecDir (Vector - direction)

Here is a simple DeathBeam script I tried out:

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
from Source import Misc
from Source import Player
# Core
from core import GameEngine
# Events
from events.decorator import Event


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
effects = Misc.GetEffects()
model = GameEngine.PrecacheModel('sprites/laserbeam.vmt')


# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event
def player_death(GameEvent):
victim = Player.PlayerOfUserid(GameEvent.GetInt('userid'))
killer = Player.PlayerOfUserid(GameEvent.GetInt('attacker'))

green = 0

if killer.GetTeamIndex() == 2:
red = 255
blue = 0
else:
red = 0
blue = 255

effects.Beam(victim.GetAbsOrigin(), killer.GetAbsOrigin(),
model, model, 0, 0, 20.0, 1, 1, 0, 0, red, green, blue, 255, 0)
Here is a pic of the results of that script:
http://steamcommunity.com/profiles/76561197970633142/screenshot/558698452561908099?tab=public

Do note, though, that while this is currently in the Misc structure, it will be moved out once we decide how to move forward with the structure on the C++ side. For future updates, if any functionality is in Misc, it is there for an undetermined time until it gets moved out, but it will be moved out at some point. If you create a script that uses Misc, be sure to keep up-to-date, so you know when you need to modify your script.

Note also, that the script above takes advantage of more new functionality available to us as of the latest updates. You can now use Player.PlayerOfUserid(<userid>) to get a userid's IPlayerInfo instance, Player.EdictOfUserid(<userid>) to get a userid's entity edict, and Player.PlayerOfIndex(<index>) to get a player's IPlayerInfo from their index.

Satoon

Do you have that sprite file?
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Sat Aug 18, 2012 8:36 pm

Awesome :D
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 19, 2012 12:33 am

DreTaX14 wrote:Do you have that sprite file?
You do not need that specific sprite on the server. It is located, for clients, in their pak01_dir.vpk file, if you wish to reference it.

Satoon
DreTaX14
Junior Member
Posts: 15
Joined: Fri Aug 17, 2012 5:05 pm

Postby DreTaX14 » Sun Aug 19, 2012 8:22 am

Okay but somehow it doesnt really work for me if i want to test it.
Scripting in Python is mostly better than SM.
Python is powerfull, if you learn it.
The reason is because I LIKE SNAKES! :D
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 19, 2012 12:40 pm

I have been having 1 issue with it, but I cannot figure out what is causing it. If "I" kill someone, the beam does not show, but if anyone else gets a kill, it shows. This is tested with just me vs bots, not sure if that has anything to do with it either.

Satoon
DreTaX14
Junior Member
Posts: 15
Joined: Fri Aug 17, 2012 5:05 pm

Postby DreTaX14 » Sun Aug 19, 2012 12:57 pm

looooooolll
Scripting in Python is mostly better than SM.

Python is powerfull, if you learn it.

The reason is because I LIKE SNAKES! :D
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Sun Aug 19, 2012 4:21 pm

Thats a weird issue...
DreTaX14
Junior Member
Posts: 15
Joined: Fri Aug 17, 2012 5:05 pm

Postby DreTaX14 » Sun Aug 19, 2012 6:33 pm

yes it is xD
Scripting in Python is mostly better than SM.

Python is powerfull, if you learn it.

The reason is because I LIKE SNAKES! :D
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Tue Nov 20, 2012 4:36 am

Be sure to note that

Syntax: Select all

model = GameEngine.PrecacheModel('sprites/laserbeam.vmt')


will crash the game if you load this before a map has loaded completly (for example having sp load <plugin> in autoexec.cfg) you will have to use something like this for precaching model for clients not to crash:

Syntax: Select all

from events import Event

model = None


@Event
def server_spawn(GameEvent):
global model
model = GameEngine.PrecacheModel('sprites/laserbeam.vmt')


#Be sure this can be only be called after map load such as player_say or another player_ event
#that way it will be save to precache if not already precached.
def beam(<example>):
global model
if model is None:
model = GameEngine.PrecacheModel('sprites/laserbeam.vmt')
effects.Beam(victim.GetAbsOrigin(), killer.GetAbsOrigin(),
model, model, 0, 0, 20.0, 1, 1, 0, 0, 255, 255, 255, 255, 0)
-Tuck
DJiSer
Junior Member
Posts: 20
Joined: Sat May 10, 2014 2:44 pm

Postby DJiSer » Sun Aug 10, 2014 1:45 pm

Effects also unavailable for current build?
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Aug 10, 2014 2:11 pm

No, they are available since a long time. :) https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/effects/__init__.py

There are two effect classes you can use: Effects and TempEntities

TempEntities also gives you the possibility to specify users who should see the effects.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 10, 2014 3:35 pm

Also note that this thread is two years old. A lot has changed in the plugin since then. Pretty much none of the examples above work with the current version of the plugin.
DJiSer
Junior Member
Posts: 20
Joined: Sat May 10, 2014 2:44 pm

Postby DJiSer » Sun Aug 10, 2014 9:18 pm

Syntax: Select all

from engines.server import EngineServer
from effects import Effects
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid


@Event
def player_hurt(game_event):
model = EngineServer.precache_model('sprites/laserbeam.vmt')
userid = game_event.get_int('userid')
attacker = game_event.get_int('attacker')
pos1 = PlayerEntity(index_from_userid(userid)).location
pos2 = PlayerEntity(index_from_userid(attacker)).location
Effects.beam(pos1, pos2, model, model, 0, 0, 20.0, 1, 1, 0, 0, 255, 0, 255, 255, 0)

Just nothing happens.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 10, 2014 9:32 pm

A player's origin (location) is at their feet. If both players are on the ground and at the same altitude, the beam will essentially be in the ground. Try increasing the z value of the vectors by 20 and see what that does.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Aug 10, 2014 9:38 pm

I just tested it, you are right. What happens if you try this?

Syntax: Select all

from engines.server import EngineServer
from effects import Effects
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid

@Event
def player_hurt(game_event):
model = EngineServer.precache_model('sprites/laserbeam.vmt')
userid = game_event.get_int('userid')
attacker = game_event.get_int('attacker')
pos1 = PlayerEntity(index_from_userid(userid)).location
pos2 = PlayerEntity(index_from_userid(attacker)).location

#Effects.beam(pos1, pos2, model, model, 0, 0, 20.0, 1, 1, 0, 0, 255, 0, 255, 255, 0)

from listeners.tick.delays import TickDelays
TickDelays.delay(0, Effects.beam, pos1, pos2, model, model, 0, 0, 20.0, 1, 1, 0, 0, 255, 0, 255, 255, 0)
DJiSer
Junior Member
Posts: 20
Joined: Sat May 10, 2014 2:44 pm

Postby DJiSer » Sun Aug 10, 2014 9:43 pm

Ayuto wrote:I just tested it, you are right. What happens if you try this?

Syntax: Select all

from engines.server import EngineServer
from effects import Effects
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid

@Event
def player_hurt(game_event):
model = EngineServer.precache_model('sprites/laserbeam.vmt')
userid = game_event.get_int('userid')
attacker = game_event.get_int('attacker')
pos1 = PlayerEntity(index_from_userid(userid)).location
pos2 = PlayerEntity(index_from_userid(attacker)).location

#Effects.beam(pos1, pos2, model, model, 0, 0, 20.0, 1, 1, 0, 0, 255, 0, 255, 255, 0)

from listeners.tick.delays import TickDelays
TickDelays.delay(0, Effects.beam, pos1, pos2, model, model, 0, 0, 20.0, 1, 1, 0, 0, 255, 0, 255, 255, 0)


It works now.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Aug 10, 2014 9:49 pm

Okay, but this is obviously a bug. We will look into this issue.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Aug 28, 2014 12:33 pm


Return to “News & Announcements”

Who is online

Users browsing this forum: No registered users and 12 guests