So well in order i wanted to draw 3D 2D Text above my NPC i used the following code on his CL_Init.lua
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT;
surface.CreateFont( "coolvetica", 64, 500, true, false, "Text64" ) -- FONT
function ENT:Draw()
self:DrawModel()
cam.Start3D2D(self:GetPos(), self:GetAngles(), 0.1)
draw.SimpleText("Hello World!", "Text64", 0, -90, Color(255,0,0,255), TEXT_ALIGN_CENTER, 1)
cam.End3D2D()
end
but then if i spawn the npc the text doesnt gets added at all BUT if i use this on a entity not a npc for some reason it works well
Iirc npcs don't have a client-side part like normal sents do.
well then how would i go to do this on a NPC?
Do it manually in PostDrawOpaqueRenderables (or other similiar hook of your choice)
sorry im not getting this
help?
He's saying to do something like this:
[lua]
surface.CreateFont( "coolvetica", 64, 500, true, false, "Text64" )
function GM:PostDrawOpaqueRenderables()
for _, ent in pairs(ents.FindByClass("npcclass")) do
cam.Start3D2D(ent:GetPos(), ent:GetAngles(), 0.1)
draw.SimpleText("Hello World!", "Text64", 0, -90, Color(255,0,0,255), TEXT_ALIGN_CENTER, 1)
cam.End3D2D()
end
end
[/lua]
well i tried that now and it still doesnt work
[editline]22nd February 2011[/editline]
i putted it on my gamemode init.lua btw
[QUOTE=werewolf0020;28212773]well i tried that now and it still doesnt work
[editline]22nd February 2011[/editline]
i putted it on my gamemode init.lua btw[/QUOTE]
Since it's a clientside hook, you need to put it in your cl_init.lua
[b][url=wiki.garrysmod.com/?title=Gamemode.PostDrawOpaqueRenderables]Gamemode.PostDrawOpaqueRenderables [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
oh my god it still doesnt work!
this is my current code
surface.CreateFont( "coolvetica", 64, 500, true, false, "Text64" )
function GM:PostDrawOpaqueRenderables()
for _, ent in pairs(ents.FindByClass("npcclass")) do
cam.Start3D2D(ent:GetPos(), ent:GetAngles(), 0.1)
draw.SimpleText("Hello World!", "Text64", 0, -90, Color(255,0,0,255), TEXT_ALIGN_CENTER, 1)
cam.End3D2D()
end
end
I think you were supposed to change npcclass.
Yeah, and when you say it's still not working, how do you mean by not working? Does it draw anything? Or doesn't it? Any error?
sorry for the dumb questions but now it sticked to the npc feet and attached to the ground in 2d i only want to attach it to the npc head and fix it position
heres a pic of the problem [IMG]http://i53.tinypic.com/de3bte.png[/IMG]
Send us your now used code if you changed anything.
[editline]23rd February 2011[/editline]
[lua]
surface.CreateFont( "coolvetica", 64, 500, true, false, "Text64" )
function GM:PostDrawOpaqueRenderables()
for _, ent in pairs(ents.FindByClass("npcclass")) do
cam.Start3D2D(ent:GetPos()+Vector(0,0,80), ent:GetAngles(), 0.1)
draw.SimpleText("Hello World!", "Text64", 0, -90, Color(255,0,0,255), TEXT_ALIGN_CENTER, 1)
cam.End3D2D()
end
end
[/lua]
Change the Pos. Drew told me, and I tested it out. It works, but you need to figure out the angles.
[editline]23rd February 2011[/editline]
Here, change this the cam.Start3D2D with this:
[lua]
cam.Start3D2D(ent:GetPos()+Vector(0,0,90), ent:GetAngles() + Angle(0,90,90), 0.25)
[/lua]
[editline]23rd February 2011[/editline]
It works perfect but is there anyway to make it always face the player? i can live with how it is alredy but it can look a bit nicer if it face the player based on from what angle is he looking at the text
Try adding "LocalPlayer:EyeAngles()" to your angle formula, and change some of the already set offsets.
[QUOTE=Donkie;28237818]Try adding "LocalPlayer:EyeAngles()" to your angle formula, and change some of the already set offsets.[/QUOTE]
You better use EyeAngles() not LocalPlayer():EyeAngles()
[QUOTE=Wizard of Ass;28238224]You better use EyeAngles() not LocalPlayer():EyeAngles()[/QUOTE]
Oh, I didn't know there was a global for that.
This works, I tested it myself.
[lua]
surface.CreateFont( "coolvetica", 64, 500, true, false, "Text64" )
function GM:PostDrawOpaqueRenderables()
for _, ent in pairs(ents.FindByClass("npcclass")) do
cam.Start3D2D(ent:GetPos()+Vector(0,0,90), ent:GetAngles() + Angle(0,90,90), 0.1)
draw.SimpleText("Hello World!", "Text64", 0, -90, Color(255,0,0,255), TEXT_ALIGN_CENTER, 1)
cam.End3D2D()
end
end
[/lua]
Thanks for all the help
Sorry, you need to Log In to post a reply to this thread.