Advertisement
Fwaky

HultinHud v2 - Tibia - Windbot

Apr 8th, 2014
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.13 KB | None | 0 0
  1. init start
  2. -- Hultin's Hud v2.0.0
  3. -- Last update: 8th April 2014
  4.  
  5.     -- Script author - This is where you put your name.
  6.     -- The rest of the script info is entered into Cavebot->Edit useroptions.
  7.     local ScriptAuthor = "Hultin"
  8.    
  9.     -- Set to true if you are developing a script. Remember to set to false when you release/sell it.
  10.     local Development = false
  11.  
  12.     -- Configuration for width/height
  13.     local FieldConfig = {
  14.         Height = 22, -- Optimized for 22px. Sizes lower than 20 looks weird and narrow, keep that in mind if you set the height lower.
  15.         Width  = 260, -- Total width of the HUD. Value/Field widths are automatically calculated.
  16.     }
  17.  
  18.  
  19.     -- You can add more color points to create a gradient. The current implementation is just a flat gradient.
  20.     -- First value is graident point, color(r, g, b, a)
  21.     -- Alpha is 0-100, 0 is non-transparent 100 is fully see through (no color!)
  22.     local Colors = {
  23.         HeaderColor =       {1, color(41, 79, 109, 10)},
  24.             HeaderInnerBorder   = color(58, 106, 140, 10),
  25.         FieldColor  =       {1, color(40, 40, 40, 10)},
  26.             FieldInnerBorder    = color(74, 74, 74, 10),
  27.         ValueNeutral =      {1, color(158, 104, 0, 10)},
  28.             NeutralInnerBorder  = color(166, 124, 44, 10),
  29.         ValuePositive =     {1, color(67, 99, 13, 10)},
  30.             PositiveInnerBorder = color(94, 119, 53, 10),
  31.         ValueNegative =     {1, color(139, 37, 13, 10)},
  32.             NegativeInnerBorder = color(150, 72, 54, 10),
  33.         Transparent  =      {1, color(0, 0, 0, 100)},
  34.             NoInnerBorder       = color(0, 0, 0, 100)
  35.     }
  36.  
  37.    
  38.     -- This value configures the width of the valuefield.
  39.     FieldConfig.ValueWidth = FieldConfig.Width/2.2
  40.  
  41.     -- This variables controlls the "Toggle all on/off" button & it's text
  42.     local AllOn = true
  43.  
  44.     -- Enginestates are treated and created diffrently than other elements are.
  45.     local Engines = {
  46.         {Name = 'Cavebot', Element = 0},
  47.         {Name = 'Looting', Element = 0},
  48.         {Name = 'Targeting', Element = 0},
  49.         {Name = 'Spell Healer', Element = 0},
  50.         {Name = 'Potion Healer', Element = 0},
  51.         {Name = 'Condition Healer', Element = 0}
  52.     }
  53.    
  54.     -- Toggles all state on/off.
  55.     function togglestates(state)
  56.         for _, e in ipairs(Engines) do
  57.             setsetting(e.Name:gsub(' ', '') .. '/Enabled', state)
  58.         end
  59.     end
  60.     -- Input events.
  61.     -- Keys, Mouseclicks, Mousemoves, Stealfocus
  62.     filterinput(false, true, false, false)
  63.     -- Allows interaction with hud, aswell as adds the ability to move the HUD.
  64.     function inputevents(e)
  65.         if e.type == IEVENT_LMOUSEUP then
  66.             for _, v in ipairs(Engines) do
  67.                 print(v)
  68.                 print(e.elementid)
  69.                 if e.elementid == v.Element then
  70.                     toggle(v.Name:gsub(' ', '') .. '/Enabled')
  71.                     return
  72.                 end
  73.                
  74.             end
  75.             if(e.elementid == Toggleall) then
  76.                 if(AllOn) then
  77.                     togglestates("no")
  78.                     AllOn = false
  79.                 else
  80.                     togglestates("yes")
  81.                     AllOn = true
  82.                 end
  83.             end
  84.         end
  85.     end
  86.  
  87.     local Elements = {}
  88. init end
  89. --[[ Functions ]]--
  90.  
  91. -- Returns a formated textstring for your vip and such.
  92. function viptext()
  93.     local total = 0
  94.     local online = 0
  95.     foreach vipentry v do
  96.         total = total +1
  97.         if(v.isonline) then
  98.             online = online + 1
  99.         end
  100.     end
  101.     return total..' ('..online..')'
  102. end
  103.  
  104. -- Works like PHPs ucfirst()
  105. -- http://www.php.net/manual/en/function.ucfirst.php
  106. function firstToUpper(str)
  107.     return (str:gsub("^%l", string.upper))
  108. end
  109.  
  110. -- Credit to SIRMATE
  111. function WeaponSkill()
  112.     local SkillTypes = {
  113.         ['axe'] = {type = 'axe', skill = $axe, skillpc = $axepc},
  114.         ['club'] = {type = 'club', skill = $club, skillpc = $clubpc},
  115.         ['sword'] = {type = 'sword', skill = $sword, skillpc = $swordpc},
  116.         ['bow'] = {type = 'distance', skill = $distance, skillpc = $distancepc},
  117.         ['distance weapon'] = {type = 'distance', skill = $distance, skillpc = $distancepc},
  118.         ['no weapon'] = {type = 'fist', skill = $fist, skillpc = $fistpc},
  119.         ['rod'] = {type = 'magic', skill = $mlevel, skillpc = $mlevelpc},
  120.         ['wand'] = {type = 'magic', skill = $mlevel, skillpc = $mlevelpc},
  121.     }
  122.  
  123.     return SkillTypes[findweapontype()]
  124. end
  125.  
  126. -- String used for Weaponskill/Magiclevel section of the HUD.
  127. local TypeSkill = WeaponSkill() or {type = 'magic', skill = $mlevel, skillpc = $mlevelpc}
  128. -- Default values to not leave any field/values blank.
  129. local ScriptName = getuseroption('scriptname')
  130. local ScriptVersion = getuseroption('scriptversion')
  131. if(string.len(ScriptName) == 0) then
  132.     ScriptName = 'Script name'
  133. end
  134. if(string.len(ScriptVersion) == 0) then
  135.     ScriptVersion = "1.0.0"
  136. end
  137. -- Sections, you can add/remove elements as you please.
  138. local Sections = {
  139.         {
  140.             Name = ScriptName,
  141.             Display = true,
  142.             Items = {
  143.                 {"Created by", ScriptAuthor},  
  144.                 {"Version", ScriptVersion}
  145.             }
  146.         },
  147.         {
  148.             Name = "Engine states",
  149.             Display = true,
  150.             Items = { -- This category is special, uses Engines table for Items.
  151.             }
  152.         },
  153.         {
  154.             Name = "Character stats",
  155.             Display = true,
  156.             Items = {
  157.                 {"Experience", num($exp)..' exp'},
  158.                 {"Experience/hour", num($exphour)},
  159.                 {"Experience left", num(exptolevel())..' exp'},
  160.                 {"Experience gained", num($expgained)..' exp'},
  161.                 {"Time online", time(math.floor($timems / 1000))},
  162.                 {"Time to level", time(timetolevel())},
  163.                 {"Ping", $ping .. ' (avg: ' .. $pingaverage .. ')'},           
  164.             }
  165.         },
  166.         {
  167.             Name = "Botting stats",
  168.             Display = true,
  169.             Items = {
  170.                 {"Level", $level .. ' (' .. 100 - math.floor(($exp - expatlvl($level)) * 100 / (expatlvl($level + 1) - expatlvl($level))) .. '%)'},
  171.                 {firstToUpper(TypeSkill.type)..' level', TypeSkill.skill .. ' (' .. 100 - TypeSkill.skillpc .. '%)'},
  172.                 {"Balance", num($balance)},
  173.                 {"Stamina", time($stamina)},
  174.                 {"Softboots duration", 0},
  175.                 {"Vip (Online)", viptext()}
  176.             }
  177.         },
  178.         {
  179.             Name = "Development toolkit",
  180.             Display = Development,
  181.             Items = {
  182.                 {"Position", $posx..'/'..$posy..'/'..$posz},
  183.                 {"Mouseover item", $cursorinfo.id},
  184.                 {"Mouse position", $cursorinfo.x..'/'..$cursorinfo.y..'/'..$cursorinfo.z}
  185.             }
  186.         }
  187.     }
  188. --[[ Functions ]]--
  189. function y(v)
  190.     return v + (FieldConfig.Height + 5)
  191. end
  192. -- Weapon skills
  193. function WeaponSkill()
  194.     local SkillTypes = {
  195.         ['axe'] = {type = 'axe', skill = $axe, skillpc = $axepc},
  196.         ['club'] = {type = 'club', skill = $club, skillpc = $clubpc},
  197.         ['sword'] = {type = 'sword', skill = $sword, skillpc = $swordpc},
  198.         ['bow'] = {type = 'distance', skill = $distance, skillpc = $distancepc},
  199.         ['distance weapon'] = {type = 'distance', skill = $distance, skillpc = $distancepc},
  200.         ['no weapon'] = {type = 'fist', skill = $fist, skillpc = $fistpc},
  201.         ['rod'] = {type = 'magic', skill = $mlevel, skillpc = $mlevelpc},
  202.         ['wand'] = {type = 'magic', skill = $mlevel, skillpc = $mlevelpc},
  203.     }
  204.  
  205.     return SkillTypes[findweapontype()]
  206. end
  207. -- Creates a header
  208. function DrawHeader(posx, posy)
  209.     addgradcolors(table.unpack(Colors.Transparent))
  210.     setbordercolor(color(0, 0, 0, 10))
  211.     drawrect(posx, posy, FieldConfig.Width+2, FieldConfig.Height+2)
  212.  
  213.     addgradcolors(table.unpack(Colors.HeaderColor))
  214.     setbordercolor(Colors.HeaderInnerBorder)
  215.     drawrect(posx+1, posy+1, FieldConfig.Width, FieldConfig.Height)
  216. end
  217. -- Creates a field
  218.  
  219. function DrawField(posx, posy)
  220.     posx = posx
  221.     addgradcolors(table.unpack(Colors.Transparent))
  222.     setbordercolor(color(0, 0, 0, 10))
  223.     drawrect(posx, posy, (FieldConfig.Width-FieldConfig.ValueWidth)-1, FieldConfig.Height+2)
  224.  
  225.     addgradcolors(table.unpack(Colors.FieldColor))
  226.     setbordercolor(Colors.FieldInnerBorder)
  227.     drawrect(posx+1, posy+1, FieldConfig.Width-FieldConfig.ValueWidth-3, FieldConfig.Height)
  228. end
  229. -- Creates a value
  230. function DrawValue(posx, posy, valueType)
  231.     if(valueType == "positive") then
  232.         Border      = Colors.PositiveInnerBorder
  233.         Background  = Colors.ValuePositive
  234.     elseif(valueType == "negative") then
  235.         Border      = Colors.NegativeInnerBorder
  236.         Background  = Colors.ValueNegative
  237.     else
  238.         Border      = Colors.NeutralInnerBorder
  239.         Background  = Colors.ValueNeutral
  240.     end
  241.     addgradcolors(table.unpack(Colors.Transparent)) -- This will not show, anyways.
  242.     setbordercolor(color(0, 0, 0, 10))
  243.     drawrect(FieldConfig.Width-FieldConfig.ValueWidth+posx, posy, FieldConfig.ValueWidth+2, FieldConfig.Height+2)
  244.  
  245.     addgradcolors(table.unpack(Background))
  246.     setbordercolor(Border)
  247.     return drawrect((FieldConfig.Width-FieldConfig.ValueWidth)+1+posx, posy+1, FieldConfig.ValueWidth, FieldConfig.Height)
  248. end
  249. -- Draws special buttons - used for toggle all & show/hide
  250. function DrawButton(posx, posy, valueType, Width)
  251.     local Width = Width or FieldConfig.ValueWidth
  252.     if(valueType == "positive") then
  253.         Border      = Colors.PositiveInnerBorder
  254.         Background  = Colors.ValuePositive
  255.     elseif(valueType == "negative") then
  256.         Border      = Colors.NegativeInnerBorder
  257.         Background  = Colors.ValueNegative
  258.     else
  259.         Border      = Colors.NeutralInnerBorder
  260.         Background  = Colors.ValueNeutral
  261.     end
  262.     addgradcolors(table.unpack(Colors.Transparent)) -- This will not show, anyways.
  263.     setbordercolor(color(0, 0, 0, 10))
  264.     drawrect(FieldConfig.Width-FieldConfig.ValueWidth+posx, posy, Width, FieldConfig.Height+2)
  265.  
  266.     addgradcolors(table.unpack(Background))
  267.     setbordercolor(Border)
  268.     return drawrect((FieldConfig.Width-FieldConfig.ValueWidth)+1+posx, posy+1, Width, FieldConfig.Height)
  269. end
  270. -- Draws text
  271. function DrawText(text, x, y, fieldtype)
  272.     -- Field type is shorthand functionality to place it over the VALUE elements.
  273.     if(fieldtype == "value") then
  274.         x = ((FieldConfig.Width-FieldConfig.ValueWidth)+x)
  275.     end
  276.     addtext(text, x+6, y+6)
  277. end
  278. -- Hud definitions
  279. setposition($clientwin.left + 5, $worldwin.top+2)
  280. setfontstyle('Tahoma', 8, 75, 0xcfebfd, 1, 0x000000)
  281. setfillstyle('gradient', 'linear', 2, 0, 0, 0, 21)
  282. setantialiasing(true)
  283. --
  284. local yPos = 0
  285. local isEnabled = nil
  286.  
  287. -- Loop fields/values
  288. for _, s in ipairs(Sections) do
  289.     if(s.Display) then
  290.     DrawHeader(0, yPos)
  291.     DrawText(s.Name, 0, yPos)
  292.     if(s.Name == 'Engine states') then
  293.         -- Toggle all
  294.         local ToggleallState = tern(AllOn, "negative", "positive")
  295.         local ToggleallText  = tern(AllOn, "TOGGLE ALL OFF", "TOGGLE ALL ON")
  296.         Toggleall = DrawButton(0, yPos, ToggleallState)
  297.         DrawText(ToggleallText, 0+10, yPos, "value")
  298.         --yPos = y(yPos)
  299.         for i, engine in ipairs(Engines) do
  300.             yPos = y(yPos)
  301.             local F, V = engine.Name
  302.             isEnabled = get(F:gsub(' ', '') .. '/Enabled') == 'yes'
  303.             fieldColor = tern(isEnabled, "positive", "negative")
  304.             Value = tern(isEnabled, "ON", "OFF")
  305.             xOffset = tern(isEnabled, (FieldConfig.ValueWidth/2)-12, (FieldConfig.ValueWidth/2)-14)
  306.  
  307.             DrawField(0, yPos)
  308.             Engines[i].Element = DrawValue(0, yPos, fieldColor)
  309.  
  310.             DrawText(F, 0 ,yPos)
  311.             DrawText(Value, 0+xOffset, yPos, "value")
  312.         end
  313.  
  314.     else
  315.         for k, v in ipairs(s.Items) do
  316.             local Field, Value = v[1], v[2]
  317.             local fieldColor = nil
  318.             local xOffset = 0
  319.             yPos = y(yPos) -- Increment yPos
  320.             if(Field == "Stamina") then
  321.                 if($stamina > 40*60) then
  322.                     fieldColor = "positive"
  323.                 end
  324.                 DrawValue(0, yPos, fieldColor)
  325.             else
  326.                 DrawValue(0, yPos)
  327.             end
  328.            
  329.             DrawField(0, yPos)
  330.             DrawText(Field, 0 ,yPos)
  331.             DrawText(Value, 0+xOffset, yPos, "value")
  332.         end
  333.     end
  334.     yPos = y(yPos)
  335.     end
  336.  
  337. end
  338. -- Footer should NEVER be edited or changed. It's theft if you do so without permission!
  339. DrawHeader(0, yPos)
  340. DrawText("Hultin's HUD", 0, yPos)
  341. DrawText("v2.0.0", FieldConfig.Width-45, yPos)
  342. -- Thank you for using Hultin's Hud V2.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement