Hey, guys and gals. I was wondering if someone would be willing to throw a extra hand in on how I could achieve say, turning a lamp on or off by hitting E (IN_USE ) on a lamp model then it emits a small light.
Ended up making this, hopefully it's what you're asking for.
[IMG]http://puu.sh/3aaDh.jpg[/IMG]
[lua]
if SERVER then
AddCSLuaFile()
end
ENT.Type = "anim"
ENT.PrintName = "Lamp"
ENT.Author = "Inferno, Eh?"
ENT.Information = ""
ENT.Category = "Lights"
ENT.Editable = true
ENT.Spawnable = true
ENT.AdminOnly = false
ENT.Model = Model("models/props_interiors/furniture_lamp01a.mdl")
function ENT:SetupDataTables()
self:NetworkVar("Bool", 0, "LightOn")
end
function ENT:SpawnFunction(ply, tr, class)
if (!tr.Hit) then return end
local pos = tr.HitPos + tr.HitNormal
local ent = ents.Create(class)
ent:Spawn()
local maxs = ent:OBBMaxs()
ent:SetPos(pos+Vector(0,0,maxs.z))
ent:Activate()
ent:DropToFloor()
return ent
end
function ENT:Initialize()
if SERVER then
self:SetModel(self.Model)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetCollisionGroup(COLLISION_GROUP_PLAYER)
self:SetSolid(SOLID_VPHYSICS)
self:DrawShadow(false)
self:SetUseType(SIMPLE_USE)
local phys = self:GetPhysicsObject()
if IsValid(phys) then
phys:EnableMotion(false)
end
end
self:SetLightOn(false)
end
function ENT:Use(activator, caller, type, value)
if IsValid(activator) then
self:SetLightOn(!self:GetLightOn())
end
end
if CLIENT then
function ENT:Draw()
self:DrawModel()
end
function ENT:Think()
if self:GetLightOn() then
local dlight = DynamicLight(self:EntIndex())
if (dlight) then
local r, g, b, a = self:GetColor()
dlight.pos = self:LocalToWorld(self:OBBCenter())+Vector(0,0,20)
dlight.r = 150
dlight.g = 150
dlight.b = 150
dlight.Brightness = 2
dlight.Size = 300
dlight.Decay = 5
dlight.DieTime = CurTime() + 0.1
end
end
end
end
[/lua]
This is a addon correct?
Thats just the code for it. You can put it in an addon or in a gamemode entities folder or whatever really.
Thanks guys, (Solved)
Sorry, you need to Log In to post a reply to this thread.