Advertisement
1ng0

Control Spawn Center

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