halo/Add

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Removing unnecessary variables)
Line 57: Line 57:
 
|Code=hook.Add( "PreDrawHalos", "AddStaffHalos", function()
 
|Code=hook.Add( "PreDrawHalos", "AddStaffHalos", function()
 
local staff = {}
 
local staff = {}
local staffcount = 0
 
  
for _, ply in ipairs( player.GetAll() ) do
+
for i, ply in ipairs( player.GetAll() ) do
 
if ( ply:IsAdmin() ) then
 
if ( ply:IsAdmin() ) then
staffcount = staffcount + 1
+
staff[i] = ply
staff[ staffcount ] = ply
+
 
end
 
end
 
end
 
end
  
if ( staffcount > 0 ) then
+
if ( not table.IsEmpty(staff) ) then
 
halo.Add( staff, Color( 0, 255, 0 ), 0, 0, 2, true, true )
 
halo.Add( staff, Color( 0, 255, 0 ), 0, 0, 2, true, true )
 
end
 
end
 
end )
 
end )
 
}}
 
}}

Revision as of 08:33, 5 December 2019

 halo.Add( )

Contents

Description

Applies a "halo" glow effect to one or multiple entities.

WARNING

Using this function outside of the PreDrawHalos hook can cause instability or crashes.

Arguments

table entities

A table of entities to add the halo effect to

Arguments

table color

The desired color of the halo. See Color structure

Arguments

number blurX=2

The strength of the halo's blur on the x axis.

Arguments

number blurY=2

The strength of the halo's blur on the y axis.

Arguments

number passes=1

The number of times the halo should be drawn per frame. Increasing this may hinder player FPS.

Arguments

boolean additive=true

Sets the render mode of the halo to additive.

Arguments

boolean ignoreZ=false

Renders the halo through anything when set to true.

Examples

Example

Adds a halo around all props in the map using an O(n) operation and iterating through unseen objects which can be extremely expensive to process.

hook.Add( "PreDrawHalos", "AddPropHalos", function()
	halo.Add( ents.FindByClass( "prop_physics*" ), Color( 255, 0, 0 ), 5, 5, 2 )
end )

Output:


halo_example.png
All the props on the map will be rendered with a red halo, a blur amount of 5, and two passes.

Examples

Example

Adds a green halo around all admins.

hook.Add( "PreDrawHalos", "AddStaffHalos", function()
	local staff = {}

	for i, ply in ipairs( player.GetAll() ) do
		if ( ply:IsAdmin() ) then
			staff[i] = ply
		end
	end

	if ( not table.IsEmpty(staff) ) then
		halo.Add( staff, Color( 0, 255, 0 ), 0, 0, 2, true, true )
	end
end )


Personal tools
Navigation