• Changing Text
    23 replies, posted
  • 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: [IMG]http://i.imgur.com/WWLNw.png[/IMG] Desired Text: [IMG]http://i.imgur.com/tVWJe.png[/IMG] I think it will be to do with this code: [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[/CODE] Thanks In Advance [highlight](User was banned for this post ("Wrong section" - Gran PC))[/highlight]
  • Avatar of JustSoFaded
  • 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?
  • Avatar of SeveredSkull
  • JustSoFaded means you must change draw.WordBox to draw.SimpleText and fix the parameters that are being passed into the function.
  • 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?
  • Avatar of SeveredSkull
  • draw.SimpleText( String Text, String Font, Number X, Number Y, Color Color, Number Xalign, Number Yalign ) See this page: [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexe61e.html[/url]
  • Avatar of JustSoFaded
  • 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. [CODE]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[/CODE]
  • Avatar of JustSoFaded
  • 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]
  • Avatar of SeveredSkull
  • [QUOTE=Scotty1207;36327814] Also when I press e on it now I don't receive any money from it. [/CODE][/QUOTE] Thats a whole different issue... Where did you get this printer from?
  • Avatar of SeveredSkull
  • 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.
  • Avatar of SeveredSkull
  • [QUOTE=Scotty1207;36328151]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.[/QUOTE] 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]
  • Avatar of SeveredSkull
  • 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)
  • Avatar of JustSoFaded
  • Your problem is that your ENT:Use() function is either not defined, or not being called. It could also be that the Use function is erroring, please post your money printers ENT:Use() function so we can help.
  • [lua]function ENT:Use(activator) if(activator:IsPlayer()) then activator:AddMoney(self:GetNWInt("PrintA")); self:SetNWInt("PrintA",0) end end[/lua] But it works now after I used: [lua] cam.Start3D2D(Pos + Ang:Up() * 5.0, 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, 12.5, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) cam.End3D2D()[/lua]
  • Avatar of SeveredSkull
  • Do you by chance have this all in one file? because the ENT:Draw() function should be in a file called cl_init.lua and the rest should be in either init.lua or shared.lua You need to split up your locations based on the type of functions you are using. Clientside scripts (Like huds and text drawing) should be in cl_init, and any serverside scripts should be in init.lua. Shared scripts ( things you want both the server and client to do) should be in shared.lua