As opposed to doing the expected action of making my dynamic boxes always visible even when the two corners aren't, this makes my box flicker wildly, and sometimes go entirely invisible, usually when I'm looking at a corner.
However, if I can't see either corner, it [i]is[/i] visible. (usually)
Specific:
[lua]function ENT:Draw()
self.Entity:DrawModel()
local other = self:GetNWEntity"other"
if not ValidEntity(other) then return end
local pos = self:GetPos()
local pos2 = other:GetPos()
if (pos ~= self.pos1 or pos2 ~= self.pos2) then
self:SetRenderBounds(pos,pos2);
self.pos1 = pos;
self.pos2 = pos2;
end
-- ...
[/lua]
(Yes I know the added bit looks a bit different, my coding style has changed since I started learning C)
Entire:
[lua]ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Dynamic Box Corner"
ENT.Author = "Lexi"
ENT.Contact = "mwaness@gmail.com"
ENT.Purpose = "Making finding box-based areas easier / Fun"
ENT.Instructions = "press 'use' to print out coords. 'sprint+use' to change movetype."
ENT.Information = "Spawn two to draw a dynamic box.\nPress 'use' on one to make it print informations.\nPress 'sprint' and 'use' on one to switch its movetype"
ENT.Category = "Util"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT;
function math.DecimalPlaces(numb,places)
return math.Round(numb*10^places)/10^places
end
if SERVER then
AddCSLuaFile"shared.lua"
AddCSLuaFile"cl_init.lua"
resource.AddFile"materials/VGUI/entities/sent_corner.vtf"
local other
function ENT:SpawnFunction( ply, tr )
if not tr.Hit then return end
local ent = ents.Create("sent_corner")
ent:SetPos( tr.HitPos --+ tr.HitNormal * 50--
)
ent:Spawn()
ent:Activate()
local phys = ent:GetPhysicsObject()
if (phys:IsValid()) then
phys:EnableMotion(false)
end
if ValidEntity(other) then
ent:SetNWEntity("other",other)
other:SetNWEntity("other",ent)
other = nil
else
other = ent
end
return ent
end
function ENT:Initialize()
self.Entity:SetModel("models//props_junk/Rock001a.mdl")
self.Entity:PhysicsInit( SOLID_VPHYSICS)
self.Entity:SetMoveType( MOVETYPE_NONE)
self.Entity:SetSolid( SOLID_VPHYSICS)
self.Entity:SetUseType(SIMPLE_USE)
self.Entity:DrawShadow(false)
end
function ENT:Use(activator,caller)
if not activator:IsPlayer() then return end
if activator:KeyDown(IN_SPEED) then
if self.Entity:GetMoveType() == MOVETYPE_VPHYSICS then
self.Entity:SetMoveType(MOVETYPE_NONE)
else
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
end
return
end
local other = self:GetNWEntity"other"
if not ValidEntity(other) then return end
local pos = self:GetPos()
local pos2 = other:GetPos()
if pos.z < pos2.z then
pos,pos2 = pos2, pos
end
local words = "top = Vector(".. math.DecimalPlaces( pos.x,4)..","..math.DecimalPlaces( pos.y,4)..","..math.DecimalPlaces( pos.z,4).."); "..
"bottom = Vector("..math.DecimalPlaces(pos2.x,4)..","..math.DecimalPlaces(pos2.y,4)..","..math.DecimalPlaces(pos2.z,4)..");"
activator:PrintMessage(HUD_PRINTCONSOLE,words)
activator:SendLua("SetClipboardText'"..words.."'")
end
return
end
local rot = Vector(0, -90, 0)
local width = 10
local Laser = Material( "cable/redlaser" )
function ENT:Draw()
self.Entity:DrawModel()
local other = self:GetNWEntity"other"
if not ValidEntity(other) then return end
local pos = self:GetPos()
local pos2 = other:GetPos()
if (pos ~= self.pos1 or pos2 ~= self.pos2) then
self:SetRenderBounds(pos,pos2);
self.pos1 = pos;
self.pos2 = pos2;
end
render.SetMaterial( Laser )
render.DrawBeam( pos, Vector( pos.x, pos2.y, pos.z ), width, 0, 0, color_white )
render.DrawBeam( pos, Vector( pos2.x, pos.y, pos.z ), width, 0, 0, color_white )
render.DrawBeam( pos, Vector( pos.x, pos.y, pos2.z ), width, 0, 0, color_white )
render.DrawBeam( pos2, Vector( pos2.x, pos2.y, pos.z ), width, 0, 0, color_white )
render.DrawBeam( pos2, Vector( pos2.x, pos.y, pos2.z ), width, 0, 0, color_white )
render.DrawBeam( pos2, Vector( pos.x, pos2.y, pos2.z ), width, 0, 0, color_white )
render.DrawBeam(Vector( pos.x, pos.y, pos2.z ), Vector( pos.x, pos2.y, pos2.z ), width, 0, 0, color_white )
render.DrawBeam(Vector( pos.x, pos.y, pos2.z ), Vector( pos2.x, pos.y, pos2.z ), width, 0, 0, color_white )
render.DrawBeam(Vector( pos2.x, pos.y, pos2.z ), Vector( pos2.x, pos.y, pos.z ), width, 0, 0, color_white )
render.DrawBeam(Vector( pos.x, pos2.y, pos2.z ), Vector( pos.x, pos2.y, pos.z ), width, 0, 0, color_white )
render.DrawBeam(Vector( pos2.x, pos2.y, pos.z ), Vector( pos.x, pos2.y, pos.z ), width, 0, 0, color_white )
render.DrawBeam(Vector( pos2.x, pos2.y, pos.z ), Vector( pos2.x, pos.y, pos.z ), width, 0, 0, color_white )
end[/lua]
-snip for trying to help someone at 1:00 at night-
[QUOTE=Gbps;18398364]The reason you are getting that problem is because you are calling SetRenderBounds every frame, causing the engine to update the bounds ever draw frame, causing the flicker. When you were not looking at the corners, everything was fine because the draw hook wasn't being called, therefore you weren't updating your render bounds ever frame. Only call SetRenderBounds when the placements of the corners have changed and you should be good to go :eng101:[/QUOTE]
Nope, look again.
Sorry, you need to Log In to post a reply to this thread.