Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- by EnnekPL
- ------API's--------
- os.loadAPI("Apis/button")
- os.loadAPI("Apis/MisAPI")
- os.loadAPI("Apis/nbtAPI")
- -----Peripherals------
- mon = peripheral.wrap("back")
- p = peripheral.wrap("left")
- open = peripheral.wrap("right")
- --rednet.open("bottom")
- --test = open.listMethods()
- --print(test)
- --fs.makeDir("dane/")
- ------Settings--------
- world = p.getWorld(p.getPeripheralWorldID())
- poz = world.getClosestPlayer( 37,62, -60, 20)
- --username = poz.getUsername()
- info = {}
- infoEmc = {}
- daneZapis = {"4:0","5:0"}
- daneOdczyt = {}
- tabEmcVal = {}
- tempTab = {}
- local slotySkrzyni = 10
- local punkty = 0
- poj = false
- slotS = 0
- a, c, b = 37,62, -59 --poz skrzyni startowej
- d, e, f = 36, 62, -65 -- pozycja skrzynie przech
- local emc = 0
- local str = 1
- recordNaStr =1
- maxStron = 1
- iloscWybr = 1
- sumka = 0
- -------Functions-------
- function save(table, name)
- local file = fs.open(name, "w")
- file.write(textutils.serialize(table))
- file.close()
- sleep(0.1)
- end
- function load(name)
- local file = fs.open(name, "r")
- local data = file.readAll()
- file.close()
- -- sleep(0.1)
- return textutils.unserialize(data)
- end
- function cleanCheast(d, e, f)
- local skrzynia = world.getTileEntity(d, e, f)
- local nbt1 = nbtAPI.readTileNBT(skrzynia)
- for i=0,10,1 do
- table.insert(nbt1.value.Items.value, {type="compound", value={id={type="short", value=0}, Count={type="byte", value=0}, Damage={type="short", value=0}, Slot={type="byte", value=i}}})
- end
- nbtAPI.writeTileNBT(skrzynia, nbt1)
- end
- function pay(a, c, b, itemIds, metData, ilosc)
- -- world.setBlock(a, c, b, 433, 5)
- local te = world.getTileEntity(a, c, b)
- local nbt = nbtAPI.readTileNBT(te)
- for zz=1,ilosc,1 do
- table.insert(nbt.value.Items.value, {type="compound", value={id={type="short", value=itemIds}, Count={type="byte", value=1}, Damage={type="short", value=metData}, Slot={type="byte", value=zz}}})
- nbtAPI.writeTileNBT(te, nbt)
- end
- sleep(0.2)
- -- world.setBlock(a, c, b, 0, 0)
- -- sleep(0.2)
- end
- function findInTable(myTable, searchValue)
- for keys,vals in pairs(myTable) do
- if vals == searchValue then
- return true
- end
- end
- return false
- end
- function findInTable2(myTable1, searchValue1)
- for keys,vals in pairs(myTable1) do
- for keys1,vals1 in pairs(vals) do
- if vals1 == searchValue1 then
- return true
- end
- end
- end
- return false
- end
- function setInfo2(name, nazwaP, idP, pktMin, lp, xmin, xmax, ymin, ymax, strona)
- infoEmc[name] = {}
- infoEmc[name]["nazwa"] = nazwaP -- nazwa bloku/itemu
- infoEmc[name]["idP"] = idP -- id bloku/itemu
- infoEmc[name]["pktMin"] = pktMin -- punkty do odjecia emc
- infoEmc[name]["lp"] = lp -- numer
- infoEmc[name]["xmin"] = xmin
- infoEmc[name]["ymin"] = ymin
- infoEmc[name]["xmax"] = xmax
- infoEmc[name]["ymax"] = ymax
- infoEmc[name]["strona"] = strona
- end
- function clearTableEMC()
- infoEmc = {}
- end
- function sprawdzUsera()
- world = p.getWorld(p.getPeripheralWorldID())
- poz = world.getClosestPlayer( 37,62, -60, 20)
- username = poz.getUsername()
- if fs.exists("dane/dane_"..username) and fs.exists("dane/emc_"..username) then
- daneOdczyt = load("dane/dane_"..username)
- loadEmc = load("dane/emc_"..username)
- emc = tonumber(loadEmc)
- else
- emc = 0
- save(daneZapis, "dane/dane_"..username)
- save(emc, "dane/emc_"..username)
- end
- end
- function clearNauka(y)
- button.write(" ",colors.lime, 10, y)
- end
- function odbierzDane(slotS)
- if fs.exists("dane/dane_player") and fs.exists("dane/emc_player") then
- daneOdczyt = load("dane/dane_player")
- loadEmc = load("dane/emc_player")
- emc = tonumber(loadEmc)
- else
- emc = 0
- save(daneZapis, "dane/dane_player")
- save(emc, "dane/emc_player")
- end
- morDet = open.getStackInSlot(slotS)
- -- print(morDet.name.."| ID: "..morDet.id..":"..morDet.dmg.." ilosc: "..morDet.qty)
- -- morDet = open.getStackInSlot(0)
- if morDet == nil then
- poj = false
- idMet = "0:0"
- iloscMat = 0
- else
- --poj = true
- idMet = morDet.id..":"..morDet.dmg
- iloscMat = morDet.qty
- if findInTable(daneOdczyt, idMet) == false and findInTable2(tabEmcVal, idMet) == true then
- table.insert(daneOdczyt, idMet)
- clearNauka(40)
- button.writeCenter("Nauczono monitor: "..morDet.name,colors.lightBlue,10,62, 40)
- save(daneOdczyt, "dane/dane_player")
- else
- clearNauka(40)
- end
- if findInTable2(tabEmcVal, idMet) == false then
- pay(a, c, b, morDet.id, morDet.dmg, morDet.qty)
- button.writeCenter("Nie Mozna Nauczyc: "..morDet.name,colors.red,10,62, 40)
- end
- end
- -- print(idMet.." - "..iloscMat)
- return poj, idMet, iloscMat
- end
- function setInfo(name, Nazwa, emc)
- info[name] = {}
- info[name]["Nazwa"] = Nazwa -- nazwa
- info[name]["emc"] = emc --kolor cieczy
- end
- function fillTable2()
- setInfo("EMC", emc)
- end
- function odswierzDane(nazwa)
- sumka= 0
- for name, data in pairs(infoEmc) do
- if str == data["strona"] and nazwa == data["nazwa"] then
- button.InfoButton(tostring(iloscWybr), colors.blue, 33,40,32,34)
- button.InfoButton(data["nazwa"].." EMC = "..MisAPI.dot(data["pktMin"]), colors.blue, 12,60,28,30)
- sumka = data["pktMin"] * iloscWybr
- if sumka <= emc then
- button.InfoButton("Koszt: "..MisAPI.dot(sumka),colors.green, 12,35,36,38)
- button.setTable(" Wydaj ", butt6, 37,60,36,38)
- clearNauka(39)
- else
- button.InfoButton("Koszt: "..MisAPI.dot(sumka),colors.red, 12,35,36,38)
- clearNauka(39)
- button.writeCenter("ZA MALO EMC!!!",colors.lime,10,62, 39)
- end
- return nazwa66
- else
- button.InfoButton("BRAK WYBRANEGO PRZEDMIOTU", colors.red, 12,60,28,30)
- end
- end
- end
- function WyswietlMozliwe(tab1, tab2, idMet, iloscMat)
- tempTab = {}
- t={}
- t= tab2
- preEmc = 0
- punkty = emc
- tempX = 1
- for k,v in pairs(t) do
- for k1,v1 in pairs(v) do
- for k2,v2 in pairs(tab1) do
- if v1 == v2 and iloscMat > 0 and idMet ==v1 then
- -- print(k1.." : "..v1.." :"..k.." : "..iloscMat)
- preEmc = tonumber(k) * tonumber(iloscMat)
- -- print(k1.." ID: "..v1.." PreEMC: "..preEmc.." = "..iloscMat.." * "..k)
- end
- if v1 == v2 and k <= (punkty + preEmc) then
- tempTab1 = {k1,v1,k}
- table.insert(tempTab,tempTab1)
- end
- tempX = tempX +1
- end
- emc1 = preEmc
- --print(k.." - "..k1.." : "..v1)
- end
- end
- --save(tempTab, "dane/test")
- return emc1, tempTab
- end
- function wys(tempArray)
- button.pole(colors.black, 11,61,9,25)
- xb1= 12
- xb2= 26
- yb1= 10
- yb2= 12
- wysMax = 5
- maxStron1 =1
- for ix=1, #tempArray do
- maxStron1 = (ix / 12)
- maxStron = math.ceil(maxStron1)
- if ix >= recordNaStr and ix <= recordNaStr + 11 and emc >= tempArray[ix][3] then
- setInfo2(tempArray[ix][1],tempArray[ix][1], tempArray[ix][2], tempArray[ix][3], ix,xb1,xb2,yb1,yb2, str)
- button.InfoButton(tempArray[ix][1], colors.red, xb1,xb2, yb1,yb2)
- yb1= yb1 + 4
- yb2= yb2 + 4
- if yb2 > 26 and xb1 == 12 then
- --print("dupa")
- xb1 = xb1 + 16
- xb2 = xb1 + 16
- yb1 = 10
- yb2 = 12
- end
- if yb2 > 26 and xb1 == 28 then
- --print("dupa1")
- xb1 = xb1 + 18
- xb2 = xb2 + 16
- yb1 = 10
- yb2 = 12
- end
- --clearTableEMC()
- end
- end
- button.screen()
- fillTable2()
- end
- function butt4()
- iloscWybr = iloscWybr + 1
- if iloscWybr > 64 then iloscWybr = 64 end
- button.flash(" + ")
- odswierzDane(nazwa66)
- fillTable2()
- end
- function butt7()
- iloscWybr = iloscWybr + 10
- if iloscWybr > 64 then iloscWybr = 64 end
- button.flash("+10")
- odswierzDane(nazwa66)
- fillTable2()
- end
- function butt5()
- iloscWybr = iloscWybr - 1
- if iloscWybr < 1 then iloscWybr = 1 end
- odswierzDane(nazwa66)
- button.flash(" - ")
- fillTable2()
- end
- function butt8()
- iloscWybr = iloscWybr - 10
- if iloscWybr < 1 then iloscWybr = 1 end
- odswierzDane(nazwa66)
- button.flash("-10")
- fillTable2()
- end
- function butt10()
- iloscWybr = 64
- odswierzDane(nazwa66)
- button.flash("MAX")
- fillTable2()
- end
- function butt11()
- iloscWybr = 1
- odswierzDane(nazwa66)
- button.flash("MIN")
- fillTable2()
- end
- function butt6()
- sumka= 0
- for name, data in pairs(infoEmc) do
- if str == data["strona"] and nazwa66 == data["nazwa"] then
- sumka = data["pktMin"] * iloscWybr
- if sumka < emc then
- emc = emc - sumka
- idSub = data["idP"]
- pom = 0
- p = idSub:find(":") - pom
- pom = pom + p
- itemIds = idSub:sub(1, p -1)
- metData = idSub:sub(p + 1)
- itemIds1 = tonumber(itemIds)
- metData1 = tonumber(metData)
- iloscWybr1 = tonumber(iloscWybr)
- -- print(itemIds.."-"..metData)
- pay(a, c, b, itemIds1, metData1, iloscWybr1)
- -- print("Kupiono: "..iloscWybr.." szt. "..data["nazwa"].." za ".. sumka.." emc. ")
- else
- -- print("za malo emc ".. emc)
- end
- if emc <= 0 then emc = 0 end
- save(emc, "dane/emc_player")
- end
- end
- str = 1 -- ??????????
- recordNaStr = 1
- odswierzDane(nazwa66)
- odbierzDane(0)
- button.flash(" Wydaj ")
- fillTable2()
- return str, recordNaStr
- end
- function uzupelnij(x, y, iloscWybr)
- sumka= 0
- for name, data in pairs(infoEmc) do
- if str == data["strona"] then
- if y>=data["ymin"] and y <=data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- button.setTable(" + ", butt4, 42,46, 32,34)
- button.setTable("+10", butt7, 48,52, 32,34)
- button.setTable("MAX", butt10, 54,58, 32,34)
- button.setTable(" - ", butt5, 26,30, 32,34)
- button.setTable("-10", butt8, 20,24, 32,34)
- button.setTable("MIN", butt11, 14,18, 32,34)
- button.InfoButton(tostring(iloscWybr), colors.blue, 32,40,32,34)
- button.InfoButton(data["nazwa"].." EMC = "..MisAPI.dot(data["pktMin"]), colors.blue, 12,60,28,30)
- sumka = data["pktMin"] * iloscWybr
- nazwa66 = data["nazwa"]
- if sumka <= emc then
- button.InfoButton("Koszt: "..MisAPI.dot(sumka),colors.green, 12,35,36,38)
- button.setTable(" Wydaj ", butt6, 37,60,36,38)
- clearNauka(39)
- else
- button.InfoButton("Koszt: "..MisAPI.dot(sumka),colors.red, 12,35,36,38)
- clearNauka(39)
- button.writeCenter("ZA MALO EMC!!!",colors.lime,10,62, 39)
- end
- return sumka
- else
- button.InfoButton("BRAK WYBRANEGO PRZEDMIOTU", colors.red, 12,60,28,30)
- end
- end
- end
- end
- end
- function butt1()
- str = str -1
- recordNaStr = recordNaStr - 12
- if recordNaStr < 1 then recordNaStr = 1 end
- if str < 1 then
- str = 1
- else
- end
- button.flash("BACK")
- fillTable2()
- --return pokaz()
- end
- function butt2()
- str = str +1
- --recordNaStr = recordNaStr + 12
- if str > maxStron then
- str = maxStron
- else
- recordNaStr = recordNaStr + 12
- end
- button.flash("NEXT")
- fillTable2()
- --return pokaz()
- end
- mon.clear()
- shell.run("clear")
- tabEmcVal = load("dane/emc_value")
- button.setTable("BACK", butt1, 2,8, 8,39)
- button.setTable("NEXT", butt2, 64,70, 8,39)
- button.border(colors.blue,10,62,8,26,1)
- button.border(colors.yellow,2,70,2,6,1)
- odbierzDane(0)
- WyswietlMozliwe(daneOdczyt, tabEmcVal, idMet, iloscMat)
- button.write(" MASZ EMC: "..MisAPI.dot(emc),colors.lime, 20, 4)
- while true do
- button.write(" ",colors.lime, 20, 4)
- button.write(" MASZ EMC: "..MisAPI.dot(emc),colors.lime, 20, 4)
- button.pole(colors.black, 11,61,9,25)
- clearTableEMC()
- WyswietlMozliwe(daneOdczyt, tabEmcVal, idMet, iloscMat)
- wys(tempTab)
- button.write(" STRONA: "..str.."/"..maxStron, colors.yellow, 53, 4)
- button.screen()
- event,side,x,y,z = os.pullEvent()
- if event == "redstone" or event == "monitor_touch" then
- if event == "redstone" then
- if redstone.getInput("top") == true then
- zasysa = 1
- iloscMat1 = 0
- while zasysa > 0 do
- --print("poj "..poj)
- if poj == false then
- zasysa=0
- end
- sleep(0.8)
- for sloty=0,slotySkrzyni,1 do
- odbierzDane(sloty)
- WyswietlMozliwe(daneOdczyt, tabEmcVal, idMet, iloscMat)
- emc = emc + emc1
- save(emc, "dane/emc_player")
- odswierzDane(nazwa66)
- -- print("EMC ="..emc)
- end
- cleanCheast(d, e, f)
- sleep(0.3)
- end
- end
- elseif event == "monitor_touch" then
- uzupelnij(x, y,iloscWybr)
- button.checkxy(x, y)
- end
- end
- fillTable2()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement