3d2d

Hey guys, I need some help, I’m trying to draw a scoreboard in 3d2d
I have no idea where to start, Could you give me a working example please?
Thanks in advance

So what your saying is You want it On the Map instead of it being holding tab?

Uh, Yeah, I managed to do it thanks anyway :slight_smile:

Care to share? I’ve never been able to get 3D2D to work for me.

Entity shared.lua…

[lua]

ENT.Type = “anim”
ENT.Base = “base_anim”–“base_gmodentity”

ENT.PrintName = “Billboard”
ENT.Author = “Matt”
ENT.Contact = “”
ENT.Purpose = “”
ENT.Instructions = “”

ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT;

if SERVER then
AddCSLuaFile( “shared.lua” )
AddCSLuaFile( “cl_init.lua” )
function ENT:SpawnFunction( ply, tr )
if not ( tr.Hit and ValidEntity(tr.Entity) and tr.Entity:GetModel():find"billboard") then return end
local ent = ents.Create"sent_billboard"
ent:SetPos( tr.Entity:GetPos() )
ent:SetAngles( tr.Entity:GetAngles() )
ent:Spawn()
ent:Activate()
local phys = ent:GetPhysicsObject()
if (phys:IsValid()) then
phys:EnableMotion(false)
end
ent:SetParent(tr.Entity)
return ent
end

function ENT:Initialize()
	self.Entity:SetModel"models/props_wasteland/interior_fence002d.mdl"
	self.Entity:SetMoveType( MOVETYPE_NONE )
	self.Entity:SetSolid( SOLID_NONE )
	self.Entity:DrawShadow(false)
	self.Entity:SetNWString("bb_Text1","Test Billboard")
	self.Entity:SetNWString("bb_Text2","May be buggy")
end
return

end

local rot = Vector(-90, 90, 0)
local width,height = 222,122
local borderw,borderh = 5,5
local mat = surface.GetTextureID"models/farp/whitemat"–“models/props_c17/metalladder003”
local function gettextsize(text,width,height)
local w,h,n = 0,0,0
for i = 50,20,-1 do
n = i
surface.CreateFont(“coolvetica”, i, 400, true, false, “bb”…i )
surface.SetFont(“bb”…i)
w,h = surface.GetTextSize(text)
if not (w and h) then
error(“wtf?”,w,h,n)
end
if w < width - 5 then
break
end
end
return w,h,n
end
function ENT:Draw()

local pos = self.Entity:GetPos() + (self.Entity:GetForward() * 2.1)
local ang = self.Entity:GetAngles()
ang:RotateAroundAxis(ang:Right(), 	rot.x)
ang:RotateAroundAxis(ang:Up(), 		rot.y)
ang:RotateAroundAxis(ang:Forward(), rot.z)
cam.Start3D2D(pos, ang,1)
	surface.SetDrawColor(225, 225, 225, 255)
	surface.SetTexture(mat)
	surface.DrawTexturedRect(width * -0.5,height * -0.5,width,height)
	surface.SetTextColor(0,0,0,255)
	local text = self.Entity:GetNWString("bb_Text1")
	if self.text1 ~= text then
		self.t1 = {gettextsize(text,width,height)}
		if self.t1[1] == 0 or self.t1[2] == 0 or self.t1[3] == 0 then
			error("gettextsize fail t1")
		end
		self.text1 = text
	end
	if self.t1[1] == 0 or self.t1[2] == 0 or self.t1[3] == 0 then
		return
	end
	surface.SetFont("bb"..self.t1[3])
	surface.SetTextPos(self.t1[1] * -0.5,self.t1[2] * -1 - 10)
	surface.DrawText(text)
	local text = self.Entity:GetNWString("bb_Text2")
	if self.text2 ~= text then
		self.t2 = {gettextsize(text,width,height)}
		if self.t2[1] == 0 or self.t2[2] == 0 or self.t2[3] == 0 then
			error("gettextsize fail t2")
		end
		self.text2 = text
	end
	if self.t2[1] == 0 or self.t2[2] == 0 or self.t2[3] == 0 then
		return
	end
	surface.SetFont("bb"..self.t2[3])
	surface.SetTextPos(self.t2[1] * -0.5,10)
	surface.DrawText(text)
cam.End3D2D()

end
[/lua]

Nice Coding i say

:>

you forgot at the top of the code :>
[lua]
if ( SERVER ) then
print("=============Adding File Blargh=================")
print(“AzuI5337/a/f4gg0t”)
AddCSLuaFile(“shared.lua”)
end
[/lua]

AzuiSleet isnt a faggot.

This man speaks the truth.

ecabc, I fixed the code for you.



if ( SERVER ) then
	print("=============Adding File Blargh=================")
	print("Av3r1c3/a/f4gg0t")
	AddCSLuaFile("shared.lua")
end


ye he is a cool guy and one hell of a coder

[lua]ENT.Type = “anim”
ENT.Base = “base_anim”

ENT.PrintName = “Target Icon”
ENT.Author = “Entoros”
ENT.Contact = “”
ENT.Purpose = “”
ENT.Instructions = “”

ENT.Spawnable = false
ENT.AdminSpawnable = false
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT;

if SERVER then
AddCSLuaFile(“shared.lua”)
AddCSLuaFile(“cl_init.lua”)
end

function ENT:Draw()
local pos = self.Owner():GetPos()
local ang = self.Owner():GetAngles()
cam.Start3D2D(pos,ang,1)
surface.SetDrawColor(255,255,255,255)
surface.SetTexture(“texture”)
surface.DrawTexturedRect(-50,-50,50,50)
end
end[/lua]

So creating this entity should make a square with a texture of “texture” at your feet?

what is 3d2d?

I’m pretty sure it’s a way of converting a 3d point into a 2d plane, so as you can view 3d objects as if they are 3d, although as you know, our screen is 2d.

ohh. k thanks

Ahem you forgot to end it.
[lua]cam.End3D2D( )[/lua]

xD Thanks man. So WITH that, should it work?

Yah…

[editline]10:23AM[/editline]

Or create a function server side…

[lua]
function test123( ply )
local lol = ents.Create(“entityname”)
lol:SetPos(ply:GetPos())
lol:Spawn()
lol:Activate()
end
concommand.Add(“rawr”, test123)
[/lua]

This following code will draw a large combine poster from HL2.
Doing this requires creating a new material, as you unfortunately can’t simply pick any texture you want and throw it in, you have to make one using the required shader.
For this, I made a material and put it in the file garrysmod/materials/combineposter.vmt
The contents of the file are:


"UnlitGeneric"
{
	"$baseTexture"  "props/paperposter003a"	 //The path to the texture we want to use
	"$nocull"		"1"	// Make the material show up on both sides. You can remove this if you only want it to be visible from the drawside.
}

The place where you put the material tells you the path to put in. Since this is in root materials, you just put the name in.
Here is the code:
[lua]ENT.Type = “anim”
ENT.Base = “base_anim”

ENT.PrintName = “Postaa”
ENT.Author = “Lexi”
ENT.Contact = “”
ENT.Purpose = “”
ENT.Instructions = “”

ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT;

if SERVER then
AddCSLuaFile( “shared.lua” )
AddCSLuaFile( “cl_init.lua” )
function ENT:SpawnFunction( ply, tr )
if not tr.Hit then return end
local ent = ents.Create(“sent_poster”)
ent:SetPos( tr.HitPos + tr.HitNormal * 52)
ent:Spawn()
ent:Activate()
local phys = ent:GetPhysicsObject()
if (phys:IsValid()) then
phys:EnableMotion(false)
end
return ent
end

function ENT:Initialize()
	self.Entity:SetModel("models/props_borealis/borealis_door001a.mdl")
	self.Entity:PhysicsInit( SOLID_VPHYSICS)
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS)
	self.Entity:SetSolid( SOLID_VPHYSICS)
	self.Entity:DrawShadow(false)
end
return

end
local rot = Vector(90, -90, 0)
local tex = surface.GetTextureID"combineposter" – This is the path/name of your material. You need to do this because of the way it works. You can’t just plug the name into SetTexture. You can shove a material made with Material() into surface.SetMaterial though.
function ENT:Draw()
–self.Entity:DrawModel() – We don’t want to draw the model, as it’d get in the way
local ang = self.Entity:GetAngles() – You need to rotate the 3d2d’s orentation somewhat, otherwise it’ll end up say, on the floor. Experement.
ang:RotateAroundAxis(ang:Right(), rot.x)
ang:RotateAroundAxis(ang:Up(), rot.y)
ang:RotateAroundAxis(ang:Forward(), rot.z)
cam.Start3D2D(self.Entity:GetPos(), ang ,0.1)
surface.SetDrawColor(225, 225, 225, 255)
local width,height = surface.GetTextureSize(tex) – Grab the width and height of the material. Better than guessing!
surface.SetTexture(tex) – Make the brush draw the texture
surface.DrawTexturedRect(-width,-height,width2,height2) – Draw the texture twice as large, centred.
cam.End3D2D()
end[/lua]

[lua]# local tex = surface.GetTextureID"combineposter" [/lua]

:40:Attempt to call string a nil value ()