Advertisement
Guest User

HUD section

a guest
Oct 20th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.65 KB | None | 0 0
  1. -- hud script!
  2. gih_y_modifier = 0
  3.  
  4. function perc(targetnumber, curnumber)
  5.     return math.ceil((curnumber * 100) / targetnumber)
  6. end
  7.  
  8. function experienceForLevel(lvl)
  9.     return (((50 * lvl * lvl * lvl) / 3) - (100 * lvl * lvl) + ((850 * lvl) / 3) - 200)
  10. end
  11.  
  12. function formatstaminaintotime(staminaAmount)
  13.     if (staminaAmount == 0) then
  14.         return "00:00"
  15.     else
  16.         local nHours = string.format("%02.f", math.floor(staminaAmount / 60))
  17.         local nMins = string.format("%02.f", math.floor(staminaAmount - (nHours * 60)))
  18.         return nHours .. ":" .. nMins
  19.     end
  20. end
  21.  
  22. function getBestSkill()
  23.     local skills = {
  24.         {name = 'sword',    p = swordpc},
  25.         {name = 'axe',      p = axepc},
  26.         {name = 'club',     p = clubpc},
  27.         {name = 'dist',     p = distancepc}
  28.     }
  29.    
  30.     local max_skill = {id = 0, value = 0}
  31.     for id, value in pairs({sword, axe, club, distance}) do
  32.         if (value > max_skill.value) then
  33.             max_skill.id = id
  34.             max_skill.value = value
  35.         end
  36.     end
  37.     return max_skill.value .. " " .. skills[max_skill.id].name .. " (" .. skills[max_skill.id].p .. "%)"
  38. end
  39.  
  40. function getStatus(bool)
  41.     return bool and "ON" or "OFF"
  42. end
  43.  
  44. function __enable(__name)
  45.     for _, section in ipairs(gih_hud_config) do
  46.         if (section.title == __name) then
  47.             section.enabled = not section.enabled
  48.             return true
  49.         end
  50.     end
  51.     return false
  52. end
  53.  
  54. function getBool(s)
  55.     return (s:lower() == "yes")
  56. end
  57.  
  58. function t_setting(s)
  59.     setsettings(s, ((getsettings(s):lower() == "yes") and "no" or "yes"))
  60. end
  61.  
  62. function rgba_to_bgra(r, g, b, a)
  63.     return b, g, r, a
  64. end
  65.  
  66. function build_params(a)
  67.     return 0.0, rgbcolor(rgba_to_bgra(unpack(a[1]))), 0.23, rgbcolor(rgba_to_bgra(unpack(a[2]))), 0.76, rgbcolor(rgba_to_bgra(unpack(a[3])))
  68. end
  69.  
  70. function enableMovement()
  71.     gih_moving.s = true
  72.     gih_moving.sx = cursorinfo().cx
  73.     gih_moving.sy = cursorinfo().cy
  74. end
  75.  
  76. function disableMovement()
  77.     if gih_moving.s then
  78.         gih_moving.s = false
  79.         gih_pos.x = gih_pos.x + cursorinfo().cx - gih_moving.sx
  80.         gih_pos.y = gih_pos.y + cursorinfo().cy - gih_moving.sy
  81.     end
  82. end
  83.  
  84. -- tricky but works
  85. local cbid = 1
  86. onClick_callbacks = {}
  87.  
  88. gih_y_modifier = gih_y_modifier + 10
  89.  
  90. if not gih_font.default_font then
  91.     setfontstyle(gih_font.name, gih_font.size, gih_font.style)
  92. end
  93.  
  94. setpen(unpack(gih_colors.borders))
  95. if gih_colors.headers.gradient then
  96.     addgradcolors(build_params(gih_colors.headers.gradmode))
  97.     setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  98. else
  99.     setfillcolor(unpack(gih_colors.headers.rgbamode))
  100. end
  101.  
  102. local movable = addrect(gih_pos.x, gih_pos.y + gih_y_modifier, gih_width, 20)
  103.  
  104. onClick_callbacks[cbid] = function()
  105.     return enableMovement()
  106. end
  107. addevent(movable, MOUSE_LEFT_DOWN, "onClick_callbacks[" .. cbid .. "]()")
  108. cbid = cbid + 1
  109.  
  110. onClick_callbacks[cbid] = function()
  111.     return disableMovement()
  112. end
  113. addevent(movable, MOUSE_LEFT_UP, "onClick_callbacks[" .. cbid .. "]()")
  114. cbid = cbid + 1
  115.  
  116. setfontcolor(unpack(gih_font.color))
  117. addtextstroke("General Information HUD v1.0.0+", gih_pos.x + 7, gih_pos.y + gih_y_modifier + 15)   
  118. gih_y_modifier = gih_y_modifier + 20   
  119.  
  120. if script_infromation.show then
  121.     setpen(unpack(gih_colors.borders))
  122.     if gih_colors.headers.gradient then
  123.         addgradcolors(build_params(gih_colors.headers.gradmode))
  124.         setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  125.     else
  126.         setfillcolor(unpack(gih_colors.headers.rgbamode))
  127.     end
  128.     addrect(gih_pos.x, gih_pos.y + gih_y_modifier, gih_width / 2, 20)
  129.    
  130.     setfontcolor(unpack(gih_font.color))
  131.     addtextstroke(script_infromation.sponsor, gih_pos.x + 7, gih_pos.y + gih_y_modifier + 15)          
  132.  
  133.     setpen(unpack(gih_colors.borders))
  134.     if gih_colors.itvalue.gradient then
  135.         addgradcolors(build_params(gih_colors.itvalue.gradmode))
  136.         setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  137.     else
  138.         setfillcolor(unpack(gih_colors.itvalue.rgbamode))
  139.     end
  140.     addrect(gih_pos.x + gih_width / 2, gih_pos.y + gih_y_modifier, gih_width / 2, 20)
  141.  
  142.     setfontcolor(unpack(gih_font.color))
  143.     addtextstroke(script_infromation.website, gih_pos.x + 7 + gih_width / 2, gih_pos.y + gih_y_modifier + 15)  
  144.     gih_y_modifier = gih_y_modifier + 20
  145.        
  146.     setpen(unpack(gih_colors.borders))
  147.     if gih_colors.ittitle.gradient then
  148.         addgradcolors(build_params(gih_colors.ittitle.gradmode))
  149.         setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  150.     else
  151.         setfillcolor(unpack(gih_colors.ittitle.rgbamode))
  152.     end
  153.     addrect(gih_pos.x, gih_pos.y + gih_y_modifier, gih_width, 20)
  154.    
  155.     setfontcolor(unpack(gih_font.color))
  156.     addtextstroke(script_infromation.name, gih_pos.x + 7, gih_pos.y + gih_y_modifier + 15)     
  157.     gih_y_modifier = gih_y_modifier + 20
  158.    
  159.     setpen(unpack(gih_colors.borders))
  160.     if gih_colors.ittitle.gradient then
  161.         addgradcolors(build_params(gih_colors.ittitle.gradmode))
  162.         setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  163.     else
  164.         setfillcolor(unpack(gih_colors.ittitle.rgbamode))
  165.     end
  166.     addrect(gih_pos.x, gih_pos.y + gih_y_modifier, gih_width / 2, 20)
  167.    
  168.     setfontcolor(unpack(gih_font.color))
  169.     addtextstroke("Script version", gih_pos.x + 7, gih_pos.y + gih_y_modifier + 15)        
  170.  
  171.     setpen(unpack(gih_colors.borders))
  172.     if gih_colors.itvalue.gradient then
  173.         addgradcolors(build_params(gih_colors.itvalue.gradmode))
  174.         setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  175.     else
  176.         setfillcolor(unpack(gih_colors.itvalue.rgbamode))
  177.     end
  178.     addrect(gih_pos.x + gih_width / 2, gih_pos.y + gih_y_modifier, gih_width / 2, 20)
  179.  
  180.     setfontcolor(unpack(gih_font.color))
  181.     addtextstroke(script_infromation.version, gih_pos.x + 7 + gih_width / 2, gih_pos.y + gih_y_modifier + 15)  
  182.     gih_y_modifier = gih_y_modifier + 20
  183.    
  184.     setpen(unpack(gih_colors.borders))
  185.     if gih_colors.ittitle.gradient then
  186.         addgradcolors(build_params(gih_colors.ittitle.gradmode))
  187.         setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  188.     else
  189.         setfillcolor(unpack(gih_colors.ittitle.rgbamode))
  190.     end
  191.     addrect(gih_pos.x, gih_pos.y + gih_y_modifier, gih_width / 2, 20)
  192.    
  193.     setfontcolor(unpack(gih_font.color))
  194.     addtextstroke("Author", gih_pos.x + 7, gih_pos.y + gih_y_modifier + 15)        
  195.  
  196.     setpen(unpack(gih_colors.borders))
  197.     if gih_colors.itvalue.gradient then
  198.         addgradcolors(build_params(gih_colors.itvalue.gradmode))
  199.         setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  200.     else
  201.         setfillcolor(unpack(gih_colors.itvalue.rgbamode))
  202.     end
  203.     addrect(gih_pos.x + gih_width / 2, gih_pos.y + gih_y_modifier, gih_width / 2, 20)
  204.  
  205.     setfontcolor(unpack(gih_font.color))
  206.     addtextstroke(script_infromation.author, gih_pos.x + 7 + gih_width / 2, gih_pos.y + gih_y_modifier + 15)   
  207.     gih_y_modifier = gih_y_modifier + 20
  208. end
  209.  
  210. for _, section in ipairs(gih_hud_config) do
  211.     setpen(unpack(gih_colors.borders))
  212.     if gih_colors.headers.gradient then
  213.         addgradcolors(build_params(gih_colors.headers.gradmode))
  214.         setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  215.     else
  216.         setfillcolor(unpack(gih_colors.headers.rgbamode))
  217.     end
  218.  
  219.     addrect(gih_pos.x, gih_pos.y + gih_y_modifier, gih_width, 20)
  220.    
  221.     setfontcolor(unpack(gih_font.color))
  222.     addtextstroke(section.title, gih_pos.x + 7, gih_pos.y + gih_y_modifier + 15)
  223.    
  224.     setpen(unpack(gih_colors.borders))
  225.     if gih_colors.cstatus.gradient then
  226.         addgradcolors(build_params(section.enabled and gih_colors.cstatus.gradmode.on or gih_colors.cstatus.gradmode.off))
  227.         setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  228.     else
  229.         setfillcolor(unpack(section.enabled and gih_colors.cstatus.rgbamode.on or gih_colors.cstatus.rgbamode.off))
  230.     end
  231.    
  232.     local minimizeRect = addrect(gih_pos.x + gih_width - 20, gih_pos.y + gih_y_modifier, 20, 20)
  233.     onClick_callbacks[cbid] = function()
  234.         return __enable(section.title)
  235.     end
  236.     addevent(minimizeRect, MOUSE_LEFT_DOWN, "onClick_callbacks[" .. cbid .. "]()")
  237.     cbid = cbid + 1
  238.    
  239.     setfontcolor(unpack(gih_font.color))
  240.     addtextstroke("-", gih_pos.x + 7 + gih_width - 20, gih_pos.y + gih_y_modifier + 15)
  241.  
  242.     gih_y_modifier = gih_y_modifier + 20
  243.    
  244.     if section.enabled then
  245.         for _, item in ipairs(section.items) do
  246.             setpen(unpack(gih_colors.borders))
  247.             if gih_colors.ittitle.gradient then
  248.                 addgradcolors(build_params(gih_colors.ittitle.gradmode))
  249.                 setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  250.             else
  251.                 setfillcolor(unpack(gih_colors.ittitle.rgbamode))
  252.             end
  253.             addrect(gih_pos.x, gih_pos.y + gih_y_modifier, gih_width / 2, 20)
  254.            
  255.             setfontcolor(unpack(gih_font.color))
  256.             addtextstroke(item.name, gih_pos.x + 7, gih_pos.y + gih_y_modifier + 15)           
  257.            
  258.             if (item.onClick == nil) then
  259.                 setpen(unpack(gih_colors.borders))
  260.                 if gih_colors.itvalue.gradient then
  261.                     addgradcolors(build_params(gih_colors.itvalue.gradmode))
  262.                     setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  263.                 else
  264.                     setfillcolor(unpack(gih_colors.itvalue.rgbamode))
  265.                 end
  266.                 addrect(gih_pos.x + gih_width / 2, gih_pos.y + gih_y_modifier, gih_width / 2, 20)
  267.  
  268.                 setfontcolor(unpack(gih_font.color))           
  269.                 addtextstroke(tostring(item.callback()), gih_pos.x + 7 + gih_width / 2, gih_pos.y + gih_y_modifier + 15)       
  270.             else
  271.                 local __status = item.callback()               
  272.                 onClick_callbacks[cbid] = item.onClick
  273.                
  274.                 setpen(unpack(gih_colors.borders))
  275.                 if gih_colors.cstatus.gradient then
  276.                     addgradcolors(build_params(__status and gih_colors.cstatus.gradmode.on or gih_colors.cstatus.gradmode.off))
  277.                     setfillstyle('gradient', 'linear', 1, 0, 0, 0, 50)
  278.                 else
  279.                     setfillcolor(unpack(__status and gih_colors.cstatus.rgbamode.on or gih_colors.cstatus.rgbamode.off))
  280.                 end
  281.                
  282.                 local rect = addrect(gih_pos.x + gih_width / 2, gih_pos.y + gih_y_modifier, gih_width / 2, 20)
  283.                 addevent(rect, MOUSE_LEFT_DOWN, "onClick_callbacks[" .. cbid .. "]()")
  284.                 cbid = cbid + 1
  285.  
  286.                 setfontcolor(unpack(gih_font.color))           
  287.                 addtextstroke(getStatus(__status), gih_pos.x + 7 + gih_width / 2, gih_pos.y + gih_y_modifier + 15) 
  288.             end
  289.             gih_y_modifier = gih_y_modifier + 20
  290.         end
  291.     end
  292. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement