Advertisement
Guest User

createIsland.lua

a guest
Sep 27th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | None | 0 0
  1. local mon = peripheral.wrap("left")
  2. local sens = peripheral.wrap("top")
  3. local w, h = mon.getSize()
  4. local tmpPlayerTable = {}
  5. local islName = 0
  6.  
  7. function printPlayersTable(tab)
  8.     for playerNumber,playerTable in pairs(tab) do
  9.         print("Player:" .. playerNumber)
  10.         for k,v in pairs(playerTable) do
  11.             print(k .. ": " .. v)
  12.         end
  13.     end
  14. end
  15.  
  16. function printTable(tab)
  17.     for k,v in pairs(tab) do
  18.         print(k,v)
  19.     end
  20. end
  21.  
  22. function displayMainScreen()
  23.     mon.clear()
  24.     mon.setCursorPos(3,5)
  25.     mon.setTextColor(colors.purple)
  26.     mon.write("Welcome to Umbra Skyblocks")
  27.     mon.setCursorPos(4,10)
  28.     mon.setTextColor(colors.orange)
  29.     mon.write("Right click this screen")
  30.     mon.setCursorPos(6,11)
  31.     mon.setTextColor(colors.orange)
  32.     mon.write("to create a base or")
  33.     mon.setCursorPos(8,12)
  34.     mon.setTextColor(colors.orange)
  35.     mon.write("check base name")
  36. end
  37.  
  38. function displayCheckingScreen()
  39.     mon.clear()
  40.     mon.setCursorPos(4,9)
  41.     mon.setTextColor(colors.orange)
  42.     mon.write("Checking players nearby")
  43.     mon.setCursorPos(8,10)
  44.     mon.setTextColor(colors.orange)
  45.     mon.write("Please wait...")
  46. end
  47.  
  48. function displaySuccessScreen()
  49.     mon.clear()
  50.     mon.setCursorPos(4,9)
  51.     mon.setTextColor(colors.orange)
  52.     mon.write("Bases created, player's")
  53.     mon.setCursorPos(4,10)
  54.     mon.setTextColor(colors.orange)
  55.     mon.write("messaged with base name")
  56. end
  57.  
  58. function getPlayers()
  59.     local tmpPlayers = sens.getPlayers()
  60.     local tmpLn = islName.readLine()
  61.    
  62.     local i = 1
  63.     while (tmpLn ~= nil) do
  64.         tmpPlayerTable[i] = {}
  65.         tmpPlayerTable[i]["uuid"] = string.sub(tmpLn, 1, 36)
  66.         tmpPlayerTable[i]["name"] = string.sub(tmpLn, 37)
  67.         i = i + 1
  68.         tmpLn = islName.readLine()
  69.         print(tmpPlayerTable[i-1]["uuid"])
  70.         print(tmpPlayerTable[i-1]["name"])
  71.     end
  72.    
  73.     --check if file was read correctly
  74.     --can comment this out once verified
  75.     --that the file is being read correctly
  76.     local i = 1
  77.     while (tmpPlayers[i] ~= nil) do
  78.         local playUUID = tostring(tmpPlayers[i]["uuid"])
  79.         local playName = tostring(tmpPlayers[i]["name"])
  80.         local hasBase = false
  81.         local tmpLn = islName.readLine()
  82.  
  83.         print(playUUID, playName)
  84.         i = i + 1
  85.     end
  86. end
  87.  
  88. function checkBases()
  89.  
  90. end
  91.  
  92. function createBases()
  93.  
  94. end
  95.  
  96. function main()
  97.     while true do
  98.         displayMainScreen()
  99.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  100.         displayCheckingScreen()
  101.   sleep(5)
  102.         islName = fs.open("createIsland/islandNames", "r")
  103.         getPlayers()
  104.         checkBases()
  105.         createBases()
  106.         displaySuccessScreen()
  107.         sleep(5)
  108.   islName.close()
  109.         tmpPlayerTable = {}
  110.     end
  111. end
  112.  
  113. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement