Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = "Dev" --(26/06 2020)
- os.loadAPI("/spawner/f") -- a monitor API made by myself, it makes my life easier
- os.loadAPI("/spawner/lib/API") -- search_bar
- os.loadAPI("/spawner/lib/APIjson")
- local list_items,items = {},{}
- local a,b,c,chestSize = 1,1,1,100
- local Pcheck = false
- b = {}
- function addButton(m,x1,y1,x2,y2,name)
- b[name] = {win = window.create(m,x1,y1,x2,y2)}
- b[name]["pos"] = {b[name].win.getPosition()} b[name]["size"] = {b[name].win.getSize()}
- b[name]["isClicked"] =
- function(x,y)
- local l = {x1,y1,x2+x1,y2+y1)
- return f.box(x,y,l[1],l[2],l[3],l[4])
- end
- end
- function getPeriphs()
- p = peripheral.find("diamond") -- can change for "chest" instead of "draconic_chest"
- if p == nil then isChest = false else isChest = true end
- m = peripheral.find("monitor") -- running on a monitor
- if m == nil then m = term.current() isMonitor = false else m.setTextScale(0.5) isMonitor = true end
- fxd = peripheral.find("thermaldynamics_fluxduct")
- w,h = m.getSize()
- bg = window.create(m,1,1,w,h)
- list = window.create(m,1,2,w*3/5-1,chestSize)
- up_bar = window.create(m,1,1,w,1)
- down_bar = window.create(m,1,h,w,h)
- scroll_bar = window.create(m,w*(3/5),2,1,h-1)
- bg2 = window.create(m,w*0.6+1,2,w*0.4+1,h-1)
- pbg2 = {bg2.getPosition()} sbg2 = {bg2.getSize()}
- addButton(bg2,2,13,sbg2[1]-2,3,"button1")
- addButton(bg2,2,9,5,3,"button2")
- addButton(bg2,2,3,5,3,"spawner1") addButton(bg2,10,3,5,3,"spawner2") addButton(bg2,18,3,5,3,"spawner3")
- for q=1,3 do bq = b["spawner"..q]
- b["spawner"..q].reset = function() b["spawner"..q].win.setBackgroundColor(colors.black) b["spawner"..q].win.clear()
- f.cprint(b["spawner"..q].win,3,2,q,"lightGray","black") end
- b["spawner"..q].selected = function() b["spawner"..q].win.setBackgroundColor(colors.magenta)
- b["spawner"..q].win.clear() f.cprint(b["spawner"..q].win,3,2,q,"black","magenta") end
- b["spawner"..q].reset()
- end
- end
- getPeriphs()
- local default = {
- spawner1={side="east",curr_item=""},
- spawner2={side="north",curr_item=""},
- spawner3={side="west",curr_item=""},
- rside="right",
- enable = true,
- player_name="MarkFergus",
- server="infinity.mineaurion.com",
- selected = 0, rubrique = 1
- }
- if fs.exists("/spawner/config") == false then f1 = fs.open("/spawner/config","w") f1.write(textutils.serialise(default)) f1.close() end
- f1 = fs.open("/spawner/config","r") index = textutils.unserialize(f1.readAll()) f1.close()
- if fs.exists("/spawner/nbt") == false then error("missing 'nbt file'") end
- f2 = fs.open("/spawner/nbt","r") nbt_index = textutils.unserialize(f2.readAll()) f2.close()
- rubrique = index.rubrique selected = index.selected
- local VIP = {"TheBaslez","SesameChocolat","Jaguar","LeChikito","jungleis26","Ertupop","Veine","annelaure1912","Gaetann18",
- "GohuSan","boucherreb","Ciliste"}
- local GUIDES = {"zorinova","DaikiKaminari","maxou684"}
- function reset()
- bg.setBackgroundColor(colors.black) bg.clear()
- list.setBackgroundColor(colors.black) list.clear()
- up_bar.setBackgroundColor(colors.lightGray) up_bar.clear()
- down_bar.setBackgroundColor(colors.lightGray) down_bar.clear()
- scroll_bar.setBackgroundColor(colors.lightGray) scroll_bar.clear()
- bg2.setBackgroundColor(colors.gray) bg2.clear()
- b["button1"].win.setBackgroundColor(colors.purple) b["button1"].win.clear()
- b["button2"].win.setBackgroundColor(colors.red) b["button2"].win.clear()
- f.centerTextRight(down_bar,1,"v"..version,"black","lightGray")
- if fxd~=nil then f.cprint(down_bar,1,1,fxd.getMaxEnergyStored()-fxd.getEnergyStored().." RF","red","lightGray") end
- f.cprint(scroll_bar,1,1,"^","black","gray")
- f.cprint(scroll_bar,1,h-2,"v","black","gray")
- f.cprint(bg2,2,1,"Mob: ","white","gray")
- f.cprint(bg2,7,1,index["spawner"..rubrique].curr_item,"purple","gray")
- f.cprint(bg2,8,10,"Status: ","white","gray")
- if index.enable == true then f.cprint(bg2,16,10,"actif ","lime","gray") else f.cprint(bg2,16,10,"inactif","purple","gray") end
- f.centerText(b["button1"].win,2,"Rafraichir","black","purple")
- f.centerText(b["button2"].win,2,"i/o","black","red")
- f.cprint(up_bar,1,1,coordinates,"lime","lightGray")
- if rubrique == 1 then b["spawner1"].selected() f.centerText(up_bar,1,"config. spawner 1","black","lightGray")
- else b["spawner1"].reset() end
- if rubrique == 2 then b["spawner2"].selected() f.centerText(up_bar,1,"config. spawner 2","black","lightGray")
- else b["spawner2"].reset() end
- if rubrique == 3 then b["spawner3"].selected() f.centerText(up_bar,1,"config. spawner 3","black","lightGray")
- else b["spawner3"].reset() end
- end
- function getItems(check1)
- if check1 == true then
- local b = 1
- items = {}
- if chestSize ~= nil then
- for a=1,chestSize do
- item = p.getStackInSlot(a)
- if item ~= nil and item.name == "mobSoul" then
- items[b] = {}
- items[b][1] = a
- for ab=1,#nbt_index do
- if item.nbt_hash == nbt_index[ab].nbt_hash then items[b][2] = nbt_index[ab].name end
- end
- items[b]["qty"] = item.qty
- b = b + 1
- end
- end
- end
- if display == nil then display = items end
- end
- end
- function list_display(check1)
- if check1 == true then
- for c=1,#display do
- if c == selected then
- f.drawLine(list,1,c,w,"lightBlue")
- f.centerTextRight(list,c,tostring(items[c].qty),"black")
- else
- list.setBackgroundColor(colors.black)
- end
- if display[c][3] == nil then
- f.centerText(list,c,display[c][2],"purple")
- end
- end
- else f.centerText(list,1,"No chest found","red","black") end
- end
- function scroll(direction)
- local x,y = list.getPosition()
- if direction == "up" and y <=1 then
- list.reposition(1,y+2)
- elseif direction == "down" and y+#items > h-1 then
- list.reposition(1,y-2)
- end
- end
- function checkPlist()
- str = APIjson.decode(http.get("http://api.mineaurion.com/v1/serveurs/"..index.server).readAll())
- local Pcheck = false
- for i,v in pairs(str.joueurs) do
- if v == index.player_name then Pcheck = true end
- end
- if (Pcheck==true and index.enable==true) then rs.setAnalogOutput(index.rside,15) else rs.setAnalogOutput(index.rside,0) end
- end
- function updateIndex()
- shell.run("rm","/spawner/config")
- index.rubrique = rubrique index.selected = selected
- f3 = fs.open("/spawner/config","w") f3.write(textutils.serialise(index)) f3.close()
- end
- while true do
- reset()
- getItems(isChest)
- list_display(isChest)
- down_bar.redraw()
- up_bar.redraw()
- checkPlist()
- updateIndex()
- xl,yl = list.getPosition()
- j,k = scroll_bar.getPosition()
- refresh = os.startTimer(20)
- event = {os.pullEvent()}
- if event[1] == "peripheral_detach" or event[1] == "peripheral" then getPeriphs() end
- if event[1] == "monitor_touch" or event[1] == "mouse_click" then
- x = event[3] y = event[4]
- coordinates = tostring(x..";"..y..","..selected..","..j)
- if y-yl+1 == selected and display[selected] ~= nil and x < j-1 then
- up_bar.clear()
- f.centerText(up_bar,1,"reconfiguration...","black")
- sleep(0.5)
- p.pushItem(index["spawner"..rubrique].side,display[selected][1],1)
- index["spawner"..rubrique].curr_item = display[selected][2]
- getItems(isChest)
- elseif y > 1 and x < j-1 then
- selected = y-yl+1
- elseif y == 2 and x == j then
- scroll("up")
- elseif yl == h-1 and event[3] == j then
- scroll("down")
- elseif f.itrv(x,pbg2[1],pbg2[1]+sbg2[1]) and f.itrv(y,pbg2[2],pbg2[2]+sbg2[2]) then
- xc = x-pbg2[1]+1 yc = y-pbg2[2]+1
- if b["button1"].isClicked(xc,yc) then
- display = nil
- sleep(0.4)
- end
- if b["spawner1"].isClicked(xc,yc) then rubrique=1 end
- if b["spawner2"].isClicked(xc,yc) then rubrique=2 end
- if b["spawner3"].isClicked(xc,yc) then rubrique=3 end
- if b["button2"].isClicked(xc,yc) then
- if index.enable == true then index.enable = false else index.enable = true end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment