1. Post #1

    August 2011
    60 Posts
    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:

    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))
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  2. Post #2
    JustSoFaded's Avatar
    December 2011
    432 Posts
    Just change it to draw.SimpleText, fix the args and re-position each group of words.

    Edited:

    Also, this isn't the correct place for this thread.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Useful Useful x 1 (list)

  3. Post #3

    August 2011
    60 Posts
    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?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  4. Post #4
    SeveredSkull's Avatar
    October 2008
    1,316 Posts
    JustSoFaded means you must change draw.WordBox to draw.SimpleText and fix the parameters that are being passed into the function.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  5. Post #5

    August 2011
    60 Posts
    Ahh thanks I just didn't understand that he meant parameters
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  6. Post #6
    SeveredSkull's Avatar
    October 2008
    1,316 Posts
    Yes. Parameters and Arguments (args) are the same thing...
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  7. Post #7

    August 2011
    60 Posts
    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?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  8. Post #8
    SeveredSkull's Avatar
    October 2008
    1,316 Posts
    draw.SimpleText( String Text, String Font, Number X, Number Y, Color Color, Number Xalign, Number Yalign )

    See this page:
    http://maurits.tv/data/garrysmod/wik...indexe61e.html
    Reply With Quote Edit / Delete Windows 7 United States Show Events Useful Useful x 1 (list)

  9. Post #9

    August 2011
    60 Posts
    Thanks much appreciated
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  10. Post #10
    JustSoFaded's Avatar
    December 2011
    432 Posts
    Try this:

    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
    

    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.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Lua Helper Lua Helper x 1Useful Useful x 1 (list)

  11. Post #11

    August 2011
    60 Posts
    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
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  12. Post #12
    JustSoFaded's Avatar
    December 2011
    432 Posts
    Actually I just realized the positioning will be a bit off with that code. Try this instead:

    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
    
    Reply With Quote Edit / Delete Windows 7 United States Show Events Lua Helper Lua Helper x 1 (list)

  13. Post #13
    SeveredSkull's Avatar
    October 2008
    1,316 Posts
    Also when I press e on it now I don't receive any money from it. [/CODE]
    Thats a whole different issue... Where did you get this printer from?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  14. Post #14

    August 2011
    60 Posts
    I started with a wiki and then looked at some examples of other money printers
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  15. Post #15
    SeveredSkull's Avatar
    October 2008
    1,316 Posts
    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?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  16. Post #16

    August 2011
    60 Posts
    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.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  17. Post #17
    SeveredSkull's Avatar
    October 2008
    1,316 Posts
    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?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  18. Post #18

    August 2011
    60 Posts
    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:
    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
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  19. Post #19
    SeveredSkull's Avatar
    October 2008
    1,316 Posts
    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)
    Reply With Quote Edit / Delete Windows 7 United States Show Events Useful Useful x 1 (list)

  20. Post #20

    August 2011
    60 Posts
    Thanks
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  21. Post #21
    JustSoFaded's Avatar
    December 2011
    432 Posts
    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.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  22. Post #22

    August 2011
    60 Posts
    function ENT:Use(activator)
    
    if(activator:IsPlayer()) then
    activator:AddMoney(self:GetNWInt("PrintA"));
    self:SetNWInt("PrintA",0)
    end
    
    end

    But it works now after I used:

    	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()
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  23. Post #23
    SeveredSkull's Avatar
    October 2008
    1,316 Posts
    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
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  24. Post #24

    August 2011
    60 Posts
    They were in the relevent files. Its strange but it works now.
    Reply With Quote Edit / Delete United Kingdom Show Events