Global/DynamicLight

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=DynamicLight
 
|Parent=Global
 
 
|Description=Creates or replaces a dynamic light with the given id.
 
|Description=Creates or replaces a dynamic light with the given id.
 +
 +
{{Note|Only 32 dlights and 64 elights can be active at once.}}
 +
{{Warning|It is not safe to hold a reference to this object after creation since its data can be replaced by another dlight at any time.}}
 +
{{Bug|Issue=3798|The minlight parameter affects the world and entities differently.}}
 
|Realm=Client
 
|Realm=Client
 
|IsClass=No
 
|IsClass=No
Line 9: Line 11:
 
|type=number
 
|type=number
 
|name=index
 
|name=index
|desc=Usually an entity index is used here.
+
|desc=An unsigned Integer. Usually an [[Entity/EntIndex|entity index]] is used here.
 +
}}
 +
{{Arg
 +
|type=boolean
 +
|name=elight
 +
|desc=Allocates an elight instead of a dlight. Elights have a higher light limit and do not light the world (making the "noworld" parameter have no effect).
 +
|default=false
 
}}
 
}}
 
{{Ret
 
{{Ret
 
|type=table
 
|type=table
 
|desc=A DynamicLight structured table. See {{Struct|DynamicLight}}
 
|desc=A DynamicLight structured table. See {{Struct|DynamicLight}}
 +
}}
 +
{{Example
 +
|Description=Emits a bright white light from local players eyes.
 +
|Code=hook.Add( "Think", "Think_Lights!", function()
 +
local dlight = DynamicLight( LocalPlayer():EntIndex() )
 +
if ( dlight ) then
 +
dlight.pos = LocalPlayer():GetShootPos()
 +
dlight.r = 255
 +
dlight.g = 255
 +
dlight.b = 255
 +
dlight.brightness = 2
 +
dlight.Decay = 1000
 +
dlight.Size = 256
 +
dlight.DieTime = CurTime() + 1
 +
end
 +
end )
 
}}
 
}}

Latest revision as of 17:43, 2 July 2019

 DynamicLight( )

Contents

Description

Creates or replaces a dynamic light with the given id.

NOTE

Only 32 dlights and 64 elights can be active at once.

WARNING

It is not safe to hold a reference to this object after creation since its data can be replaced by another dlight at any time.

BUG

The minlight parameter affects the world and entities differently.

Issue Tracker: #3798

Arguments

number index

An unsigned Integer. Usually an entity index is used here.

Arguments

boolean elight=false

Allocates an elight instead of a dlight. Elights have a higher light limit and do not light the world (making the "noworld" parameter have no effect).

Returns

table

A DynamicLight structured table. See DynamicLight structure

Examples

Example

Emits a bright white light from local players eyes.

hook.Add( "Think", "Think_Lights!", function()
	local dlight = DynamicLight( LocalPlayer():EntIndex() )
	if ( dlight ) then
		dlight.pos = LocalPlayer():GetShootPos()
		dlight.r = 255
		dlight.g = 255
		dlight.b = 255
		dlight.brightness = 2
		dlight.Decay = 1000
		dlight.Size = 256
		dlight.DieTime = CurTime() + 1
	end
end )


Personal tools
Navigation