PostDrawOpaqueRenderables

this is my code:



local function LMMNPCRBounceFunction()
	for k, v in pairs( ents.FindByClass( "lmm_npcr" ) ) do
	   
		local p
	   
		p = v:GetPos() + Vector(0,0,95 + math.sin(CurTime()*3)*5)

		for _,yaw in pairs({0, 180}) do
			local a = Angle(0, 0, 0)
			a:RotateAroundAxis(a:Forward(), 90)
			a:RotateAroundAxis(a:Right(), yaw)
   
			a:RotateAroundAxis(a:Right(), CurTime() * 15)

			local name = v:GetNWString("LMMNPCRName") or "UnKnown"
			local cooldown = v:GetNWFloat("LMMNPCRCooldown") or 0
			local robbing = v:GetNWFloat("LMMNPCRRobbingInProgress") or 0
			local id = v:GetNWString("LMMNPCRID") or 0
			local colorr = v:GetNWFloat("LMMNPCRColorR") or 255
			local colorg = v:GetNWFloat("LMMNPCRColorG") or 0
			local colorb = v:GetNWFloat("LMMNPCRColorB") or 0
			local colora = v:GetNWFloat("LMMNPCRColorA") or 255
	 
			render.PushFilterMag(TEXFILTER.ANISOTROPIC)
			render.PushFilterMin(TEXFILTER.ANISOTROPIC)
			cam.Start3D2D(p, a, 0.1)
				if robbing == 1 then
					draw.DrawText(name.."
Robbing...", "LMMNPCRBounceFont", 0, 0, Color(colorr, colorg, colorb, colora), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)				
				elseif cooldown == 1 then
					draw.DrawText(name.."
Cooldown: "..string.ToMinutesSeconds(math.Round(LMMNPCRConfig.CooldownTime * 60 - (math.abs(tonumber(v:GetNWFloat("LMMNPCRGetCooldownTime")) - CurTime())))), "LMMNPCRBounceFont", 0, 0, Color(colorr, colorg, colorb, colora), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)								
				else
					draw.DrawText(name, "LMMNPCRBounceFont", 0, 0, Color(colorr, colorg, colorb, colora), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)								
				end
			cam.End3D2D()
			render.PopFilterMag()
			render.PopFilterMin()
		end
	end	
end 
hook.Add( "PostDrawOpaqueRenderables", "LMMNPCRBounceFunction", LMMNPCRBounceFunction)


problem:

Sometimes the text does not render… sometimes it does there are no errors just sometimes does not happen… Please help! Thanks

This is a very horrible way of doing this, ( ents.FindByClass is super slow ), since you are using a custom entity, just draw your shit from ENT:Draw()

alright i switched to the ENT:Draw function but now its still not working…

Are you setting Render Bounds?

Not sure what you mean i have never really used the ENT:Draw() function

An entity will only render if its render bounds are on your screen.

sorry to answer so late but what would you recommend for the vectors there?

ENT:Draw won’t draw through other world models… At least from my experience with it

Mins and Maxs, relative positions to the Entity:GetPos().

Choose a value that will cover the entire entity.

Think of it as a box. Mins is the top left corner and Maxs is the bottom left.
Mins usually has all 3 coordinates negative ( Vector(-100, -100, -100) for example )

You must choose values that will create a box that will cover your entire entity and everything it draws.

When any part of that box is on the screen, your entity will be drawn.

Just to know, if you are not using a custom entity but just “prop_physics” for example, what do you do ?

here’s an example



for k, v in pairs(ents.FindByClass("prop_physics")) do
    if v:GetModel() == "yourmodel" then 
        -- do something
    end
end


Doing it by model might not be a good idea (actual props having the model, for example), you could set a member on your prop’s table when it is created then use that.

eg:
upon creation: ent.SomeMember = true

if v.SomeMember then