Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("left")
- local sens = peripheral.wrap("top")
- local w, h = mon.getSize()
- local tmpPlayerTable = {}
- local islName = 1
- local num = 1
- local numNoBase = 1
- local maxNames = 500
- function contains(val)
- for k,v in pairs(tmpPlayerTable) do
- if (v["uuid"] == val) then
- v["nearby"] = true
- return true
- end
- end
- return false
- end
- function displayMainScreen()
- mon.clear()
- mon.setCursorPos(3,5)
- mon.setTextColor(colors.purple)
- mon.write("Welcome to Umbra Skyblocks")
- mon.setCursorPos(4,10)
- mon.setTextColor(colors.orange)
- mon.write("Right click this screen")
- mon.setCursorPos(6,11)
- mon.setTextColor(colors.orange)
- mon.write("to create a base or")
- mon.setCursorPos(8,12)
- mon.setTextColor(colors.orange)
- mon.write("check base name")
- end
- function displayCheckingScreen()
- mon.clear()
- mon.setCursorPos(4,9)
- mon.setTextColor(colors.orange)
- mon.write("Checking players nearby")
- mon.setCursorPos(8,10)
- mon.setTextColor(colors.orange)
- mon.write("Please wait...")
- end
- function displaySuccessScreen()
- mon.clear()
- mon.setCursorPos(4,9)
- mon.setTextColor(colors.orange)
- mon.write("Bases created, player's")
- mon.setCursorPos(4,10)
- mon.setTextColor(colors.orange)
- mon.write("messaged with base name")
- end
- function getPlayers()
- islName = fs.open("createIsland/islandNames", "r")
- local tmpLn = islName.readLine()
- local i = 1
- while (tmpLn ~= nil) do
- tmpPlayerTable[i] = {}
- tmpPlayerTable[i]["islandName"] = string.sub(tmpLn, 1, 5)
- tmpPlayerTable[i]["uuid"] = string.sub(tmpLn, 6, 41)
- tmpPlayerTable[i]["name"] = string.sub(tmpLn, 42)
- tmpPlayerTable[i]["hasBase"] = true
- tmpPlayerTable[i]["ID"] = num
- tmpPlayerTable[i]["nearby"] = false
- print(tmpPlayerTable[i]["islandName"] .. " " .. tmpPlayerTable[i]["uuid"] .. " " .. tmpPlayerTable[i]["name"] .. " " .. tmpPlayerTable[i]["ID"])
- i = i + 1
- num = num + 1
- tmpLn = islName.readLine()
- end
- islName.close()
- end
- function checkBases()
- local tmpPlayers = sens.getPlayers()
- numNoBase = num
- for k,v in pairs(tmpPlayers) do
- if (contains(v["uuid"])) then
- print(v["name"] .. " has a base")
- else
- print(v["name"] .. " does not have a base")
- tmpPlayerTable[numNoBase] = {}
- tmpPlayerTable[numNoBase]["islandName"] = ""
- tmpPlayerTable[numNoBase]["uuid"] = v["uuid"]
- tmpPlayerTable[numNoBase]["name"] = v["name"]
- tmpPlayerTable[numNoBase]["hasBase"] = false
- tmpPlayerTable[numNoBase]["ID"] = numNoBase
- tmpPlayerTable[numNoBase]["nearby"] = true
- numNoBase = numNoBase + 1
- end
- end
- end
- function createBases()
- local namePool = fs.open("createIsland/namePool", "r")
- islName = fs.open("createIsland/islandNames", "a")
- local nextName
- if(num > maxNames or numNoBase > maxNames) then
- print("All " .. maxNames .. " base names have been used, add more names!")
- commands.exec("tellraw @a {text:'Please inform admins island names are exhausted!'}")
- sleep(0.5)
- else
- local i = 1
- while(i < num) do
- nextName = namePool.readLine()
- i = i + 1
- end
- for k,v in pairs (tmpPlayerTable) do
- if (v["hasBase"] == true) then
- if (v["nearby"] == true) then
- commands.exec("tellraw " .. v["name"] .. " {text:'Your base name is " .. v["islandName"] .. "',bold:true}")
- sleep(0.5)
- commands.exec("tellraw " .. v["name"] .. " {text:'Use \"/island_join " .. v["islandName"] .. "\" to go to your island',bold:true}")
- sleep(0.5)
- end
- else
- nextName = namePool.readLine()
- v["islandName"] = nextName
- commands.exec("island_create " .. v["islandName"])
- sleep(0.5)
- v["hasBase"] = true
- commands.exec("tellraw " .. v["name"] .. " {text:'Your base name is " .. v["islandName"] .. "',bold:true}")
- sleep(0.5)
- commands.exec("tellraw " .. v["name"] .. " {text:'Use \"/island_join " .. v["islandName"] .. "\" to go to your island',bold:true}")
- sleep(0.5)
- islName.writeLine(v["islandName"] .. v["uuid"] .. v["name"])
- end
- end
- end
- namePool.close()
- islName.close()
- end
- function main()
- while true do
- displayMainScreen()
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- displayCheckingScreen()
- sleep(2.5)
- getPlayers()
- checkBases()
- createBases()
- displaySuccessScreen()
- sleep(2.5)
- tmpPlayerTable = {}
- num = 1
- numNoBase = 1
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement