Category:EFFECT Hooks

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Gamemode effects go in entities/effects not content/effects)
(Fixed first example not actually working.)
Line 11: Line 11:
 
|Description=Creates a particle effect using a combination of the Init and the Think hooks.
 
|Description=Creates a particle effect using a combination of the Init and the Think hooks.
 
|Code=function EFFECT:Init( data )
 
|Code=function EFFECT:Init( data )
 +
    self.data = data
 
self.particles = 4
 
self.particles = 4
 
end
 
end
  
 
function EFFECT:Think()
 
function EFFECT:Think()
return false
+
return true
 
end
 
end
  
 
function EFFECT:Render()
 
function EFFECT:Render()
local vOffset = data:GetOrigin() + Vector( 0, 0, 0.2 )
+
local vOffset = self.data:GetOrigin() + Vector( 0, 0, 0.2 )
local vAngle = data:GetAngles()
+
local vAngle = self.data:GetAngles()
 
 
 
local emitter = ParticleEmitter( vOffset, false )
 
local emitter = ParticleEmitter( vOffset, false )
Line 72: Line 73:
  
 
function EFFECT:Render()
 
function EFFECT:Render()
return false
 
 
end
 
end
 
}}
 
}}

Revision as of 13:52, 18 May 2016

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.

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.

Contents

Examples

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


Examples

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


Pages in category "EFFECT Hooks"

The following 8 pages are in this category, out of 8 total.

Personal tools
Navigation