I am trying to make a black box appear while facing a specific angle based of a entities angle.
Kinda like how parented props stay always at the same angle of the parent prop. How can I do this?
this is my code.
[code]
hook.Add("PostDrawTranslucentRenderables", LocalPlayer():Nick() .. "LightDrawer", function()
for k,v in pairs(ents.GetAll()) do
if(IsEntity(v) && !v:IsWeapon() && !v:IsPlayer()) then
if(v.IsOn) then
local pos = v:GetPos()
local ang = v:GetAngles() * 2
cam.Start3D2D(pos, ang, 1)
draw.RoundedBox(0,0,0,10,10,Color(0,0,0))
cam.End3D2D()
end
end
end
end)
[/code]
Don't loop through all entities checking for a specific flag. Very hard on the cpu. Just add whatever entities you want to loop through into a table.
[lua]
local boxEntities = {} --table.insert any entities you want into this table.
hook.Add("PostDrawTranslucentRenderables", "PlayerLightDrawer", function()
for k,v in pairs(boxEntities) do
if v:IsValid() then
local pos = v:GetPos()
local ang = v:GetAngles() * 2
cam.Start3D2D(pos, ang, 1)
draw.RoundedBox(0,0,0,10,10,Color(0,0,0))
cam.End3D2D()
else
table.remove(boxEntities, k)
end
end
end)
[/lua]
Your question wasn't clear to me. Maybe elaborate a bit more.
Sorry, you need to Log In to post a reply to this thread.