Category:Lua:Sample Scripts:Effects

From GMod Wiki

Jump to: navigation, search


Effects

Effects are cool visuals that may be generated at the end of a SENT, when firing a SWEP, and/or when using a tool. Team Garry has created one very unique example, of the wheel. He made a custom material, and then used scripts to flip, rotate, and set rotation loops of this. they are generated by the wheel entities created by the wheel tool.

Effects: Wheel Indicator

Yarin Kaul Icon Lua48.png
Description:Makes the Wheels Rotational Direction Indicator.
Original Author(s):Team Garry
 
/*------------------------------------------------------------------------------------
	DO NOT EDIT THIS, THIS WAS FINNISHED BY TEAM GARRY, AND SURELY DOES NOT NEED EDITTING!!!!! IF YOU DECIDE TO EDIT 
	THIS, AND YOUR GAME STARTS ACTING FUNNY, DONT SAY WE DIDN'T WARN YOU!
------------------------------------------------------------------------------------*/
 
EFFECT.Mat = Material( "effects/wheel_ring" )
 
local WheelEffects = {}
 
/*---------------------------------------------------------
	Initializes the effect. The data is a table of data 
	which was passed from the server.
---------------------------------------------------------*/
function EFFECT:Init( data )
 
	local size = 64
	self:SetCollisionBounds( Vector( -size,-size,-size ), Vector( size,size,size ) )
 
	self:SetPos( data:GetOrigin() )
	self.Wheel 	= data:GetEntity()
	if (!self.Wheel:IsValid()) then return end
 
	local oldeffect = WheelEffects[ self.Wheel:EntIndex() ]
	if ( oldeffect && oldeffect:IsValid() ) then
 
		oldeffect:Remove()
 
	end
 
	// This 0.01 is a hack.. to prevent the angle being weird and messing up when we change it back to a normal
	self:SetAngles( data:GetNormal():Angle() + Angle( 0.01, 0.01, 0.01 ) )
 
	self:SetParent( self.Wheel )
 
	self.Pos = data:GetOrigin()
	self.Normal = self.Wheel:GetPos() - self.Pos
	self.Alpha = 255
 
	self.Direction = data:GetScale()
 
	self.Size = 64
 
	self.Size = data:GetEntity():BoundingRadius() + 8
 
 
	WheelEffects[ self.Wheel:EntIndex() ] = self
 
end
 
 
/*---------------------------------------------------------
   THINK
---------------------------------------------------------*/
function EFFECT:Think( )
 
	if (!self.Wheel:IsValid()) then return end
 
	local speed = FrameTime()
 
	self.Alpha = self.Alpha - speed * 100.0
 
	if (self.Alpha < 0 ) then return false end
	return true
 
end
 
/*---------------------------------------------------------
   Draw the effect
---------------------------------------------------------*/
function EFFECT:Render( )
 
	if (!self.Wheel:IsValid()) then return end
 
	if (self.Alpha < 1 ) then return end
 
	render.SetMaterial( self.Mat )
 
	render.DrawQuadEasy( self:GetPos(),
						 self.Normal:GetNormalized() * self.Direction * -1,
						 self.Size, self.Size,
						 Color( 255, 255, 255, self.Alpha ),
						 self.Alpha )
 
 
end
 
 

Please Submit More!

This category currently contains no pages or media.

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox