Results 1 to 1 of 1

Thread: Simple HUD system

  1. #1
    Normal User
    Join Date
    May 2012
    Location
    England
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    16
    Rep Power
    5

    Simple HUD system

    So if you've made a script and want a basic "entry level" HUD, I made the perfect code for you!

    Sample:



    This just an example of what's possible using this system.

    Code:
    -- { FONT SIZE } --
    local fontsize = 8
    
    -- { FONT COLOUR } --
    local fontcolour = "white"
    
    -- { FONT STYLE } --
    local fontface = "Verdana"
    
    -- Configuring Font and Positioning, do not edit unless you know what you're doing, your HUD may disappear as a result.
    local startx = 18
    local rightx = 120
    local starty = 28
    local fontspacing = fontsize+2
    local linestep = fontsize + 4
    setfontstyle(fontface, fontsize, fontcolour)
    setfontcolor(fontcolour)
    
    function display(string1, string2, line)
       addtext(string1, startx, starty + line * linestep)
       addtext(": " .. string2, rightx, starty + line * linestep)
    end
    
    function displaytitle(string1, linestart)
       addtext("---------------------------------------------", startx - 10, starty + linestart * linestep)
       addtext(string1, startx, starty + (linestart + 1) * linestep)
       addtext("---------------------------------------------", startx - 10, starty + (linestart + 2) * linestep)
    end
    
    local function ExperienceToLevel(LEVEL)
    	return 50 / 3 * (LEVEL ^ 3 - 6 * LEVEL ^ 2 + 17 * LEVEL - 12)
    end
    
    local function LevelPercent()
    	return 100 - math.floor((exp - ExperienceToLevel(level)) * 100 / (ExperienceToLevel(level + 1) - ExperienceToLevel(level)))
    end
    
    function displayexpbar(linestart)
       addtext("Exp Bar", startx, starty + linestart * linestep)
       addtext(": ", rightx, starty + linestart * linestep)
       local i = 0
       while i<=100 do
          beginbar = rightx + 5
          drawpos = beginbar + i
          if i < (100 - LevelPercent()) then
             setfontcolor("green")
             addtext("|", drawpos, starty + (linestep * linestart))
             setfontcolor(fontcolour)
             i = i + 1
          else
             setfontcolor("gray")
             addtext("|", drawpos, starty + (linestep * linestart))
             setfontcolor(fontcolour)
             i = i + 1
          end
       end
       addtext(LevelPercent() .. "% to go", rightx + 30, starty + linestart * linestep)
    end
    
    
    
    
    function displayexpbarwide(linestart)
       local i = 0
       while i<=100 do
          beginbar = startx + 5
          drawpos = beginbar + i
          if i < (100 - LevelPercent()) then
             setfontcolor("green")
             addtext("|", drawpos + i, starty + (linestep * linestart))
             setfontcolor(fontcolour)
             i = i + 1
          else
             setfontcolor("gray")
             addtext("|", drawpos + i, starty + (linestep * linestart))
             setfontcolor(fontcolour)
             i = i + 1
          end
       end
       addtext(LevelPercent() .. "% to go", startx + 80, starty + linestart * linestep)
    end
    
    
    
    
    
    
    
    
    displaytitle("HUD by XtrmJosh", 1)
    
    display("Character", name, 4)
    display("Level", level, 5)
    display("Experience", exp, 6)
    display("Exp Per Hour", exphour, 7)
    display("Location", posx .. ", " .. posy .. ", " .. posz, 8)
    display("Exp To Level", ExperienceToLevel(level + 1) - exp, 9)
    displayexpbar(10)
    displayexpbarwide(11)


    Basically just pop that into a HUD script, and at the end add

    display(string para 1, string para 2, int line number)

    It will display para 1 on the left, para 2 on the right level with it, at the line number set (aka line 1 is top, then line 2, then line 3, then line 4, all down the edge of your screen, like so:

    Code:
    -------------------------------
         HUD by XtrmJosh
    -------------------------------
    
    Character    : Paladski
    Level        : 82
    Experience   : 8,800,805
    Exp Per Hour : 52027
    Location     : 32478, 31198, 10
    Use it as you wish, only took me 10 mins to put together and makes HUD making a bit simpler

    You can also now add titles (like where it says HUD by XtrmJosh). They take up 3 lines, so make sure you account for this in your HUD script.

    displaytitle(string titletext, int startline)

    Displays titletext sandwiched between 2 lines of -----------------------, with the first line of them at startline.

    You can now add displayexpbar(int startline) to add a drawn exp bar, using a standard character; |. Check it out! It draws your exp bar on screen!!! Also added text over this to show % remaining (e.g 99% to go).

    Also added displayexpbarwide(int startline) to add a drawn exp bar which is full width, with no "defining" text, other than the % to go drawn over it.
    Last edited by XtrmJosh; 08-25-2012 at 04:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •