View difference between Paste ID: FLG2SKe6 and TqV0Mi9L
SHOW: | | - or go back to the newest paste.
1-
local version = "1.13" --(01/09 2020)
1+
local version = "Dev" --(26/06 2020)
2-
os.loadAPI("/lib/f") -- a monitor API made by myself, it makes my life easier
2+
os.loadAPI("/spawner/f") -- a monitor API made by myself, it makes my life easier
3-
os.loadAPI("/lib/getInput") -- search bar read() function
3+
os.loadAPI("/spawner/lib/API") -- search_bar
4-
os.loadAPI("/portal/API") -- custom API to help run the program
4+
os.loadAPI("/spawner/lib/APIjson")
5-
local p = peripheral.find("draconic_chest") -- can change for "chest" instead of "draconic_chest"
5+
local list_items,items = {},{}
6-
local m = peripheral.find("monitor") -- running on a monitor
6+
local a,b,c,chestSize = 1,1,1,100
7-
local q = peripheral.find("peripheral")
7+
local Pcheck = false
8-
m.setTextScale(1)
8+
9-
local side,rside = "east","left" -- IMPORTANT
9+
b = {}
10-
local list_items,items,stq = {},{},{}
10+
function addButton(m,x1,y1,x2,y2,name)
11-
local a,b,c = 1,1,1
11+
  b[name] = {win = window.create(m,x1,y1,x2,y2)}
12-
local selected,last_dest = 0,"aucun"
12+
  b[name]["pos"] = {b[name].win.getPosition()} b[name]["size"] = {b[name].win.getSize()}
13-
local chestSize = p.getInventorySize()
13+
  b[name]["isClicked"] =
14-
local w,h = m.getSize()
14+
  function(x,y)
15
    local l = {x1,y1,x2+x1,y2+y1)
16-
local bg = window.create(m,1,1,w,h)
16+
    return f.box(x,y,l[1],l[2],l[3],l[4])
17-
local list = window.create(m,1,2,w*3/5-1,chestSize)
17+
18-
local up_bar = window.create(m,1,1,w,1)
18+
19-
local down_bar = window.create(m,1,h,w,h)
19+
20-
local scroll_bar = window.create(m,w*(3/5),2,1,h-1)
20+
function getPeriphs()
21-
local bg2 = window.create(m,w*0.6+1,2,w*0.4+1,h-1)
21+
  p = peripheral.find("diamond") -- can change for "chest" instead of "draconic_chest"
22-
local pbg2 = {bg2.getPosition()} sbg2 = {bg2.getSize()}
22+
  if p == nil then isChest = false else isChest = true end
23-
local button1 = window.create(bg2,2,3,sbg2[1]-3,3)
23+
  m = peripheral.find("monitor") -- running on a monitor
24-
local pb1 = {button1.getPosition()} sb1 = {button1.getSize()}
24+
  if m == nil then m = term.current() isMonitor = false else m.setTextScale(0.5) isMonitor = true end
25
  fxd = peripheral.find("thermaldynamics_fluxduct")
26
  w,h = m.getSize()
27
  bg = window.create(m,1,1,w,h)
28
  list = window.create(m,1,2,w*3/5-1,chestSize)
29
  up_bar = window.create(m,1,1,w,1)
30
  down_bar = window.create(m,1,h,w,h)
31
  scroll_bar = window.create(m,w*(3/5),2,1,h-1)
32
  bg2 = window.create(m,w*0.6+1,2,w*0.4+1,h-1)
33
  pbg2 = {bg2.getPosition()} sbg2 = {bg2.getSize()}
34
  addButton(bg2,2,13,sbg2[1]-2,3,"button1")
35
  addButton(bg2,2,9,5,3,"button2")
36
  addButton(bg2,2,3,5,3,"spawner1") addButton(bg2,10,3,5,3,"spawner2") addButton(bg2,18,3,5,3,"spawner3")
37-
  button1.setBackgroundColor(colors.red) button1.clear()
37+
  for q=1,3 do bq = b["spawner"..q]
