Update 3d2d?

Not sure if “updating” the 3d2d is the right word.

I’m working on a moneyprinter addon, and I’m trying to update the 3d2d textscreen showing the amount of paper left.

Whenever I try to use self:Draw it throws the error:


[ERROR] addons/advancedmp/lua/entities/amp_base/cl_init.lua:38: attempt to index global 'self' (a nil value)
  1. func - addons/advancedmp/lua/entities/amp_base/cl_init.lua:38
   2. unknown - lua/includes/extensions/net.lua:32


Can I use self in clientside? I should be able to because earlier I used: self.Paper in drawing simple text.

This is the code for cl_init.lua


net.Receive("Update3d2d", function()
self:Draw()
end)

and for init.lua:


function ENT:AddPaper(amount)
self.Paper = self.Paper + amount
net.Start("Update3d2d")
net.Broadcast()
end

On another note, is there an easy way to adjust 3d2d textscreens? It’s a bit boggling trying to get it in the right position. Any help is appreciated, thanks.

You can only use ‘self’ within functions of the entity. For example:
[lua]function ENT:AddPaper(amount)
– self is usable here
end

– self is NOT usable here

net.Receive(“Update3d2d”, function()
– self is NOT usable here
end)[/lua]

What exactly are you trying to do?

Everytime paper is added to the printer, the 3d2d textscreen should be updated to reflect that change.

It doesn’t do it currently.

Show the code that draws the 3D2D

Please ignore the awkward 3d positions of the draw itself, I’m still trying to figure out how to adjust it


function ENT:Draw()
self:DrawModel()
local Pos = self:GetPos()
local Ang = self:GetAngles()
local text = self.PrintName
local TextWidth = surface.GetTextSize(text)

cam.Start3D2D(self:GetPos() + Ang:Up() * 11.5, Ang, 0.3)
draw.RoundedBox(0,0,0,100,25,Color(0,0,0, 155))
draw.SimpleText("Paper: "..self.Paper, "ChatFont", 100-TextWidth*2.6,25-(TextWidth/2),Color(255,255,255), 0, 0)
cam.End3D2D()
end

its because you dont send the new paper value in the Update3D2D netmessage, you only start it and send it whilst being empty, send the integrer of the paper amount, and update ENT.Paper with it.

[editline]16th April 2016[/editline]

About the positioning, go on youtube and search up Code Blue, he shows a simple way to adjust them.

Hah, I’m actually learning from code blue. I’ll tell you later if that works, busy doing something else right now.