Advertisement
Guest User

computercraft smartglass

a guest
Jul 5th, 2014
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.04 KB | None | 0 0
  1. echest = "west"
  2. net = peripheral.wrap("back")
  3. ae = "appeng_me_tilecolorlesscable_1"
  4. glass= "openperipheral_glassesbridge_0"
  5. net.callRemote(glass,"clear")
  6. sheight = 250
  7. swidth = 450
  8. AEmonmax = math.floor((swidth-20)/30)
  9. monitems = {}
  10. monicons = {}
  11. montext = {}
  12. formattext = {}
  13. b = ""
  14.  
  15. message = function(message,colour)
  16.    for word in string.gmatch(message) do
  17.       a = string.len(word)
  18.       blen = string.len(b)
  19.       if a + blen < 15 then
  20.          b = b.." "..word
  21.       else
  22.          table.insert(formattext, b)
  23.          b = word
  24.       end
  25.    end
  26. end
  27.      
  28.  
  29. function round(number, sigDigits)
  30.   local decimalPlace = string.find(number, "%.")
  31.   if not decimalPlace or (sigDigits < decimalPlace) then
  32.     numberTable = {}
  33.     count = 1
  34.     for digit in string.gmatch(number, "%d") do
  35.       table.insert(numberTable, digit)
  36.     end
  37.     local endNumber = ""
  38.     for i,digit in ipairs(numberTable) do
  39.       if i < sigDigits then
  40.         endNumber = endNumber .. digit
  41.       end
  42.       if i == sigDigits then
  43.         if tonumber(numberTable[i + 1]) >= 5 then
  44.           endNumber = endNumber .. digit + 1
  45.         else
  46.           endNumber = endNumber .. digit
  47.         end
  48.       end
  49.       if i > sigDigits and (not decimalPlace or (i < decimalPlace)) then
  50.         endNumber = endNumber .. "0"
  51.       end
  52.     end
  53.     return tonumber(endNumber)      
  54.   else
  55.     local decimalDigits = sigDigits - decimalPlace + 1
  56.     return tonumber(string.format("%" .. decimalPlace - 1 .. "." .. decimalDigits .. "f", number))
  57.   end
  58. end
  59.  
  60. addmon = function()
  61.    curitem = {}
  62.    event,itmid = os.pullEvent("chat_command")
  63.    itmid = tonumber(itmid)
  64.    event,itmdmg = os.pullEvent("chat_command")
  65.    itmdmg = tonumber(itmdmg)
  66.    curitem = {id=itmid;dmg=itmdmg;}
  67.    table.insert(monitems,curitem)
  68. end
  69.  
  70.  
  71. AEmon = function()
  72.    if #monitems > 0 then
  73.       AEbox = net.callRemote(glass,"addBox",10,10,#monitems*30,40,0x000000,0.7)
  74.       for i = 1,#monitems do
  75.          if i <= #montext then
  76.             curdeltext = montext[i]
  77.             curdeltext.delete()
  78.          end
  79.          curitem = monitems[i]
  80.          curid = curitem.id
  81.          curdmg = curitem.dmg
  82.          monicons[i] = net.callRemote(glass,"addIcon",(30*i)-13,17,curid,curdmg)
  83.          iteminsys = net.callRemote(ae,"countOfItemType",curid,curdmg)
  84.          if iteminsys > 9999999999 then
  85.             iteminsys = iteminsys/1000000000
  86.             iteminsys = round(iteminsys, 4)
  87.             iteminsys = iteminsys.."B"
  88.          elseif iteminsys > 9999999 then
  89.             iteminsys = iteminsys/1000000
  90.             iteminsys = round(iteminsys, 4)
  91.             iteminsys = iteminsys.."M"
  92.          elseif iteminsys > 9999 then
  93.             iteminsys = iteminsys/1000
  94.             iteminsys = round(iteminsys, 4)
  95.             iteminsys = iteminsys.."K"
  96.          end
  97.          montext[i] = net.callRemote(glass,"addText",(30*i)-20,40,iteminsys)
  98.       end
  99.    end
  100. end
  101.  
  102. removemon = function()
  103.    event, num = os.pullEvent()
  104.    table.remove(monitems, num)
  105.    delicon = monicons[num]
  106.    delicon.delete()
  107.    deltext = montext[num]
  108.    deltext.delete()
  109.    AEbox.delete()
  110.    AEmon()
  111. end
  112.  
  113.  
  114. refresh = function()
  115.    AEmon()
  116. end
  117.  
  118.  
  119. request = function()
  120.    event, itmqty = os.pullEvent("chat_command")
  121.    itmqty = tonumber(itmqty)
  122.    event, itmid = os.pullEvent("chat_command")
  123.    itmid = tonumber(itmid)
  124.    event, itmdmg = os.pullEvent("chat_command")
  125.    itmdmg = tonumber(itmdmg)
  126.    reqitem = {id = itmid;dmg = itmdmg;qty = itmqty;}
  127.    unavailable = itmqty - net.callRemote(ae,"countOfItemType",itmid,itmdmg)
  128.       if unavailable > 0 then
  129.       craft = reqitem
  130.       craft[qty] = unavailable
  131.       net.callRemote(ae,requestCrafting,craft)
  132.    end
  133.    net.callRemote(ae,"extractItem",reqitem,echest)   
  134. end
  135.        
  136.  
  137.  
  138.  
  139. while true do
  140.    os.startTimer(1)
  141.    event,action = os.pullEvent()
  142.    if event == "timer" then
  143.       refresh()
  144.    elseif action == "req" then
  145.       request()
  146.    elseif action == "addmon" then
  147.       addmon()
  148.    elseif action == "removemon" then
  149.       removemon()
  150.    end
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement