Advertisement
1ng0

CC - Auto Spawner Control System

Jul 20th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. --------------
  2. --  1ng0 ©  --
  3. --------------
  4. mon = peripheral.wrap("top")
  5. rednet.open("bottom")
  6. turtleId = 61
  7. buttons = {}
  8.  
  9. function greateButton(mon,text,mob)
  10.   bxmin,bymin = mon.getCursorPos()
  11.   bxmax = bxmin + #text
  12.   bymax = bymin
  13.   buttons[mob.slot] = {["mob"] = mob, ["text"] = text, ["slot"] = mob.slot, ["name"] = mob.name, ["xmin"] = bxmin, ["ymin"] = bymin, ["xmax"] = bxmax, ["ymax"] = bymax}
  14.   mon.setBackgroundColor(colors.blue)
  15.   println (mon, text)
  16.   mon.setBackgroundColor(colors.black)
  17. end
  18.  
  19. function command(cname,args)
  20.   if (args) then
  21.     cmd = {["cname"] = cname, ["args"] = args}
  22.   else
  23.     cmd = {["cname"] = cname}
  24.   end
  25.   rednet.send(turtleId, cmd)
  26.   senderId, message, distance = rednet.receive(5)
  27.   return message
  28. end
  29.  
  30. function println(mon,text)
  31.   cx,cy = mon.getCursorPos()
  32.   mon.write(text)
  33.   mon.setCursorPos(cx,cy+1)
  34. end
  35.  
  36. function essenseStats()
  37.   tankInfo = command("getTankInfo",nil)
  38.   mon.setCursorPos(42,1)
  39.   println(mon,"Stats")
  40.   println(mon,"Essense:")
  41.   if (tankInfo.amount) then
  42.     am = tankInfo.amount
  43.   else
  44.     am = 0
  45.   end
  46.   println(mon,tostring(am))
  47.   if (command("getSpawnExact",nil)) then
  48.     div = 500
  49.   else
  50.     div = 150
  51.   end
  52.   println(mon,"~"..math.floor(am/div).." mobs")
  53.   greateButton(mon,"Exact:",{slot = 100,command = "swapExact"})
  54.   isExact = command("getSpawnExact",nil)
  55.   println(mon,tostring(isExact))
  56. end
  57.  
  58. function init(mon,mobs,currentMob)
  59.   mon.clear()
  60.   mon.setCursorPos(1,1)
  61.   sx,sy = mon.getSize()
  62.   println(mon,"All Available Mobs:")
  63.   numnom = 1
  64.   for i,mob in pairs(mobs) do
  65.     if (i ~= 0) then
  66.       if (numnom == 8) then
  67.         mon.setCursorPos(21,2)
  68.       end
  69.       greateButton(mon,i..": "..mob.name, mob)
  70.       numnom = numnom + 1
  71.     end
  72.   end
  73.   mon.setCursorPos(1,9)
  74.   greateButton(mon,"EMPTY",mobs[0])
  75.   mon.setCursorPos(1,10)
  76.   println(mon,"Currently selected mob:")
  77.   println(mon,currentMob.slot..": "..currentMob.name)
  78.   mon.setBackgroundColor(colors.blue)
  79.   println(mon, "REFRESH")
  80.   mon.setBackgroundColor(colors.black)
  81.   essenseStats()
  82. end
  83.  
  84. function checkButtons(x,y)
  85.   for i,button in pairs(buttons) do
  86.     if (x>=button.xmin and x<=button.xmax and y>=button.ymin and y<=button.ymax) then
  87.       return button.mob
  88.     end
  89.   end
  90.   return false
  91. end
  92.  
  93. while true do
  94.   mobs = command("getAllMobs",nil)
  95.   currentMob = command("getCurrentMob",nil)
  96.   init(mon,mobs,currentMob)
  97.   event,side,posX,posY = os.pullEvent("monitor_touch")
  98.   selectedMob = checkButtons(posX,posY)
  99.   if (selectedMob ~= false) then
  100.     --println(mon,"You clicked on "..selectedMob.name)
  101.     if (selectedMob.command) then
  102.       if (selectedMob.command == "swapExact") then
  103.         currentExact = command("getSpawnExact",nil)
  104.         command("setSpawnExact", {[1] = not(currentExact)})
  105.       end
  106.     else
  107.       command("fromSpawnerToChest",nil)
  108.       command("fromChestToSpawner",{[1] = selectedMob})
  109.     end
  110.   else
  111.    -- println(mon,"You clicked on non button area ("..posX..","..posY..")")
  112.   end
  113. --  sleep(2.5)
  114. end
  115.  
  116. --print(command("selectMob", {[1] = mob}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement