Advertisement
Guest User

VisualLua.lua

a guest
Nov 14th, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.57 KB | None | 0 0
  1. vl = {
  2.   current_hudtxt2_id = 21,
  3.   buttonstyles = {
  4.     [1] = {
  5.       name = "Windows 7",
  6.       patch = "gfx/_AlcatrazZ/Lua/Visual Lua/button_windows7.png",
  7.       xsize = 160,
  8.       ysize = 21,
  9.       txtcolor = "080080080",
  10.       patch_hover = "gfx/_AlcatrazZ/Lua/Visual Lua/buttonhover_windows7.png",
  11.       patch_click = "gfx/_AlcatrazZ/Lua/Visual Lua/buttonclick_windows7.png"
  12.     },
  13.     [2] = {
  14.       name = "Windows 8",
  15.       patch = "gfx/_AlcatrazZ/Lua/Visual Lua/button_windows8.png",
  16.       xsize = 160,
  17.       ysize = 21,
  18.       txtcolor = "080080080",
  19.       patch_hover = "gfx/_AlcatrazZ/Lua/Visual Lua/buttonhover_windows8.png",
  20.       patch_click = "gfx/_AlcatrazZ/Lua/Visual Lua/buttonclick_windows8.png"
  21.     },
  22.     [3] = {
  23.       name = "Windows 8 close",
  24.       patch = "gfx/_AlcatrazZ/Lua/Visual Lua/close_windows8.png",
  25.       xsize = 32,
  26.       ysize = 20,
  27.       txtcolor = "080080080",
  28.       patch_hover = "gfx/_AlcatrazZ/Lua/Visual Lua/closehover_windows8.png",
  29.       patch_click = "gfx/_AlcatrazZ/Lua/Visual Lua/closeclick_windows8.png"
  30.     },
  31.     [4] = {
  32.       name = "Minecraf Craft",
  33.       patch = "gfx/_AlcatrazZ/Lua/Minecraft/craftbutton_minecraft.png",
  34.       xsize = 80,
  35.       ysize = 32,
  36.       txtcolor = "080080080",
  37.       patch_hover = "gfx/_AlcatrazZ/Lua/Minecraft/craftbuttonhover_minecraft.png",
  38.       patch_click = "gfx/_AlcatrazZ/Lua/Minecraft/craftbuttonclick_minecraft.png"
  39.     }
  40.   },
  41.   windowstyles = {
  42.     [1] = {
  43.       name = "Windows 7",
  44.       patch = "gfx/_AlcatrazZ/Lua/Visual Lua/window_windows7.png",
  45.       xsize = 207,
  46.       ysize = 317,
  47.       txtcolor = "080080080",
  48.       ox = -90,
  49.       oy = -150
  50.     },
  51.     [2] = {
  52.       name = "Windows 8",
  53.       patch = "gfx/_AlcatrazZ/Lua/Visual Lua/window_windows8.png",
  54.       xsize = 207,
  55.       ysize = 317,
  56.       txtcolor = "070140170",
  57.       ox = -90,
  58.       oy = -150
  59.     },
  60.     [3] = {
  61.       name = "Minecraft Inventory",
  62.       patch = "gfx/_AlcatrazZ/Lua/Minecraft/window_inventory.png",
  63.       xsize = 352,
  64.       ysize = 332,
  65.       txtcolor = "080080080",
  66.       ox = -90,
  67.       oy = -150
  68.     }
  69.   },
  70.   slotstyles = {
  71.     [1] = {
  72.       name = "Minecraft slot",
  73.       patch = "gfx/_AlcatrazZ/Lua/Minecraft/slot_minecraft.png",
  74.       xsize = 36,
  75.       ysize = 36,
  76.       txtcolor = "255255255",
  77.       patch_hover = "gfx/_AlcatrazZ/Lua/Minecraft/slothover_minecraft.png",
  78.       patch_select = "gfx/_AlcatrazZ/Lua/Minecraft/slotselect_minecraft.png",
  79.       ox = 0,
  80.       oy = 8
  81.     }
  82.   },
  83.   items = {
  84.     [1] = {
  85.       name = "Dirt",
  86.       patch = "gfx/_AlcatrazZ/Lua/Minecraft/items/1.png",
  87.       stack = 64
  88.     },
  89.     [2] = {
  90.       name = "Stone",
  91.       patch = "gfx/_AlcatrazZ/Lua/Minecraft/items/2.png",
  92.       stack = 64
  93.     }
  94.   },
  95.   crafts = {
  96.     [1] = {
  97.       2,
  98.       2,
  99.       false,
  100.       2
  101.     },
  102.     [2] = {
  103.       1,
  104.       1,
  105.       1,
  106.       1
  107.     }
  108.   }
  109. }
  110. vl.hook = {}
  111. vl.user = {}
  112. function vl.hook.join(id)
  113.   if player(id, "bot") then
  114.     return
  115.   end
  116.   vl.user[id] = {
  117.     buttons = {},
  118.     windows = {},
  119.     slots = {},
  120.     hudtxt2ids = {}
  121.   }
  122. end
  123. function vl.hook.leave(id)
  124.   if player(id, "bot") then
  125.     return
  126.   end
  127.   vl.user[id] = nil
  128. end
  129. function vl.hook.startround()
  130.   for _, id in pairs(player(0, "table")) do
  131.     if player(id, "bot") then
  132.       return
  133.     end
  134.   end
  135. end
  136. function vl.hook.clientdata(id, mode, x, y)
  137.   if player(id, "bot") then
  138.     return
  139.   end
  140.   if mode == 0 and vl.user[id] then
  141.     vl.user[id].screenx = x
  142.     vl.user[id].screeny = y
  143.   end
  144. end
  145. function vl.hook.ms100()
  146.   for _, id in pairs(player(0, "table")) do
  147.     if player(id, "bot") then
  148.       return
  149.     end
  150.     if vl.user[id] then
  151.       vl.ButtonHover(id)
  152.       vl.SlotHover(id)
  153.     end
  154.   end
  155. end
  156. function vl.hook.attack(id)
  157.   if player(id, "bot") then
  158.     return
  159.   end
  160.   vl.ButtonClick(id)
  161.   vl.SlotClick(id)
  162. end
  163. function vl.CreateButton(id, buttonid, x, y, style, func)
  164.   if not vl.user[id].buttons[buttonid] then
  165.     vl.user[id].buttons[buttonid] = {
  166.       imageid = image(vl.buttonstyles[style].patch, x, y, 2, id),
  167.       style = style,
  168.       func = func,
  169.       x = x,
  170.       y = y,
  171.       textids = {}
  172.     }
  173.   else
  174.     vl.Error("button " .. buttonid .. " of player " .. id .. " already exists")
  175.   end
  176. end
  177. function vl.RemoveButton(id, buttonid)
  178.   if vl.user[id].buttons[buttonid] then
  179.     vl.user[id].buttoninrange = nil
  180.     vl.RemoveText(id, "button", buttonid)
  181.     freeimage(vl.user[id].buttons[buttonid].imageid)
  182.     vl.user[id].buttons[buttonid] = nil
  183.     if vl.user[id].buttonhover then
  184.       freeimage(vl.user[id].buttonhover)
  185.       vl.user[id].buttonhover = nil
  186.     end
  187.   end
  188. end
  189. function vl.ButtonHover(id)
  190.   if vl.user[id] then
  191.     if vl.user[id].screenx == nil then
  192.       vl.user[id].screenx = 0
  193.     end
  194.     if vl.user[id].screeny == nil then
  195.       vl.user[id].screeny = 0
  196.     end
  197.     for _, i in pairs(vl.user[id].buttons) do
  198.       local xsize = vl.buttonstyles[vl.user[id].buttons[_].style].xsize
  199.       local ysize = vl.buttonstyles[vl.user[id].buttons[_].style].ysize
  200.       if not vl.user[id].buttoninrange then
  201.         if vl.user[id].screenx >= i.x - xsize / 2 and vl.user[id].screeny >= i.y - ysize / 2 and vl.user[id].screenx <= i.x + xsize / 2 and vl.user[id].screeny <= i.y + ysize / 2 then
  202.           if vl.buttonstyles[vl.user[id].buttons[_].style].patch_hover then
  203.             vl.user[id].buttonhover = image(vl.buttonstyles[vl.user[id].buttons[_].style].patch_hover, i.x, i.y, 2, id)
  204.           end
  205.           vl.user[id].buttoninrange = _
  206.         end
  207.       elseif (vl.user[id].screenx <= i.x - xsize / 2 or vl.user[id].screeny <= i.y - ysize / 2 or vl.user[id].screenx >= i.x + xsize / 2 or vl.user[id].screeny >= i.y + ysize / 2) and vl.user[id].buttoninrange == _ then
  208.         if vl.buttonstyles[vl.user[id].buttons[_].style].patch_hover then
  209.           freeimage(vl.user[id].buttonhover)
  210.           vl.user[id].buttonhover = nil
  211.         end
  212.         vl.user[id].buttoninrange = nil
  213.       end
  214.     end
  215.     reqcld(id, 0)
  216.   end
  217. end
  218. function vl.ButtonClick(id)
  219.   if vl.user[id].buttoninrange and not vl.user[id].buttonclicked then
  220.     if vl.buttonstyles[vl.user[id].buttons[vl.user[id].buttoninrange].style].patch_click then
  221.       vl.user[id].buttonclick = image(vl.buttonstyles[vl.user[id].buttons[vl.user[id].buttoninrange].style].patch_click, vl.user[id].buttons[vl.user[id].buttoninrange].x, vl.user[id].buttons[vl.user[id].buttoninrange].y, 2, id)
  222.     end
  223.     vl.user[id].buttonclicked = true
  224.     timer(100, "parse", "lua vl.ButtonUnclick(" .. id .. "," .. vl.user[id].buttoninrange .. ")")
  225.   end
  226. end
  227. function vl.ButtonUnclick(id, buttonid)
  228.   vl.user[id].buttonclicked = false
  229.   if vl.user[id].buttonclick then
  230.     freeimage(vl.user[id].buttonclick)
  231.     vl.user[id].buttonclick = nil
  232.   end
  233.   if vl.user[id].buttons[buttonid] and vl.user[id].buttons[buttonid].func then
  234.     vl.user[id].buttons[buttonid].func(id, vl.user[id].slotselected)
  235.   end
  236. end
  237. function vl.CreateWindow(id, windowid, x, y, style, headline)
  238.   if not vl.user[id].windows[windowid] then
  239.     vl.user[id].windows[windowid] = {
  240.       imageid = image(vl.windowstyles[style].patch, x, y, 2, id),
  241.       style = style,
  242.       x = x,
  243.       y = y,
  244.       textids = {}
  245.     }
  246.     if headline ~= nil and headline ~= "" then
  247.       vl.CreateText(id, "window", windowid, style, x + vl.windowstyles[style].ox, y + vl.windowstyles[style].oy, headline, 0, nil, true)
  248.     end
  249.   end
  250. end
  251. function vl.RemoveWindow(id, windowid)
  252.   if vl.user[id].windows[windowid] then
  253.     vl.RemoveText(id, "window", windowid)
  254.     freeimage(vl.user[id].windows[windowid].imageid)
  255.     vl.user[id].windows[windowid] = nil
  256.   end
  257. end
  258. function vl.CreateSlot(id, invid, slotid, x, y, style, showamount, morethanone, hoveroveritem)
  259.   showamount = showamount or false
  260.   if not vl.user[id].slots[invid] then
  261.     vl.user[id].slots[invid] = {}
  262.   end
  263.   if not vl.user[id].slots[invid][slotid] then
  264.     vl.user[id].slots[invid][slotid] = {
  265.       imageid = image(vl.slotstyles[style].patch, x, y, 2, id),
  266.       itemid = nil,
  267.       visible = true,
  268.       style = style,
  269.       x = x,
  270.       y = y,
  271.       item = false,
  272.       amount = 0,
  273.       showamount = showamount,
  274.       morethanone = morethanone,
  275.       hoveroveritem = hoveroveritem,
  276.       textids = {}
  277.     }
  278.   end
  279. end
  280. function vl.ShowSlot(id, invid, slotid)
  281.   if vl.user[id].slots[invid][slotid] and not vl.user[id].slots[invid][slotid].visible then
  282.     vl.user[id].slots[invid][slotid].imageid = image(vl.slotstyles[vl.user[id].slots[invid][slotid].style].patch, vl.user[id].slots[invid][slotid].x, vl.user[id].slots[invid][slotid].y, 2, id)
  283.     vl.user[id].slots[invid][slotid].visible = true
  284.     if vl.user[id].slots[invid][slotid].item then
  285.       vl.user[id].slots[invid][slotid].itemid = image(vl.items[vl.user[id].slots[invid][slotid].item].patch, vl.user[id].slots[invid][slotid].x, vl.user[id].slots[invid][slotid].y, 2, id)
  286.       if vl.user[id].slots[invid][slotid].showamount then
  287.         if vl.user[id].slots[invid][slotid].morethanone then
  288.           if vl.user[id].slots[invid][slotid].amount > 1 then
  289.             vl.CreateText(id, "slot", slotid, vl.user[id].slots[invid][slotid].style, vl.user[id].slots[invid][slotid].x + vl.slotstyles[vl.user[id].slots[invid][slotid].style].ox, vl.user[id].slots[invid][slotid].y + vl.slotstyles[vl.user[id].slots[invid][slotid].style].oy, vl.user[id].slots[invid][slotid].amount, 1, invid)
  290.           end
  291.         else
  292.           vl.CreateText(id, "slot", slotid, vl.user[id].slots[invid][slotid].style, vl.user[id].slots[invid][slotid].x + vl.slotstyles[vl.user[id].slots[invid][slotid].style].ox, vl.user[id].slots[invid][slotid].y + vl.slotstyles[vl.user[id].slots[invid][slotid].style].oy, vl.user[id].slots[invid][slotid].amount, 1, invid)
  293.         end
  294.       end
  295.     end
  296.   end
  297. end
  298. function vl.HideSlot(id, invid, slotid)
  299.   if vl.user[id].slots[invid][slotid] and vl.user[id].slots[invid][slotid].visible then
  300.     vl.RemoveText(id, "slot", slotid, invid)
  301.     vl.user[id].slotinrange = nil
  302.     vl.user[id].invinrange = nil
  303.     vl.RemoveText(id, "slot", slotid, invid)
  304.     freeimage(vl.user[id].slots[invid][slotid].imageid)
  305.     vl.user[id].slots[invid][slotid].imageid = nil
  306.     if vl.user[id].slots[invid][slotid].itemid then
  307.       freeimage(vl.user[id].slots[invid][slotid].itemid)
  308.       vl.user[id].slots[invid][slotid].itemid = nil
  309.     end
  310.     vl.user[id].slots[invid][slotid].visible = false
  311.     if vl.user[id].slothover then
  312.       freeimage(vl.user[id].slothover)
  313.       vl.user[id].slothover = nil
  314.     end
  315.     if vl.user[id].selectedid then
  316.       freeimage(vl.user[id].selectedid)
  317.       vl.user[id].selectedinv = false
  318.       vl.user[id].selectedslot = false
  319.     end
  320.   end
  321. end
  322. function vl.RemoveSlot(id, invid, slotid)
  323.   if vl.user[id].slots[invid][slotid] then
  324.     vl.user[id].slotinrange = nil
  325.     vl.user[id].invinrange = nil
  326.     vl.RemoveText(id, "slot", slotid, invid)
  327.     freeimage(vl.user[id].slots[invid][slotid].imageid)
  328.     if vl.user[id].slots[invid][slotid].itemid then
  329.       freeimage(vl.user[id].slots[invid][slotid].itemid)
  330.       vl.user[id].slots[invid][slotid].itemid = nil
  331.     end
  332.     vl.user[id].slots[invid][slotid] = nil
  333.     if vl.user[id].slothover then
  334.       freeimage(vl.user[id].slothover)
  335.       vl.user[id].slothover = nil
  336.     end
  337.     if vl.user[id].selectedid then
  338.       freeimage(vl.user[id].selectedid)
  339.       vl.user[id].selectedinv = false
  340.       vl.user[id].selectedslot = false
  341.     end
  342.   end
  343. end
  344. function vl.SlotHover(id)
  345.   if vl.user[id] then
  346.     if vl.user[id].screenx == nil then
  347.       vl.user[id].screenx = 0
  348.     end
  349.     if vl.user[id].screeny == nil then
  350.       vl.user[id].screeny = 0
  351.     end
  352.     for k, v in pairs(vl.user[id].slots) do
  353.       for _, i in pairs(vl.user[id].slots[k]) do
  354.         if vl.user[id].slots[k][_].visible and vl.slotstyles[vl.user[id].slots[k][_].style].patch_hover then
  355.           local xsize = vl.slotstyles[vl.user[id].slots[k][_].style].xsize
  356.           local ysize = vl.slotstyles[vl.user[id].slots[k][_].style].ysize
  357.           if not vl.user[id].slothover then
  358.             if vl.user[id].screenx >= i.x - xsize / 2 and vl.user[id].screeny >= i.y - ysize / 2 and vl.user[id].screenx <= i.x + xsize / 2 and vl.user[id].screeny <= i.y + ysize / 2 then
  359.               if not vl.user[id].slots[k][_].hoveroveritem then
  360.                 if vl.user[id].slots[k][_].itemid then
  361.                   freeimage(vl.user[id].slots[k][_].itemid)
  362.                   vl.user[id].slothover = image(vl.slotstyles[vl.user[id].slots[k][_].style].patch_hover, i.x, i.y, 2, id)
  363.                   vl.user[id].slots[k][_].itemid = image(vl.items[vl.user[id].slots[k][_].item].patch, vl.user[id].slots[k][_].x, vl.user[id].slots[k][_].y, 2, id)
  364.                   imagescale(vl.user[id].slots[k][_].itemid, 0.8, 0.8)
  365.                 else
  366.                   vl.user[id].slothover = image(vl.slotstyles[vl.user[id].slots[k][_].style].patch_hover, i.x, i.y, 2, id)
  367.                 end
  368.               else
  369.                 vl.user[id].slothover = image(vl.slotstyles[vl.user[id].slots[k][_].style].patch_hover, i.x, i.y, 2, id)
  370.               end
  371.               vl.user[id].slotinrange = _
  372.               vl.user[id].invinrange = k
  373.             end
  374.           elseif (vl.user[id].screenx <= i.x - xsize / 2 or vl.user[id].screeny <= i.y - ysize / 2 or vl.user[id].screenx >= i.x + xsize / 2 or vl.user[id].screeny >= i.y + ysize / 2) and vl.user[id].slotinrange == _ and vl.user[id].invinrange == k then
  375.             freeimage(vl.user[id].slothover)
  376.             vl.user[id].slothover = nil
  377.             vl.user[id].slotinrange = nil
  378.             vl.user[id].invinrange = nil
  379.           end
  380.         end
  381.       end
  382.     end
  383.     reqcld(id, 0)
  384.   end
  385. end
  386. function vl.SlotClick(id)
  387.   if vl.user[id].invinrange and vl.user[id].slotinrange and not vl.user[id].slotclicked then
  388.     if vl.slotstyles[vl.user[id].slots[vl.user[id].invinrange][vl.user[id].slotinrange].style].patch_click then
  389.       vl.user[id].slotclick = image(vl.slotstyles[vl.user[id].slots[vl.user[id].invinrange][vl.user[id].slotinrange].style].patch_click, vl.user[id].slots[vl.user[id].invinrange][vl.user[id].slotinrange].x, vl.user[id].slots[vl.user[id].invinrange][vl.user[id].slotinrange].y, 2, id)
  390.     end
  391.     vl.user[id].slotclicked = true
  392.     timer(100, "parse", "lua vl.SlotUnclick(" .. id .. "," .. vl.user[id].invinrange .. "," .. vl.user[id].slotinrange .. ")")
  393.   end
  394. end
  395. function vl.SlotUnclick(id, invid, slotid)
  396.   vl.user[id].slotclicked = false
  397.   if vl.user[id].slotclick then
  398.     freeimage(vl.user[id].slotclick)
  399.     vl.user[id].slotclick = nil
  400.   end
  401.   vl.SlotSelect(id, invid, slotid)
  402. end
  403. function vl.SlotSelect(id, invid, slotid)
  404.   if vl.user[id].selectedinv and vl.user[id].selectedslot then
  405.     freeimage(vl.user[id].selectedid)
  406.     vl.user[id].selectedid = nil
  407.     if invid ~= vl.user[id].selectedinv or slotid ~= vl.user[id].selectedslot then
  408.       local x = vl.AddItem(id, invid, slotid, vl.user[id].slots[vl.user[id].selectedinv][vl.user[id].selectedslot].item, vl.user[id].slots[vl.user[id].selectedinv][vl.user[id].selectedslot].amount)
  409.       if x == "remove" then
  410.         vl.RemoveItem(id, vl.user[id].selectedinv, vl.user[id].selectedslot, vl.user[id].slots[vl.user[id].selectedinv][vl.user[id].selectedslot].item)
  411.       elseif type(x) == "number" then
  412.         vl.RemoveItem(id, vl.user[id].selectedinv, vl.user[id].selectedslot, vl.user[id].slots[vl.user[id].selectedinv][vl.user[id].selectedslot].item, x)
  413.       end
  414.     end
  415.     vl.user[id].selectedinv = false
  416.     vl.user[id].selectedslot = false
  417.   else
  418.     vl.user[id].selectedinv = invid
  419.     vl.user[id].selectedslot = slotid
  420.     vl.user[id].selectedid = image(vl.slotstyles[vl.user[id].slots[invid][slotid].style].patch_select, vl.user[id].slots[invid][slotid].x, vl.user[id].slots[invid][slotid].y, 2, id)
  421.   end
  422. end
  423. function vl.AddItem(id, invid, slotid, item, amount)
  424.   local amount = amount or 1
  425.   if vl.user[id].slots[invid] then
  426.     if vl.user[id].slots[invid][slotid] then
  427.       if vl.user[id].slots[invid][slotid].item then
  428.         if vl.user[id].slots[invid][slotid].item == item then
  429.           if vl.items[item].stack >= vl.user[id].slots[invid][slotid].amount + amount then
  430.             vl.user[id].slots[invid][slotid].amount = vl.user[id].slots[invid][slotid].amount + amount
  431.             if vl.user[id].slots[invid][slotid].visible then
  432.               vl.HideSlot(id, invid, slotid)
  433.               vl.ShowSlot(id, invid, slotid)
  434.             end
  435.             return "remove"
  436.           else
  437.             local x = vl.user[id].slots[invid][slotid].amount
  438.             if amount < x and x < vl.items[item].stack then
  439.               vl.user[id].slots[invid][slotid].amount = vl.items[item].stack
  440.               if vl.user[id].slots[invid][slotid].visible then
  441.                 vl.HideSlot(id, invid, slotid)
  442.                 vl.ShowSlot(id, invid, slotid)
  443.               end
  444.               return vl.items[item].stack - x
  445.             end
  446.           end
  447.         end
  448.       elseif item and amount <= vl.items[item].stack then
  449.         vl.user[id].slots[invid][slotid].item = item
  450.         vl.user[id].slots[invid][slotid].amount = amount
  451.         if vl.user[id].slots[invid][slotid].visible then
  452.           vl.HideSlot(id, invid, slotid)
  453.           vl.ShowSlot(id, invid, slotid)
  454.         end
  455.         return "remove"
  456.       end
  457.     else
  458.       local emptySlot = vl.getEmpty(id, invid, slotid, item, amount)
  459.       if emptySlot then
  460.         if vl.user[id].slots[invid][emptySlot].item then
  461.           vl.user[id].slots[invid][emptySlot].amount = vl.user[id].slots[invid][emptySlot].amount + amount
  462.           if vl.user[id].slots[invid][emptySlot].visible then
  463.             vl.HideSlot(id, invid, emptySlot)
  464.             vl.ShowSlot(id, invid, emptySlot)
  465.           end
  466.           return "remove"
  467.         elseif amount <= vl.items[item].stack then
  468.           vl.user[id].slots[invid][emptySlot].item = item
  469.           vl.user[id].slots[invid][emptySlot].amount = amount
  470.           if vl.user[id].slots[invid][emptySlot].visible then
  471.             vl.HideSlot(id, invid, emptySlot)
  472.             vl.ShowSlot(id, invid, emptySlot)
  473.           end
  474.           return "remove"
  475.         end
  476.       end
  477.     end
  478.   end
  479.   return false
  480. end
  481. function vl.RemoveItem(id, invid, slotid, item, amount)
  482.   if vl.user[id].slots[invid] and vl.user[id].slots[invid][slotid] then
  483.     local amount = amount or vl.user[id].slots[invid][slotid].amount
  484.     if vl.user[id].slots[invid][slotid].item and vl.user[id].slots[invid][slotid].item == item then
  485.       if amount < vl.user[id].slots[invid][slotid].amount then
  486.         vl.user[id].slots[invid][slotid].amount = vl.user[id].slots[invid][slotid].amount - amount
  487.         if vl.user[id].slots[invid][slotid].visible then
  488.           vl.HideSlot(id, invid, slotid)
  489.           vl.ShowSlot(id, invid, slotid)
  490.         end
  491.       elseif vl.user[id].slots[invid][slotid].amount == amount then
  492.         vl.user[id].slots[invid][slotid].amount = 0
  493.         vl.user[id].slots[invid][slotid].item = false
  494.         freeimage(vl.user[id].slots[invid][slotid].itemid)
  495.         vl.user[id].slots[invid][slotid].itemid = nil
  496.         if vl.user[id].slots[invid][slotid].visible then
  497.           vl.HideSlot(id, invid, slotid)
  498.           vl.ShowSlot(id, invid, slotid)
  499.         end
  500.       end
  501.     end
  502.   end
  503. end
  504. function vl.getItemPatch(itemid)
  505.   if vl.items[itemid] then
  506.     return vl.items[itemid].patch
  507.   end
  508.   return false
  509. end
  510. function vl.getEmpty(id, invid, slotid, item, amount)
  511.   if not slotid then
  512.     for _, i in pairs(vl.user[id].slots[invid]) do
  513.       if i.item then
  514.         if i.item == item and vl.items[i.item].stack >= i.amount + amount then
  515.           return _
  516.         end
  517.       else
  518.         return _
  519.       end
  520.     end
  521.   elseif vl.user[id].slots[invid][slotid].item then
  522.     if vl.user[id].slots[invid][slotid].item == item and vl.items[vl.user[id].slots[invid][slotid].item].stack >= vl.user[id].slots[invid][slotid].amount + amount then
  523.       return slotid
  524.     end
  525.   else
  526.     return slotid
  527.   end
  528.   return false
  529. end
  530. function vl.CreateText(id, b, typeid, style, x, y, txt, align, invid, header)
  531.   local a, a2
  532.   if b == "button" then
  533.     a = vl.user[id].buttons[typeid].textids
  534.     a2 = vl.buttonstyles[style]
  535.   elseif b == "window" then
  536.     a = vl.user[id].windows[typeid].textids
  537.     a2 = vl.windowstyles[style]
  538.   elseif b == "slot" then
  539.     a = vl.user[id].slots[invid][typeid].textids
  540.     a2 = vl.slotstyles[style]
  541.   end
  542.   local tid = vl.getTextID(id)
  543.   if b == "button" then
  544.     parse("hudtxt2 " .. id .. " " .. tid .. " \"" .. "\169" .. a2.txtcolor .. txt .. "\" " .. x .. " " .. y - 8 .. " " .. align)
  545.   elseif b == "window" then
  546.     if not header or header == 0 then
  547.       parse("hudtxt2 " .. id .. " " .. tid .. " \"" .. "\169" .. a2.txtcolor .. txt .. "\" " .. x .. " " .. y - 8 .. " " .. align)
  548.     else
  549.       parse("hudtxt2 " .. id .. " " .. tid .. " \"" .. "\169" .. a2.txtcolor .. txt .. "\" " .. x .. " " .. y .. " " .. align)
  550.     end
  551.   elseif b == "slot" then
  552.     parse("hudtxt2 " .. id .. " " .. tid .. " \"" .. "\169" .. a2.txtcolor .. txt .. "\" " .. x .. " " .. y - 8 .. " " .. align)
  553.   end
  554.   table.insert(vl.user[id].hudtxt2ids, tid)
  555.   table.insert(a, tid)
  556. end
  557. function vl.RemoveText(id, b, typeid, invid)
  558.   local a
  559.   if b == "button" then
  560.     a = vl.user[id].buttons[typeid].textids
  561.   elseif b == "window" then
  562.     a = vl.user[id].windows[typeid].textids
  563.   elseif b == "slot" then
  564.     a = vl.user[id].slots[invid][typeid].textids
  565.   end
  566.   if a[1] then
  567.     for _, i in pairs(a) do
  568.       parse("hudtxt2 " .. id .. " " .. i .. " \" \" 0 0 0")
  569.       vl.tableRemove(vl.user[id].hudtxt2ids, i)
  570.       vl.tableRemove(a, i)
  571.     end
  572.   end
  573. end
  574. function vl.tableRemove(tab, value)
  575.   for _, i in pairs(tab) do
  576.     if i == value then
  577.       table.remove(tab, _)
  578.     end
  579.   end
  580. end
  581. function vl.getTextID(id)
  582.   local txtid = vl.current_hudtxt2_id
  583.   while vl.FindTextID(id, txtid) do
  584.     txtid = txtid + 1
  585.   end
  586.   return txtid
  587. end
  588. function vl.FindTextID(id, tid)
  589.   if vl.user[id].hudtxt2ids[1] then
  590.     for _, i in pairs(vl.user[id].hudtxt2ids) do
  591.       if i == tid then
  592.         return true
  593.       end
  594.     end
  595.   end
  596.   return false
  597. end
  598. function vl.RemoveEngine(id)
  599.   for i in pairs(vl.user[id].buttons) do
  600.     vl.RemoveButton(id, i)
  601.   end
  602.   for i in pairs(vl.user[id].windows) do
  603.     vl.RemoveWindow(id, i)
  604.   end
  605.   for i in pairs(vl.user[id].slots) do
  606.     vl.DeleteSlot(id, i)
  607.   end
  608. end
  609. function vl.Error(txt)
  610.   print("\169255000000Visual Lua ERROR: " .. txt)
  611. end
  612. function vl.addhooks()
  613.   for i in pairs(vl.hook) do
  614.     addhook(tostring(i), "vl.hook." .. tostring(i), -3)
  615.   end
  616. end
  617. vl.addhooks()
  618. print("\169000255000Successfully loaded Visual Lua!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement