Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- s = sensor.wrap("top")
- rednet.open("back")
- term.setBackgroundColor(32768)
- term.setCursorPos(1,1)
- term.clear()
- ------------------------------------------------------------
- term.setTextColor(colors.yellow)
- print("Item Trading System")
- print("~~~~~~~~~~~~~~~~~~~")
- print(" ")
- term.setTextColor(colors.red)
- print(" ")
- print("please come closer !!!")
- print("please come closer !!!")
- print("please come closer !!!")
- print(" ")
- print("Always stand inside the white circle")
- print("on the floor, that goes around the Computer.")
- print(" ")
- print(" ")
- print(" ")
- print(" ")
- term.setTextColor(colors.lightGray)
- print("Shop build by MagmaLP")
- print("System programmed by MagmaLP")
- print("01.01.2023")
- print("In case of errors please report to MagmaLP")
- ------------------------------------------------------------
- local itemList = { "HV Solar Panel", "MV Solar Panel", "LV Solar Panel", "ME Cable", "ME Storage Bus", "ME Import Bus",
- "ME Export Bus",
- "ME Controller", "ME Access Terminal", "ME Drive", "Re-Enriched Uranium Cell", "ME 64k Storage", "ME 16k Storage",
- "ME 4k Storage" }
- function calc_color(color)
- return math.pow(2, color - 1)
- end
- function msg(gap, line, color, groundb, text)
- term.setBackgroundColor(calc_color(groundb))
- term.setCursorPos(gap,line)
- term.setTextColor(calc_color(color))
- text = term.write(text)
- end
- file = fs.open("local/", "w") --name local löschen
- file.write(" ")
- file.close()
- m0 = 0
- m1 = 0
- m2 = 0
- m3 = 0
- m4 = 0
- m5 = 0
- m6 = 0
- m7 = 0
- m8 = 0
- m9 = 0
- m10 = 0
- m11 = 0
- m12 = 0
- m13 = 0
- m14 = 0
- m15 = 0
- m16 = 0
- m17 = 0
- M = {m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17}
- b1 = 0
- b2 = 0
- b3 = 8000
- b4 = 1000
- b5 = 150
- b6 = 10
- b7 = 125
- b8 = 125
- b9 = 120
- b10 = 250
- b11 = 150
- b12 = 65
- b13 = 3
- b14 = 5000
- b15 = 2000
- b16 = 1000
- b17 = 0
- B = {b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17}
- function kaufen()
- local event, button, X, Y = os.pullEvent("mouse_click")
- for i = 3,13 do --item von zeile 3-13
- if X >= 40 and X <= 42 and Y == i then -- +1
- if M[i] < 60 then -- max 60
- M[i] = M[i] + 1
- c = c + B[i]
- msg(44,i,04,16,""..M[i].."")
- msg(42,19,06,16,""..c.."$")
- break
- end
- end
- if X >= 47 and X <= 49 and Y == i then -- -1
- if M[i] > 0 then
- M[i] = M[i] - 1
- c = c - B[i]
- msg(44,i,04,16,""..M[i].." ")
- msg(42,19,06,16,""..c.."$ ")
- break
- end
- end
- end
- for i = 14,16 do --item von zeile 14-16
- if X >= 40 and X <= 42 and Y == i then -- +1
- if M[i] < 1 then -- max 1
- M[i] = M[i] + 1
- c = c + B[i]
- msg(44,i,04,16,""..M[i].."")
- msg(42,19,06,16,""..c.."$")
- break
- end
- end
- if X >= 47 and X <= 49 and Y == i then -- -1
- if M[i] > 0 then
- M[i] = M[i] - 1
- c = c - B[i]
- msg(44,i,04,16,""..M[i].." ")
- msg(42,19,06,16,""..c.."$ ")
- break
- end
- end
- end
- c = tonumber(c)
- money = tonumber(money)
- if X >= 11 and X <= 21 and Y == 19 then --Abbrechen
- os.reboot()
- elseif X >= 01 and X <= 08 and Y == 19 then --Kaufen
- if c > money then --zu wenig Geld
- msg(41,19,01,15," "..c.."$ ")
- sleep(0.25)
- msg(41,19,06,16," "..c.."$ ")
- sleep(0.25)
- msg(41,19,01,15," "..c.."$ ")
- sleep(0.25)
- msg(41,19,06,16," "..c.."$ ")
- sleep(0.5)
- elseif c <= money then --genug Geld
- money = money - c
- file = fs.open("local/" , "r") --read user
- name = file.readLine()
- file.close()
- file = fs.open("user/" ..name.. "/", "w")
- file.write(money)
- file.close()
- if fs.exists("spendmoney/" ..name) == false then --create spendmoney directory
- file = fs.open("spendmoney/" ..name.. "/", "w")
- file.write(0.0)
- file.close()
- end
- file = fs.open("spendmoney/" ..name, "r") --read user of spendmoney directory
- oldspendmoney = file.readLine()
- file.close()
- spendmoney = oldspendmoney + c
- file = fs.open("spendmoney/" ..name.. "/", "w")
- file.write(spendmoney)
- file.close()
- package = {}
- for i,amount in pairs(M) do --sende Daten an turtle
- local a = {}
- if amount > 0 then
- local num = i - 2
- a = {
- ["Slot"] = num,
- ["Amount"] = amount
- }
- table.insert(package, a)
- writeToFile(num, amount)
- end
- end
- rednet.open("back")
- rednet.send(11894,textutils.serialize(package))
- os.reboot()
- end
- end
- -- end
- kaufen()
- end
- function writeToFile(item, amount)
- local file = http.get("http://www.atomuhr.de/uhrzeit/")
- local file2 = file.readAll()
- local length = file2.len(file2)
- local start = length - 40
- local endString = length - 22
- local time = string.sub(file2, start, endString)
- file = fs.open("kaufliste", "a")
- file.write("\n", " ")
- file.write(time.." ")
- file.write(name.." ")
- file.write(itemList[item].." "..amount)
- file.close()
- end
- while true do
- for name,info in pairs(s.getTargets()) do --detect user
- if fs.exists("user/" ..name) == false then --create user
- file = fs.open("user/" ..name.. "/", "w")
- file.write(0.0)
- money = "0.0"
- file.close()
- else
- file = fs.open("user/" ..name, "r") --read user
- money = file.readLine()
- file.close()
- end
- file = fs.open("local/", "w") --name local speichern
- file.write(name)
- file.close()
- for a = 1,20 do
- for b = 1,51 do
- msg(b,a,16,16," ")
- end
- end
- msg(01,01,06,16,"< Account of "..name.." >") msg(36,01,06,16," > "..money.."$ ") --überschrift
- msg(01,02,04,16,"+-------------------------------------------------+")
- msg(06,07,01,15," ") msg(30,07,01,15," ") --mainscreen
- msg(06,08,01,15," deposit money ") msg(30,08,01,15," buy items ")
- msg(06,09,01,15," ") msg(30,09,01,15," ")
- msg(02,13,09,16,"This PC exchanges items for virtual money")
- msg(02,14,09,16,"(saved on this PC)")
- msg(02,15,09,16,"in order to buy other items with it.")
- msg(01,19,01,16," >> Top-List << ")
- local event, button, X, Y = os.pullEvent("mouse_click")
- if X >= 06 and X <= 23 and Y >= 07 and Y <= 09 then --Verkauf Screen
- for a = 3,20 do
- for b = 1,50 do
- msg(b,a,16,16," ")
- end
- end
- sleep(0.5)
- msg(02,06,01,15," ")
- msg(02,07,01,15," click here to see a list of all sellable items ")
- msg(02,08,01,15," ")
- msg(02,12,09,16,"Throw in all items on the left and confirm with")
- msg(02,13,09,16,"the button below. The money is stored permanently ")
- msg(02,14,09,16,"until you buy something with it.")
- msg(40,16,01,15," ")
- msg(40,17,01,15," confirm ") msg(32,17,01,16,"----->")
- msg(40,18,01,15," ")
- msg(01,19,16,01,"back")
- local event, button, X, Y = os.pullEvent("mouse_click")
- if X >= 03 and X <= 48 and Y >= 06 and Y <= 08 then --item list button
- for a = 3,20 do
- for b = 1,50 do
- msg(b,a,16,16," ")
- end
- end
- msg(02,04,09,16,"1x Shard of Minium = 25$ (64x = 1600$)")
- msg(02,05,09,16,"1x Quartz Crystal = 25$ (64x = 1600$)")
- msg(02,06,09,16,"1x Lead Ore = 4$ (64x = 256$)")
- msg(02,07,09,16,"1x Silver Ore = 3$ (64x = 192$)")
- msg(02,08,09,16,"1x Tungsten Ore = 40$ (64x = 2560$)")
- msg(02,09,09,16,"1x Ferrouse Ore = 50$ (64x = 3200$)")
- msg(02,10,09,16,"1x Ghast Tear = 120$ (64x = 7680$)")
- msg(02,11,09,16,"1x Shiny Ingot = 500$ (64x = 32000$)")
- msg(02,12,09,16,"1x Wither Skull = 2000$")
- msg(02,13,09,16,"1x Nether Star = 6000$")
- msg(01,19,16,01,"back")
- local event, button, X, Y = os.pullEvent("mouse_click")
- if X >= 01 and X <= 04 and Y == 19 then --back button
- os.reboot()
- end
- elseif X >= 40 and X <= 49 and Y >= 16 and Y <= 18 then --confirm button
- rednet.send(11900,1)
- x, y, z = rednet.receive()
- money = y + money
- local file = fs.open("user/" ..name.. "/", "w")
- file.write(money)
- file.close()
- elseif X >= 01 and X <= 04 and Y == 19 then --back button2
- os.reboot()
- end
- elseif X >= 30 and X <= 45 and Y >= 07 and Y <= 09 then --kaufen Screen
- for a = 3,20 do
- for b = 1,50 do
- msg(b,a,16,16," ")
- end
- end
- c = 0.0
- msg(01,03,04,16,"| 8000$ HV Solar Panel") msg(51,03,04,16,"|")
- msg(01,04,04,16,"| 1000$ MV Solar Panel") msg(51,04,04,16,"|")
- msg(01,05,04,16,"| 150$ LV Solar Panel") msg(51,05,04,16,"|")
- msg(01,06,04,16,"| 10$ ME Cable ") msg(51,06,04,16,"|")
- msg(01,07,04,16,"| 125$ ME Storage Bus ") msg(51,07,04,16,"|")
- msg(01,08,04,16,"| 125$ ME Import Bus ") msg(51,08,04,16,"|")
- msg(01,09,04,16,"| 120$ ME Export Bus ") msg(51,09,04,16,"|")
- msg(01,10,04,16,"| 250$ ME Controller ") msg(51,10,04,16,"|")
- msg(01,11,04,16,"| 150$ ME Access Terminal") msg(51,11,04,16,"|")
- msg(01,12,04,16,"| 65$ ME Drive") msg(51,12,04,16,"|")
- msg(01,13,04,16,"| 3$ Re-Enriched Uranium Cell") msg(51,13,04,16,"|")
- msg(01,14,04,16,"| 5000$ ME 64k Storage ") msg(51,14,04,16,"|")
- msg(01,15,04,16,"| 2000$ ME 16k Storage ") msg(51,15,04,16,"|")
- msg(01,16,04,16,"| 1000$ ME 4k Storage ") msg(51,16,04,16,"|")
- msg(01,17,04,16,"| ") msg(51,17,04,16,"|")
- msg(01,18,04,16,"+-------------------------------------------------+")
- msg(01,19,01,15," Buy ") msg(11,19,01,15," Cancel ")
- msg(34,19,04,16,"Amount:") msg(42,19,06,16,""..c.."$")
- for i = 3,16 do -- +für zeile 3-16
- msg(40,i,01,15," + ")
- end
- for i = 3,16 do -- 0für zeile 3-16
- msg(44,i,04,16,"0")
- end
- for i = 3,16 do -- -für zeile 3-16
- msg(47,i,01,15," - ")
- end
- kaufen()
- elseif X >= 19 and X <= 34 and Y >= 18 and Y <= 19 then --Top-List Screen
- for a = 1,20 do
- for b = 1,50 do
- msg(b,a,16,16," ")
- end
- end
- msg(01,01,06,16," Money - Top List ") --überschrift 1
- msg(01,02,04,16,"+-------------------------------------------------+")
- -- Funktion zum Einlesen des Inhalts einer Datei und Umwandeln in eine Zahl
- local function readNumberFromFile(fileName)
- local file = fs.open(fileName, "r")
- if file then
- local content = file.readAll()
- file.close()
- return tonumber(content)
- end
- return nil
- end
- -- Verzeichnisname
- local directory = "user"
- -- Liste aller Dateien im Verzeichnis
- local files = fs.list(directory)
- -- Tabelle zur Speicherung der Spieler und ihrer Punkte
- local scores = {}
- -- Durchlaufen aller Dateien im Verzeichnis
- for _, file in ipairs(files) do
- local filePath = fs.combine(directory, file)
- local score = readNumberFromFile(filePath)
- if score then
- table.insert(scores, {name = file, score = score})
- end
- end
- -- Funktion zum Sortieren der Scores
- local function compareScores(a, b)
- return a.score > b.score
- end
- -- Sortieren der Scores
- table.sort(scores, compareScores)
- -- Ausgabe der Top 5 Spieler
- for i = 1, math.min(6, #scores) do
- print(i .. ". " .. scores[i].name .. " - " .. scores[i].score)
- end
- msg(01,10,06,16," Money spend - Top List ") --überschrift 2
- msg(01,11,04,16,"+-------------------------------------------------+")
- -- Funktion zum Einlesen des Inhalts einer Datei und Umwandeln in eine Zahl
- local function readNumberFromFile(fileName)
- local file = fs.open(fileName, "r")
- if file then
- local content = file.readAll()
- file.close()
- return tonumber(content)
- end
- return nil
- end
- -- Verzeichnisname
- local directory = "spendmoney"
- -- Liste aller Dateien im Verzeichnis
- local files = fs.list(directory)
- -- Tabelle zur Speicherung der Spieler und ihrer Punkte
- local scores = {}
- -- Durchlaufen aller Dateien im Verzeichnis
- for _, file in ipairs(files) do
- local filePath = fs.combine(directory, file)
- local score = readNumberFromFile(filePath)
- if score then
- table.insert(scores, {name = file, score = score})
- end
- end
- -- Funktion zum Sortieren der Scores
- local function compareScores(a, b)
- return a.score > b.score
- end
- -- Sortieren der Scores
- table.sort(scores, compareScores)
- -- Ausgabe der Top 5 Spieler
- for i = 1, math.min(6, #scores) do
- print(i .. ". " .. scores[i].name .. " - " .. scores[i].score)
- end
- msg(01,19,16,01,"back")
- local event, button, X, Y = os.pullEvent("mouse_click")
- if X >= 01 and X <= 04 and Y == 19 then --back button
- os.reboot()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement