Garry's Mod Wiki

EFFECT

EFFECT

These hooks are used inside of a Lua effect. Lua effects are stored in either the /lua/effects directory or in a gamemode in /gamemodes/<gamemodename>/entities/effects.

Effects are entities with the class CLuaEffect, and as such, Entity functions are usable on them (using the self argument).

An EFFECT is made using either a combination of the EFFECT:Init, EFFECT:Render and optionally the EFFECT:Think hook. Another way is to create all particles in one go in the Init hook and don't use the other hooks at all.

Example

Creates a particle effect using a combination of the Init and the Think hooks.

function EFFECT:Init( data ) self.data = data self.particles = 4 end function EFFECT:Think() return true end function EFFECT:Render() local vOffset = self.data:GetOrigin() + Vector( 0, 0, 0.2 ) local vAngle = self.data:GetAngles() local emitter = ParticleEmitter( vOffset, false ) for i=0, self.particles do local particle = emitter:Add( "effects/softglow", vOffset ) if particle then particle:SetAngles( vAngle ) particle:SetVelocity( Vector( 0, 0, 15 ) ) particle:SetColor( 255, 102, 0 ) particle:SetLifeTime( 0 ) particle:SetDieTime( 0.2 ) particle:SetStartAlpha( 255 ) particle:SetEndAlpha( 0 ) particle:SetStartSize( 1.6 ) particle:SetStartLength( 1 ) particle:SetEndSize( 1.2 ) particle:SetEndLength( 4 ) end end emitter:Finish() end

Example

Creates a particle effect using only the Init hook. To use this effect in a loop one needs to create a new instance of this effect every drawn frame.

function EFFECT:Init( data ) local vOffset = data:GetOrigin() + Vector( 0, 0, 0.2 ) local vAngle = data:GetAngles() local emitter = ParticleEmitter( vOffset, false ) for i=0,4 do local particle = emitter:Add( "effects/softglow", vOffset ) if particle then particle:SetAngles( vAngle ) particle:SetVelocity( Vector( 0, 0, 15 ) ) particle:SetColor( 255, 102, 0 ) particle:SetLifeTime( 0 ) particle:SetDieTime( 0.2 ) particle:SetStartAlpha( 255 ) particle:SetEndAlpha( 0 ) particle:SetStartSize( 1.6 ) particle:SetStartLength( 1 ) particle:SetEndSize( 1.2 ) particle:SetEndLength( 4 ) end end emitter:Finish() end function EFFECT:Think() return false end function EFFECT:Render() end

Events

EFFECT:EndTouch()
Vector EFFECT:GetTracerShootPos( Vector pos, Weapon ent, number attachment )
Used to get the "real" start position of a trace, for weapon tracer effects. "real" meaning in 3rd person, the 3rd person position will be used, in first person the first person position will be used.
EFFECT:Init( CEffectData effectData )
Called when the effect is created.
EFFECT:PhysicsCollide( table colData, PhysObj collider )
Called when the effect collides with anything.
EFFECT:Render()
Called when the effect should be rendered.
EFFECT:StartTouch()
boolean EFFECT:Think()
Called when the effect should think, return false to kill the effect.
EFFECT:Touch()

Special Pages


Wikis

?

Render Time: 61ms

DB GetPage 38
Generate Html 7
SaveChanges (1) 6
Render Body 0
Render Sidebar 7