wiremod-svn-archive/wire/lua/entities/gmod_wire_lamp/init.lua
tad2020 60643226ef [added] model selection to adv pod ctrlr
[changed] cleaned up more stools' code
[fixed] some ents not keeping updated values when duplicated
[added] presets to some stools
[fixed] some ents not being added to cleanup when duplicated
[fixed] some ents not being staying frozen when duplicated
[fixed] some ents cleanup & undo text
[changed] moved many stools control panels over to DForm functions
[changed] made easier to add preset control to cp
[changed] made easier to add cleanup and undo lang to stools/bak
[changed] made easier to add
2008-02-06 01:21:09 +00:00

179 lines
4.6 KiB
Lua

AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
ENT.WireDebugName = "Lamp"
local MODEL = Model( "models/props_wasteland/prison_lamp001c.mdl" )
AccessorFunc( ENT, "Texture", "FlashlightTexture" )
ENT:SetFlashlightTexture( "effects/flashlight001" )
/*---------------------------------------------------------
Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()
self:SetModel( MODEL )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
self.lightr = 255
self.lightg = 255
self.lightb = 255
self.Inputs = Wire_CreateInputs(self.Entity, { "Red", "Green", "Blue", "On" })
self:TurnOn()
end
/*---------------------------------------------------------
Name: Sets the color of the light
---------------------------------------------------------*/
function ENT:SetLightColor( r, g, b )
self.lightr = r
self.lightg = g
self.lightb = b
self:SetVar( "lightr", r )
self:SetVar( "lightg", g )
self:SetVar( "lightb", b )
self:SetColor( r, g, b, 255 )
self.Entity:SetColor( r, g, b, 255 )
self.m_strLightColor = Format( "%i %i %i", r, g, b )
if ( self.flashlight ) then
self.flashlight:SetKeyValue( "lightcolor", self.m_strLightColor )
end
self:SetOverlayText( "Red:" .. r .. " Green:" .. g .. " Blue" .. b )
end
function ENT:Setup( r, g, b )
self:SetLightColor( r, g, b )
end
/*---------------------------------------------------------
Name: Sets the texture
---------------------------------------------------------*/
function ENT:SetFlashlightTexture( tex )
self.Texture = tex
if ( self.flashlight ) then
self.flashlight:Input( "SpotlightTexture", NULL, NULL, self:GetFlashlightTexture() )
end
end
/*---------------------------------------------------------
Name: OnTakeDamage
---------------------------------------------------------*/
function ENT:OnTakeDamage( dmginfo )
self.Entity:TakePhysicsDamage( dmginfo )
end
/*---------------------------------------------------------
Name: TriggerInput
Desc: the inputs
---------------------------------------------------------*/
function ENT:TriggerInput(iname, value)
if (iname == "Red") then
self:SetLightColor( value, self.lightg, self.lightb )
elseif (iname == "Green") then
self:SetLightColor( self.lightr, value, self.lightb )
elseif (iname == "Blue") then
self:SetLightColor( self.lightr, self.lightg, value )
elseif (iname == "On") then
if value > 0 then
self:TurnOn()
else
self:TurnOff()
end
end
end
function ENT:TurnOn()
self:SetOn(true)
local angForward = self.Entity:GetAngles() + Angle( 90, 0, 0 )
self.flashlight = ents.Create( "env_projectedtexture" )
self.flashlight:SetParent( self.Entity )
// The local positions are the offsets from parent..
self.flashlight:SetLocalPos( Vector( 0, 0, 0 ) )
self.flashlight:SetLocalAngles( Angle(90,90,90) )
// Looks like only one flashlight can have shadows enabled!
self.flashlight:SetKeyValue( "enableshadows", 1 )
self.flashlight:SetKeyValue( "farz", 2048 )
self.flashlight:SetKeyValue( "nearz", 8 )
//Todo: Make this tweakable?
self.flashlight:SetKeyValue( "lightfov", 50 )
// Color.. Bright pink if none defined to alert us to error
self.flashlight:SetKeyValue( "lightcolor", self.m_strLightColor or "255 0 255" )
self.flashlight:Spawn()
self.flashlight:Input( "SpotlightTexture", NULL, NULL, self:GetFlashlightTexture() )
end
function ENT:TurnOff()
self:SetOn(false)
SafeRemoveEntity( self.flashlight )
self.flashlight = nil
end
function ENT:OnRemove()
Wire_Remove(self.Entity)
end
function ENT:OnRestore()
Wire_Restored(self.Entity)
end
include('shared.lua')
function MakeWireLamp( pl, r, g, b, Texture, Data )
if ( !pl:CheckLimit( "wire_lamps" ) ) then return false end
local wire_lamp = ents.Create( "gmod_wire_lamp" )
if (!wire_lamp:IsValid()) then return end
wire_lamp:SetFlashlightTexture( Texture or "effects/flashlight001" )
duplicator.DoGeneric( wire_lamp, Data )
wire_lamp:SetLightColor( r, g, b )
wire_lamp:Spawn()
duplicator.DoGenericPhysics( wire_lamp, pl, Data )
wire_lamp:SetPlayer( pl )
wire_lamp.pl = pl
pl:AddCount( "wire_lamps", wire_lamp )
pl:AddCleanup( "wire_lamp", wire_lamp )
return wire_lamp
end
duplicator.RegisterEntityClass( "gmod_wire_lamp", MakeWireLamp, "lightr", "lightg", "lightb", "Texture", "Data" )