38-
  f.centerText(up_bar,1,"selectionner une destination","black","lightGray")
38+
  b["spawner"..q].reset = function() b["spawner"..q].win.setBackgroundColor(colors.black) b["spawner"..q].win.clear() 
39-
  f.cprint(down_bar,1,1,"dernier tp : ","black")
39+
  f.cprint(b["spawner"..q].win,3,2,q,"lightGray","black") end
40
  b["spawner"..q].selected = function() b["spawner"..q].win.setBackgroundColor(colors.magenta) 
41-
  f.cprint(down_bar,14,1,last_dest,"blue","lightGray")
41+
  b["spawner"..q].win.clear() f.cprint(b["spawner"..q].win,3,2,q,"black","magenta") end
42
  b["spawner"..q].reset()
43
  end
44-
  f.cprint(bg2,2,1,"Status: ","white","gray")
44+
45-
  f.cprint(bg2,2,7,"Rechercher:","white","gray")
45+
getPeriphs()
46-
  f.centerText(button1,2,"fermer","black","red")
46+
47-
  f.drawLine(bg2,2,9,sbg2[1]-2.4,"lightGray")
47+
local default = {
48-
  if q ~= nil then
48+
  spawner1={side="east",curr_item=""},
49-
    local stq = q.getAllStacks()
49+
  spawner2={side="north",curr_item=""},
50-
    if stq[1] ~= nil then f.cprint(bg2,10,1,"ouvert","green","gray")
50+
  spawner3={side="west",curr_item=""},
51-
    else f.cprint(bg2,10,1,"en veille","yellow","gray") end
51+
  rside="right",
52
  enable = true,
53-
  if word ~= nil then f.cprint(bg2,2,9,word,"gray","lightGray") end
53+
  player_name="MarkFergus",
54-
  f.cprint(bg2,2,11,"Double-cliquer sur","white","gray")
54+
  server="infinity.mineaurion.com",
55-
  f.cprint(bg2,2,12," un nom pour se","white","gray")
55+
  selected = 0, rubrique = 1
56-
  f.cprint(bg2,2,13," teleporter.","white","gray")
56+
}
57-
  f.cprint(bg2,2,14,"Taper dans le","white","gray")
57+
58-
  f.cprint(bg2,2,15," computer une ","white","gray")
58+
if fs.exists("/spawner/config") == false then f1 = fs.open("/spawner/config","w") f1.write(textutils.serialise(default)) f1.close() end
59-
  f.cprint(bg2,2,16," recherche.","white","gray")
59+
f1 = fs.open("/spawner/config","r") index = textutils.unserialize(f1.readAll()) f1.close()
60
if fs.exists("/spawner/nbt") == false then error("missing 'nbt file'") end
61
f2 = fs.open("/spawner/nbt","r") nbt_index = textutils.unserialize(f2.readAll()) f2.close()
62-
function pulse()
62+
rubrique = index.rubrique selected = index.selected
63-
  rs.setAnalogOutput(rside,15)
63+
64-
  sleep(0.5)
64+
65-
  rs.setAnalogOutput(rside,0)
65+
66
local GUIDES = {"zorinova","DaikiKaminari","maxou684"}
67
68-
function getItems()
68+
69-
  b = 1
69+
70
  list.setBackgroundColor(colors.black) list.clear()
71
  up_bar.setBackgroundColor(colors.lightGray) up_bar.clear()
72
  down_bar.setBackgroundColor(colors.lightGray) down_bar.clear()
73-
      list_items[a] = p.getStackInSlot(a)
73+
74-
      if list_items[a] ~= nil and list_items[a].name == "teleporterMKI" then
74+
75
  b["button1"].win.setBackgroundColor(colors.purple) b["button1"].win.clear()
76
  b["button2"].win.setBackgroundColor(colors.red) b["button2"].win.clear()
77-
        items[b][2] = API.normalize(list_items[a].display_name)
77+
78-
        if API.check(VIP,items[b][2]) == true then items[b][3] = "VIP" end
78+
  if fxd~=nil then f.cprint(down_bar,1,1,fxd.getMaxEnergyStored()-fxd.getEnergyStored().." RF","red","lightGray") end
79-
        if API.check(GUIDES,items[b][2]) == true then items[b][3] = "guide" end
79+
80
  f.cprint(scroll_bar,1,h-2,"v","black","gray")
81
  f.cprint(bg2,2,1,"Mob: ","white","gray")
82
  f.cprint(bg2,7,1,index["spawner"..rubrique].curr_item,"purple","gray")
83
  f.cprint(bg2,8,10,"Status: ","white","gray")
84-
  table.sort(items, function(a, b) return a[2] < b[2] end)
84+
  if index.enable == true then f.cprint(bg2,16,10,"actif  ","lime","gray") else f.cprint(bg2,16,10,"inactif","purple","gray") end
85-
  table.insert(items,1,{1,">>> retour au Spawn <<<","spawn"})
85+
  f.centerText(b["button1"].win,2,"Rafraichir","black","purple")
86
  f.centerText(b["button2"].win,2,"i/o","black","red")
87
  f.cprint(up_bar,1,1,coordinates,"lime","lightGray")
88
  if rubrique == 1 then b["spawner1"].selected() f.centerText(up_bar,1,"config. spawner 1","black","lightGray")
89-
function list_display()
89+
  else b["spawner1"].reset() end
90
  if rubrique == 2 then b["spawner2"].selected() f.centerText(up_bar,1,"config. spawner 2","black","lightGray")
91
  else b["spawner2"].reset() end
92-
      f.drawLine(list,1,c,w,"red")
92+
  if rubrique == 3 then b["spawner3"].selected() f.centerText(up_bar,1,"config. spawner 3","black","lightGray")
93-
      f.centerTextRight(list,c,"ouvrir","white")
93+
  else b["spawner3"].reset() end
94
end
95
96
function getItems(check1)
97
  if check1 == true then
98-
      f.cprint(list,1,c,display[c][2],"gray")
98+
  local b = 1
99-
    elseif display[c][3] == "spawn" then
99+
100-
      f.centerText(list,c,display[c][2],"lightBlue")
100+
101-
    elseif display[c][3] == "VIP" then
101+
102-
      f.cprint(list,1,c,display[c][2],"orange")
102+
      item = p.getStackInSlot(a)
103-
    elseif display[c][3] == "guide" then
103+
      if item ~= nil and item.name == "mobSoul" then
104-
      f.cprint(list,1,c,display[c][2],"lime")
104+
105
        items[b][1] = a
106
        for ab=1,#nbt_index do
107
          if item.nbt_hash == nbt_index[ab].nbt_hash then items[b][2] = nbt_index[ab].name end
108
        end
109
        items[b]["qty"] = item.qty
110
        b = b + 1
111
      end
112
    end
113
  end
114
  if display == nil then display = items end
115
  end
116
end
117
118-
function search(entry)
118+
function list_display(check1)
119-
  bg2.setCursorPos(2,9)
119+
  if check1 == true then
120-
  word = getInput.read({bg2},30,"lightGray",entry)
120+
121-
  display = {}
121+
122-
  for i,v in pairs(items) do
122+
      f.drawLine(list,1,c,w,"lightBlue")
123-
    if string.find(v[2],word) ~= nil then
123+
      f.centerTextRight(list,c,tostring(items[c].qty),"black")
124-
      table.insert(display,v)
124+
125
      list.setBackgroundColor(colors.black)
126
    end
127
    if display[c][3] == nil then
128
      f.centerText(list,c,display[c][2],"purple")
129-
pulse()
129+
130
  end
131
  else f.centerText(list,1,"No chest found","red","black") end
132
end
133-
  getItems()
133+
134-
  list_display()
134+
135
  local x,y = list.getPosition()
136
  if direction == "up" and y <=1 then
137-
  x,y = list.getPosition()
137+
138
  elseif direction == "down" and y+#items > h-1 then
139-
  local event = {os.pullEvent()}
139+
140-
  if event[1] == "monitor_touch" then
140+
141-
    if event[4]-y+1 == selected and display[selected] ~= nil and event[3] < j-1 then
141+
142
  
143-
      f.centerText(up_bar,1,"ouverture...","black")
143+
function checkPlist()
144-
      pulse()
144+
  str = APIjson.decode(http.get("http://api.mineaurion.com/v1/serveurs/"..index.server).readAll())
145
  local Pcheck = false
146-
      p.pushItem(side,display[selected][1])
146+
  for i,v in pairs(str.joueurs) do
147-
      last_dest = display[selected][2]
147+
    if v == index.player_name then Pcheck = true end
148-
      getItems()
148+
149-
    elseif event[4] > 1 and event[3] < j-1 then
149+
  if (Pcheck==true and index.enable==true) then rs.setAnalogOutput(index.rside,15) else rs.setAnalogOutput(index.rside,0) end
150-
      selected = event[4]-y+1
150+
151-
    elseif event[4] == 2 and event[3] == j then
151+
152
function updateIndex()
153-
    elseif event[4] == h-1 and event[3] == j then
153+
  shell.run("rm","/spawner/config")
154
  index.rubrique = rubrique index.selected = selected
155-
    elseif f.itrv(event[3],pbg2[1],pbg2[1]+sbg2[1]) and f.itrv(event[4],pbg2[2],pbg2[2]+sbg2[2]) then
155+
  f3 = fs.open("/spawner/config","w") f3.write(textutils.serialise(index)) f3.close()
156-
      xc = event[3]-pbg2[1]+1 yc = event[4]-pbg2[2]+1
156+
157-
      if f.itrv(xc,pb1[1],pb1[1]+sb1[1]) and f.itrv(yc,pb1[2],pb1[2]+sb1[2]-1) then
157+
158-
        up_bar.clear()
158+
159-
        f.centerText(up_bar,1,"fermeture...","black")
159+
160-
        pulse()
160+
  getItems(isChest)
161
  list_display(isChest)
162-
      elseif f.itrv(xc,2,sbg2[1]) and f.itrv(yc,6,9) then
162+
163-
        search()
163+
164
  checkPlist()
165
  updateIndex()
166
  xl,yl = list.getPosition()
167-
  if event[1] == "char" then search(event[2]) end
167+
168
  refresh = os.startTimer(20)
169
  event = {os.pullEvent()}
170
  if event[1] == "peripheral_detach" or event[1] == "peripheral" then getPeriphs() end
171
  if event[1] == "monitor_touch" or event[1] == "mouse_click" then
172
    x = event[3] y = event[4]
173
    coordinates = tostring(x..";"..y..","..selected..","..j)
174
    if y-yl+1 == selected and display[selected] ~= nil and x < j-1 then
175
      up_bar.clear()
176
      f.centerText(up_bar,1,"reconfiguration...","black")
177
      sleep(0.5)
178
      p.pushItem(index["spawner"..rubrique].side,display[selected][1],1)
179
      index["spawner"..rubrique].curr_item = display[selected][2]
180
      getItems(isChest)
181
    elseif y > 1 and x < j-1 then
182
      selected = y-yl+1
183
    elseif y == 2 and x == j then
184
      scroll("up")
185
    elseif yl == h-1 and event[3] == j then
186
      scroll("down")
187
    elseif f.itrv(x,pbg2[1],pbg2[1]+sbg2[1]) and f.itrv(y,pbg2[2],pbg2[2]+sbg2[2]) then
188
      xc = x-pbg2[1]+1 yc = y-pbg2[2]+1
189
      if b["button1"].isClicked(xc,yc) then
190
        display = nil
191
        sleep(0.4)
192
      end
193
      if b["spawner1"].isClicked(xc,yc) then rubrique=1 end
194
      if b["spawner2"].isClicked(xc,yc) then rubrique=2 end
195
      if b["spawner3"].isClicked(xc,yc) then rubrique=3 end
196
      if b["button2"].isClicked(xc,yc) then
197
        if index.enable == true then index.enable = false else index.enable = true end
198
      end
199
    end
200
  end
201
end