21-Jun-2024, 20:38
(This post was last modified: 14-Aug-2024, 15:14 by SweptThrone.)
Set
Create a new
Pretty simple fix for a common problem. It makes sense when you think about it, but if you're like me, you never even knew there was a "DrawTranslucent" hook for entities. This is the case even if your 3D2D isn't translucent, as you can see below. Both the opaque text and the translucent background are drawn behind the door before the fix, and in front of it after.
![[Image: fixdumb.png]](https://sweptthr.one/img/fixdumb.png)
Shoutout to Fesiug for helping me fix this on STRP.
Here's an example from STFood Neu STRP Edition's stove:
ENT.RenderGroup = RENDERGROUP_BOTH
in your entity's shared file.Create a new
ENT:DrawTranslucent()
hook and move all of your 3D2D code to it. Keep self:DrawModel()
in ENT:Draw()
. These should both be clientside only.Pretty simple fix for a common problem. It makes sense when you think about it, but if you're like me, you never even knew there was a "DrawTranslucent" hook for entities. This is the case even if your 3D2D isn't translucent, as you can see below. Both the opaque text and the translucent background are drawn behind the door before the fix, and in front of it after.
![[Image: fixdumb.png]](https://sweptthr.one/img/fixdumb.png)
Shoutout to Fesiug for helping me fix this on STRP.
Here's an example from STFood Neu STRP Edition's stove:
Code:
-- BAD, DO NOT USE THIS
-- st_food_neu_stove.lua (shared)
AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "base_anim"
ENT.PrintName = "Stove"
ENT.Author = "SweptThrone"
ENT.Contact = "sweptthr.one/contact"
ENT.Spawnable = true
ENT.AdminSpawnable = false
ENT.Category = "STFood Neu"
if CLIENT then
function ENT:Draw()
self:DrawModel()
local Pos = self:GetPos()
local Ang = self:GetAngles()
Ang:RotateAroundAxis(Ang:Forward(), 90)
Ang:RotateAroundAxis(Ang:Right(), 270)
local txt = "Serve Food!"
surface.SetFont( "DermaLarge" )
local TextWidth = surface.GetTextSize( txt )
cam.Start3D2D( Pos + Ang:Up() * -15 + Ang:Right() * ( 5 + TimedSin( 0.25, 0, 2, 0 ) ) - Ang:Forward() * 1.5, Ang, 0.16 )
draw.WordBox( 4, -TextWidth*0.5, -260, txt, "DermaLarge", Color( 0, 0, 0, 200 ), Color( 255, 255, 255, 255 ) )
cam.End3D2D()
end
end
Code:
-- GOOD, USE THIS EXAMPLE
-- st_food_neu_stove.lua (shared)
AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "base_anim"
ENT.PrintName = "Stove"
ENT.Author = "SweptThrone"
ENT.Contact = "sweptthr.one/contact"
ENT.Purpose = ""
ENT.Instructions = ""
ENT.Spawnable = true
ENT.AdminSpawnable = false
ENT.Category = "STFood Neu"
ENT.RenderGroup = RENDERGROUP_BOTH
if CLIENT then
function ENT:Draw()
self:DrawModel()
end
function ENT:DrawTranslucent()
local Pos = self:GetPos()
local Ang = self:GetAngles()
Ang:RotateAroundAxis(Ang:Forward(), 90)
Ang:RotateAroundAxis(Ang:Right(), 270)
local txt = "Serve Food!"
surface.SetFont( "DermaLarge" )
local TextWidth = surface.GetTextSize( txt )
cam.Start3D2D( Pos + Ang:Up() * -15 + Ang:Right() * ( 5 + TimedSin( 0.25, 0, 2, 0 ) ) - Ang:Forward() * 1.5, Ang, 0.16 )
draw.WordBox( 4, -TextWidth*0.5, -260, txt, "DermaLarge", Color( 0, 0, 0, 200 ), Color( 255, 255, 255, 255 ) )
cam.End3D2D()
end
end
~SweptThrone •.-