Advertisement
Daraketh

createBaseScript

Sep 26th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.31 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 = 1
  6. local num = 1
  7. local numNoBase = 1
  8. local maxNames = 500
  9.  
  10. function contains(val)
  11.     for k,v in pairs(tmpPlayerTable) do
  12.         if (v["uuid"] == val) then
  13.             v["nearby"] = true
  14.             return true
  15.         end
  16.     end
  17.     return false
  18. end
  19.  
  20. function displayMainScreen()
  21.     mon.clear()
  22.     mon.setCursorPos(3,5)
  23.     mon.setTextColor(colors.purple)
  24.     mon.write("Welcome to Umbra Skyblocks")
  25.     mon.setCursorPos(4,10)
  26.     mon.setTextColor(colors.orange)
  27.     mon.write("Right click this screen")
  28.     mon.setCursorPos(6,11)
  29.     mon.setTextColor(colors.orange)
  30.     mon.write("to create a base or")
  31.     mon.setCursorPos(8,12)
  32.     mon.setTextColor(colors.orange)
  33.     mon.write("check base name")
  34. end
  35.  
  36. function displayCheckingScreen()
  37.     mon.clear()
  38.     mon.setCursorPos(4,9)
  39.     mon.setTextColor(colors.orange)
  40.     mon.write("Checking players nearby")
  41.     mon.setCursorPos(8,10)
  42.     mon.setTextColor(colors.orange)
  43.     mon.write("Please wait...")
  44. end
  45.  
  46. function displaySuccessScreen()
  47.     mon.clear()
  48.     mon.setCursorPos(4,9)
  49.     mon.setTextColor(colors.orange)
  50.     mon.write("Bases created, player's")
  51.     mon.setCursorPos(4,10)
  52.     mon.setTextColor(colors.orange)
  53.     mon.write("messaged with base name")
  54. end
  55.  
  56. function getPlayers()
  57.     islName = fs.open("createIsland/islandNames", "r")
  58.     local tmpLn = islName.readLine()
  59.    
  60.     local i = 1
  61.     while (tmpLn ~= nil) do
  62.         tmpPlayerTable[i] = {}
  63.         tmpPlayerTable[i]["islandName"] = string.sub(tmpLn, 1, 5)
  64.         tmpPlayerTable[i]["uuid"] = string.sub(tmpLn, 6, 41)
  65.         tmpPlayerTable[i]["name"] = string.sub(tmpLn, 42)
  66.         tmpPlayerTable[i]["hasBase"] = true
  67.         tmpPlayerTable[i]["ID"] = num
  68.         tmpPlayerTable[i]["nearby"] = false
  69.         print(tmpPlayerTable[i]["islandName"] .. " " .. tmpPlayerTable[i]["uuid"] .. " " .. tmpPlayerTable[i]["name"] .. " " .. tmpPlayerTable[i]["ID"])
  70.         i = i + 1
  71.         num = num + 1
  72.         tmpLn = islName.readLine()
  73.     end
  74.     islName.close()
  75. end
  76.  
  77. function checkBases()
  78.     local tmpPlayers = sens.getPlayers()
  79.     numNoBase = num
  80.     for k,v in pairs(tmpPlayers) do
  81.         if (contains(v["uuid"])) then
  82.             print(v["name"] .. " has a base")
  83.         else
  84.             print(v["name"] .. " does not have a base")
  85.             tmpPlayerTable[numNoBase] = {}
  86.             tmpPlayerTable[numNoBase]["islandName"] = ""
  87.             tmpPlayerTable[numNoBase]["uuid"] = v["uuid"]
  88.             tmpPlayerTable[numNoBase]["name"] = v["name"]
  89.             tmpPlayerTable[numNoBase]["hasBase"] = false
  90.             tmpPlayerTable[numNoBase]["ID"] = numNoBase
  91.             tmpPlayerTable[numNoBase]["nearby"] = true
  92.             numNoBase = numNoBase + 1
  93.         end
  94.     end
  95. end
  96.  
  97. function createBases()
  98.     local namePool = fs.open("createIsland/namePool", "r")
  99.     islName = fs.open("createIsland/islandNames", "a")
  100.     local nextName
  101.     if(num > maxNames or numNoBase > maxNames) then
  102.         print("All " .. maxNames .. " base names have been used, add more names!")
  103.         commands.exec("tellraw @a {text:'Please inform admins island names are exhausted!'}")
  104.         sleep(0.5)
  105.     else
  106.         local i = 1
  107.         while(i < num) do
  108.             nextName = namePool.readLine()
  109.             i = i + 1
  110.         end
  111.         for k,v in pairs (tmpPlayerTable) do
  112.             if (v["hasBase"] == true) then
  113.                 if (v["nearby"] == true) then
  114.                     commands.exec("tellraw " .. v["name"] .. " {text:'Your base name is " .. v["islandName"] .. "',bold:true}")
  115.                     sleep(0.5)
  116.                     commands.exec("tellraw " .. v["name"] .. " {text:'Use \"/island_join " .. v["islandName"] .. "\" to go to your island',bold:true}")
  117.                     sleep(0.5)
  118.                 end
  119.             else
  120.                 nextName = namePool.readLine()
  121.                 v["islandName"] = nextName
  122.                 commands.exec("island_create " .. v["islandName"])
  123.                 sleep(0.5)
  124.                 v["hasBase"] = true
  125.                 commands.exec("tellraw " .. v["name"] .. " {text:'Your base name is " .. v["islandName"] .. "',bold:true}")
  126.                 sleep(0.5)
  127.                 commands.exec("tellraw " .. v["name"] .. " {text:'Use \"/island_join " .. v["islandName"] .. "\" to go to your island',bold:true}")
  128.                 sleep(0.5)
  129.                 islName.writeLine(v["islandName"] .. v["uuid"] .. v["name"])
  130.             end
  131.         end
  132.     end
  133.     namePool.close()
  134.     islName.close()
  135. end
  136.  
  137. function main()
  138.     while true do
  139.         displayMainScreen()
  140.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  141.         displayCheckingScreen()
  142.         sleep(2.5)
  143.         getPlayers()
  144.         checkBases()
  145.         createBases()
  146.         displaySuccessScreen()
  147.         sleep(2.5)
  148.         tmpPlayerTable = {}
  149.         num = 1
  150.         numNoBase = 1
  151.     end
  152. end
  153.  
  154. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement