Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Monitor -> front
- Logistic Pipe -> right
- Player Sensor -> bottom
- Inventory Sensor -> left
- --]]
- os.pullEvent = os.pullEventRaw
- mon = peripheral.wrap("front")
- term.clear()
- term.setCursorPos(1,1)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setTextScale(0.5)
- if fs.isDir("users") ~= true then
- fs.makeDir("users")
- end
- if fs.isDir("data") ~= true then
- fs.makeDir("data")
- end
- os.loadAPI("ocs/apis/sensor")
- pipe = peripheral.wrap("right")
- ------------------------------------
- local offset = {
- X = 4,
- Y = 0,
- Z = 0
- }
- local radius = 6
- function distance(pos)
- local xd = pos.X - offset.X
- local yd = pos.Y - offset.Y
- local zd = pos.Z - offset.Z
- return math.sqrt(xd*xd + yd*yd + zd*zd)
- end
- function player()
- local tablePCount = {}
- local tablePlayer = {}
- local proximity = sensor.wrap("bottom")
- local targets = proximity.getTargets()
- for k, v in pairs(targets) do
- if distance(v.Position) < radius then
- table.insert(tablePCount, "1")
- table.insert(tablePlayer, k)
- end
- end
- if sum(tablePCount) == 1 then
- return tablePlayer[1]
- else
- local player = 0
- return player
- end
- end
- function sum(data)
- local sum = 0
- for k, v in pairs(data) do
- sum = sum + v
- end
- return sum
- end
- function xPos(txt)
- local l = string.len(txt)
- local a, b = mon.getSize()
- local xpos = math.floor((a - l)/2 + 1)
- return xpos
- end
- function pos(x,y)
- return mon.setCursorPos(x,y)
- end
- function loadpw(user)
- local file = fs.open("users/" .. user, "r")
- if file then
- local password = tostring(file.readLine())
- file.close()
- return password
- else
- return nil
- end
- end
- function savepw(p, pw)
- file = fs.open("users/" .. p, "w")
- file.writeLine(pw)
- file.close()
- end
- function button(x, y, size, lenght, color_txt, color_bg, txt)
- for yPos = y, y+size-1 do
- pos(x, yPos)
- mon.setBackgroundColor(color_bg)
- mon.write(string.rep(" ", lenght))
- end
- local ypos = math.floor(y + (size/2))
- local l = string.len(txt)
- local xpos = math.floor((lenght - l)/2 + x)
- pos(xpos, ypos)
- mon.setTextColor(color_txt)
- mon.write(txt)
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- end
- function register()
- cap = math.random(10000, 99999)
- mon.clear()
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- pos(1,1)
- mon.write("Bitte benutze nicht deine Minecraft Passwort!")
- pos(1,3)
- mon.write("ID:")
- pos(1,5)
- mon.write("Passwort: ")
- pos(23,7)
- mon.setBackgroundColor(colors.white)
- mon.setTextColor(colors.black)
- mon.write(string.rep(" ", 7))
- pos(23,8)
- mon.write(" " .. cap .. " ")
- pos(23,9)
- mon.write(string.rep(" ", 7))
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- pos(1,11)
- mon.write("Captcha: ")
- pos(23,5)
- password = read()
- pos(23,11)
- captcha = tonumber(read())
- end
- function registerbuttons()
- button(4, 16, 3, 14, colors.white, colors.orange, "Zuruecksetzen")
- button(20, 16, 3, 14, colors.white, colors.red, "Abbrechen")
- button(36, 16, 3, 14, colors.white, colors.green, "Abschliessen")
- pos(23,3)
- mon.write(player())
- pos(23,5)
- while true do
- local event, side, X, Y = os.pullEvent("monitor_touch")
- if X >= 4 and X <= 17 and Y >= 16 and Y <= 18 then
- pos(1,14)
- mon.setTextColor(colors.orange)
- mon.write("Felder werden zurueckgesetzt")
- sleep(2)
- parallel.waitForAll(register, registerbuttons)
- elseif X >= 20 and X <= 33 and Y >= 16 and Y <= 18 and button == 1 then
- pos(1,14)
- mon.setTextColor(colors.red)
- mon.write("Registrierung abgebrochen!")
- sleep(2)
- startscreen()
- elseif X >= 36 and X <= 49 and Y >= 16 and Y <= 18 and button == 1 then
- if captcha == cap and string.len(password) > 4 then
- savepw(player(), password)
- pos(1,14)
- mon.setTextColor(colors.lime)
- mon.write("Registrierung erfolgreich!")
- sleep(1)
- startscreen()
- elseif password == nil then
- pos(1,14)
- mon.setTextColor(colors.red)
- mon.write("Passwort zu kurz! (Mindstlaenge: 5)")
- sleep(3)
- parallel.waitForAll(register, registerbuttons)
- elseif string.len(password) < 5 then
- pos(1,14)
- mon.setTextColor(colors.red)
- mon.write("Passwort zu kurz! (Mindstlaenge: 5)")
- sleep(3)
- parallel.waitForAll(register, registerbuttons)
- elseif captcha ~= cap then
- pos(1,14)
- mon.setTextColor(colors.red)
- mon.write("Captcha falsch!")
- sleep(3)
- parallel.waitForAll(register, registerbuttons)
- end
- end
- end
- end
- function status()
- pos(1,1)
- mon.clearLine()
- mon.write("ID: " .. player())
- --[[ if loadpw(player()) ~= nil then
- pos(27,1)
- mon.write("Status: registriert")
- else
- pos(27,1)
- mon.write("Status: nicht registriert")
- end--]]
- end
- function request(id, amount, data)
- id = pipe.getItemIdentifierIDFor(id, data or 0)
- pipe.makeRequest(id, amount)
- end
- function startscreen()
- mon.clear()
- status()
- while true do
- if loadpw(player()) ~= nil then
- button(18, 8, 3, 15, colors.white, colors.green, "Login")
- else
- button(18, 8, 3, 15, colors.white, colors.green, "Registrierung")
- end
- local event, side, X, Y = os.pullEvent("monitor_touch")
- if X >= 18 and X <= 32 and Y >= 8 and Y <= 10 and loadpw(player()) ~= nil then
- login()
- elseif X >= 18 and X <= 32 and Y >= 8 and Y <= 10 and loadpw(player()) == nil then
- parallel.waitForAll(register, registerbuttons)
- end
- end
- end
- function storage(itemName)
- local tableItem = {}
- local prox = sensor.wrap("left")
- local targets = prox.getTargets()
- for k, v in pairs(targets) do
- local details = prox.getTargetDetails(k)
- if details.Name == "Diamond Chest" then
- for i = 1, 108, 1 do
- local item = details.Slots[i].Name
- local amount = details.Slots[i].Size
- if item == itemName then
- table.insert(tableItem, amount)
- end
- end
- end
- end
- return tonumber(sum(tableItem))
- end
- function saveFile()
- local file = fs.open("data/" .. player(), "w")
- file.writeLine("" .. OakWood)
- file.close()
- end
- function loadFile()
- local file = fs.open("data/" .. player(), "r")
- if file then
- OakWood = tonumber(file.readLine())
- file.close()
- else
- OakWood = 512
- end
- end
- function selection()
- mon.clear()
- pos(xPos("Auswahl"), 3)
- mon.setTextColor(colors.lime)
- mon.write("Auswahl")
- button(2, 5, 3, 8, colors.white, colors.brown, "Wood")
- button(28, 21, 3, 8, colors.white, colors.red, "Exit")
- while true do
- status()
- local event, side, X, Y = os.pullEvent("monitor_touch")
- if X ~= nil and Y ~= nil then
- if X >= 2 and X <= 9 and Y >= 5 and Y <= 7 and player() ~= 0 then
- loadFile()
- wahl("Oak Wood", OakWood, 17)
- elseif X >= 28 and X <= 35 and Y >= 21 and Y <= 23 then
- os.reboot()
- else
- term.clear()
- print("nope")
- end
- end
- end
- end
- function touchpad(x,y)
- mon.setTextColor(colors.lightGray)
- for yPos = y,(y+11), 2 do
- pos(x,yPos)
- mon.clearLine()
- mon.write("+---+---+---+")
- end
- pos(x,(y+1))
- mon.clearLine()
- mon.write("|")
- pos((x+12),(y+1))
- mon.write("|")
- for yPos = (y+3),(y+9), 2 do
- pos(x,yPos)
- mon.write("|")
- pos((x+4),yPos)
- mon.write("|")
- pos((x+8),yPos)
- mon.write("|")
- pos((x+12),yPos)
- mon.write("|")
- end
- mon.setTextColor(colors.white)
- local x2 = x + 2
- local y2 = y + 3
- for i = 1,3 do
- pos(x2,y2)
- mon.write("" .. i)
- x2 = x2 + 4
- end
- local x2 = x + 2
- local y2 = y + 5
- for i = 4,6 do
- pos(x2,y2)
- mon.write("" .. i)
- x2 = x2 + 4
- end
- local x2 = x + 2
- local y2 = y + 7
- for i = 7,9 do
- pos(x2,y2)
- mon.write("" .. i)
- x2 = x2 + 4
- end
- pos((x+6),(y+9))
- mon.write("0")
- pos((x+1),(y+9))
- mon.setTextColor(colors.red)
- mon.write("DEL")
- pos((x+9),(y+9))
- mon.setTextColor(colors.green)
- mon.write("ENT")
- mon.setTextColor(colors.white)
- button(28, 21, 3, 8, colors.white, colors.red, "Exit")
- local tableNum = {}
- while true do
- local event, side, X, Y = os.pullEvent("monitor_touch")
- if event == "monitor_touch" then
- if X >= (x+1) and X <= (x+3) and Y == (y+3) then -- 1
- table.insert(tableNum, tonumber(1) )
- elseif X >= (x+5) and X <= (x+7) and Y == (y+3) then -- 2
- table.insert(tableNum, tonumber(2) )
- elseif X >= (x+9) and X <= (x+11) and Y == (y+3) then -- 3
- table.insert(tableNum, tonumber(3) )
- elseif X >= (x+1) and X <= (x+3) and Y == (y+5) then -- 4
- table.insert(tableNum, tonumber(4) )
- elseif X >= (x+5) and X <= (x+7) and Y == (y+5) then -- 5
- table.insert(tableNum, tonumber(5) )
- elseif X >= (x+9) and X <= (x+11) and Y == (y+5) then -- 6
- table.insert(tableNum, tonumber(6) )
- elseif X >= (x+1) and X <= (x+3) and Y == (y+7) then -- 7
- table.insert(tableNum, tonumber(7) )
- elseif X >= (x+5) and X <= (x+7) and Y == (y+7) then -- 8
- table.insert(tableNum, tonumber(8) )
- elseif X >= (x+9) and X <= (x+11) and Y == (y+7) then -- 9
- table.insert(tableNum, tonumber(9) )
- elseif X >= (x+5) and X <= (x+9) and Y == (y+9) then -- 0
- table.insert(tableNum, tonumber(0) )
- elseif X >= (x+1) and X <= (x+3) and Y == (y+9) then -- DELETE
- tableNum = {}
- pos((x+1),(y+1))
- mon.write(string.rep(" ", 11))
- elseif X >= 28 and X <= 35 and Y >= 21 and Y <= 23 then
- os.reboot()
- end
- local inputStr = ""
- for k,v in pairs( tableNum ) do
- inputStr = tonumber(inputStr .. v)
- end
- if X >= (x+9) and X <= (x+11) and Y == (y+9) then -- ENTER
- return inputStr
- end
- if string.len(inputStr) > 11 then
- return inputStr
- end
- pos((x+1),(y+1))
- mon.write("" .. inputStr)
- end
- end
- end
- function wahl(itemName, amountStor, id, data)
- mon.clear()
- pos(1,1)
- mon.write("Derzeitge Wahl: " .. itemName)
- pos(1,3)
- mon.write("Im Lager vorhanden: " .. storage(itemName))
- pos(1,5)
- mon.write("Dir noch zur Verfuegung stehend: " .. amountStor)
- pos(1,8)
- mon.write("Wie viel " .. itemName)
- pos(1,9)
- mon.write("moechtest du ausgeben?")
- local amount = tonumber(touchpad(1,14))
- if amount ~= nil then
- if amount <= storage(itemName) and amount <= amountStor then
- request(id, amount, data or 0)
- OakWood = amountStor - amount
- saveFile()
- pos(1,1)
- mon.clear()
- mon.write(amount .. " " .. itemName .. " liegen nun")
- pos(1,2)
- mon.write("rechts im ME-System")
- sleep(2)
- selection()
- elseif amount > storage(itemName) then
- pos(1,11)
- mon.clearLine()
- mon.write("Im Lager ist nicht genuegend")
- pos(1,12)
- mon.clearLine()
- mon.write(itemName .. " vorhanden.")
- sleep(2)
- selection()
- elseif amount > amountStor then
- pos(1,11)
- mon.clearLine()
- mon.write("Du hast fuer diese Woche bereits")
- pos(1,12)
- mon.clearLine()
- mon.write("den maximalen Betrag abgeholt.")
- sleep(2)
- selection()
- end
- else
- pos(1,11)
- mon.clearLine()
- mon.setTextColor(colors.red)
- mon.write("Gebe bitte eine Zahl ein.")
- mon.setTextColor(colors.white)
- sleep(2)
- wahl(itemName, amountStor, id, data)
- end
- end
- function login()
- mon.clear()
- pos(xPos("Login"), 3)
- mon.setTextColor(colors.lime)
- mon.write("Login")
- pos(1,6)
- mon.setTextColor(colors.white)
- mon.write("ID: ")
- pos(23,6)
- mon.write(player())
- pos(1,8)
- mon.clearLine()
- mon.write("Passwort:")
- sleep(0.5)
- passwort = nil
- parallel.waitForAll(input, loginbuttons)
- end
- function input(x,y)
- pos(23,8)
- passwort = tostring(read())
- end
- function loginbuttons()
- button(20, 16, 3, 14, colors.white, colors.red, "Abbrechen")
- button(36, 16, 3, 14, colors.white, colors.green, "Login")
- user = player()
- pos(23,8)
- while true do
- local event, side, X, Y = os.pullEvent("monitor_touch")
- if X >= 20 and X <= 33 and Y >= 16 and Y <= 18 then
- startscreen()
- elseif X >= 36 and X <= 49 and Y >= 16 and Y <= 18 then
- if passwort == loadpw(user) then
- selection()
- else
- pos(1,11)
- mon.setTextColor(colors.red)
- mon.write("Falsches Passwort")
- passwort = nil
- sleep(2)
- login()
- end
- end
- end
- end
- while true do
- selection()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement