Changing Text

Hi, I was wondering if someone could help me I would like to change the text on this money printer(shown below) to the text which is shown in the second photo.

Current Money Printer Text:

Desired Text:

I think it will be to do with this code:


include("shared.lua")
 
function ENT:Initialize()
end
 
function ENT:Draw()
    self.Entity:DrawModel()
     
    local Pos = self:GetPos()
    local Ang = self:GetAngles()
     
    local owner = self.dt.owning_ent
    owner = (ValidEntity(owner) and owner:Nick()) or "unknown"
    amount = self:GetDTInt(0) or 0
     
    surface.SetFont("HUDNumber5")
    local TextWidth = surface.GetTextSize("Money printer")
    local TextWidth2 = surface.GetTextSize("Contains: $"..amount)
     
    Ang:RotateAroundAxis(Ang:Up(), 90)
     
    cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11)
        draw.WordBox(2, -TextWidth*0.5, -30, "Money printer", "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
        draw.WordBox(2, -TextWidth2*0.5, 66, "Contains: $"..amount, "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
    cam.End3D2D()
end
 
function ENT:Think()
end

Thanks In Advance


(User was banned for this post ("Wrong section" - Gran PC))

Just change it to draw.SimpleText, fix the args and re-position each group of words.

[editline]14th June 2012[/editline]

Also, this isn’t the correct place for this thread.

Ok thanks, sorry about posting in wrong section I thought because it was LUA it would go best in the LUA Section. When you say fix the args, I’m unsure what needs fixing?

JustSoFaded means you must change draw.WordBox to draw.SimpleText and fix the parameters that are being passed into the function.

Ahh thanks I just didn’t understand that he meant parameters

Yes. Parameters and Arguments (args) are the same thing…

Will the parameters being passed be from the same file or will they be from init.lua, because I’m don’t see what parameters are wrong?

draw.SimpleText( String Text, String Font, Number X, Number Y, Color Color, Number Xalign, Number Yalign )

See this page:

Thanks much appreciated

Try this:

[lua]
function ENT:Draw()
self.Entity:DrawModel()

local Pos = self:GetPos()
local Ang = self:GetAngles()
 
local owner = self.dt.owning_ent
owner = (ValidEntity(owner) and owner:Nick()) or "unknown"
amount = self:GetDTInt(0) or 0
 
surface.SetFont("HUDNumber5")
local TextWidth = surface.GetTextSize("Money printer")
local TextWidth2 = surface.GetTextSize("Contains: $"..amount)
 
Ang:RotateAroundAxis(Ang:Up(), 90)
 
cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11)
    draw.SimpleText("Money Printer", "TargetID", -TextWidth*0.5, -30, Color(255, 255, 255, 255));
    draw.SimpleText("Contains: $"..amount, "TargetIDSmall", -TextWidth2*0.5, 66, Color(255, 255, 255, 255));
cam.End3D2D()

end
[/lua]

As draw.WordBox & draw.SimpleText require different variables passed into scope you needed to extract the args from the draw.WordBox that you need (x, y pos mainly) and apply it to draw.SimpleText. I have done this for you in the code above.

Thanks, I used your code but noticed that the text was off to the left of the object so I used to syntax to try to align the text but the text would align to the center of the box. My code is below. Also when I press e on it now I don’t receive any money from it.


function ENT:Draw()
    self.Entity:DrawModel()
      
    local Pos = self:GetPos()
    local Ang = self:GetAngles()
      
    local owner = self.dt.owning_ent
    owner = (ValidEntity(owner) and owner:Nick()) or "unknown"
    amount = self:GetDTInt(0) or 0
      
    surface.SetFont("HUDNumber5")
    local TextWidth = surface.GetTextSize("Money printer")
    local TextWidth2 = surface.GetTextSize("Contains: $"..amount)
      
    Ang:RotateAroundAxis(Ang:Up(), 90)
      
    cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11)
        draw.SimpleText("Money Printer", "TargetID", -TextWidth*0.5, -30, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
        draw.SimpleText("$"..amount, "TargetIDSmall", -TextWidth2*0.5, 66, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
    cam.End3D2D()
end

Actually I just realized the positioning will be a bit off with that code. Try this instead:

[lua]
function ENT:Draw()
self.Entity:DrawModel()

local Pos = self:GetPos()
local Ang = self:GetAngles()
  
local owner = self.dt.owning_ent
owner = (ValidEntity(owner) and owner:Nick()) or "unknown"
amount = self:GetDTInt(0) or 0
  
surface.SetFont("TargetID")
local TextWidth = surface.GetTextSize("Money printer")

surface.SetFont("TargetIDSmall");
local TextWidth2 = surface.GetTextSize("Contains: $"..amount)
  
Ang:RotateAroundAxis(Ang:Up(), 90)
  
cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11)
    draw.SimpleText("Money Printer", "TargetID", -TextWidth*0.5, -30, Color(255, 255, 255, 255));
    draw.SimpleText("Contains: $"..amount, "TargetIDSmall", -TextWidth2*0.5, 66, Color(255, 255, 255, 255));
cam.End3D2D()

end
[/lua]

Thats a whole different issue... Where did you get this printer from?

I started with a wiki and then looked at some examples of other money printers

Then odds are you did not code your ENT:Use() hook correctly to give the player money.

Did this work before you added this drawing code in or did it not work at all before?

It worked before the drawing code, so I will re do it with the worldbox text and then try it again, I properly just added something by accident.

Well when things tend not to work, usually it involves an error… Would you mind giving it to us if there is any?

I’ve got it working with the function below, but the text is overlapped does anyone suggest how I could fix this. Also is it possible to make the text appear closer to the model and so you can see it from whichever angle you look at?

Code:
[LUA]function ENT:Draw()
self.Entity:DrawModel()

local Pos = self:GetPos()
local Ang = self:GetAngles()

txt1 = "Money Printer"
txt2 = "$" ..self:GetNWInt("PrintA")

surface.SetFont("HUDNumber5")
local TextWidth = surface.GetTextSize(txt1)
local TextWidth2 = surface.GetTextSize(txt2)

Ang:RotateAroundAxis(Ang:Up(), 90)

cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11)
	draw.SimpleText(txt1, DefaultFixedDropShadow, 0, 0, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
	draw.SimpleText(txt2, DefaultFixedDropShadow, 0, 0, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
cam.End3D2D()

end[/LUA]

Line 16 is your position. Change that. reduce 11.5 to something (up to you… will require fiddling, but that is the number in units above the position of the printer)

Thanks