Advertisement
VikeStepFTB

CCGames: terminalGlasses

Dec 21st, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. --Initialising Variables
  2. local users = {} --All
  3. local num = 0
  4. local p = peripheral.wrap("top")
  5. local welcomeText = {{"Welcome to the"},{"ComputerCraft Games!"},{""},{"type $$next in chat to"},{"go to next screen"}}
  6. local nextText = {{"This is the second"},{"page"},{""},{"Success!"}}
  7.  
  8. function displayText(text,surface)
  9.     surface.clear()
  10.     local longestString = 0
  11.     for i = 1, #text do
  12.         text[i][2] = p.getStringWidth(text[i][1])
  13.         if text[i][2] > longestString then
  14.             longestString = text[i][2]
  15.         end
  16.     end
  17.     longestString = longestString + 2
  18.     surface.addBox(0,0,longestString,1000,0xFFFFFF,0.5)
  19.     local line = 1
  20.     for i = 1, #text do
  21.         local textX = math.floor((longestString - text[i][2])/2)
  22.         surface.addText(textX,line,text[i][1],0x000000)
  23.         line = line + 9
  24.     end
  25. end
  26.  
  27. function newUser()
  28.     num = #p.getUsers()
  29.     users[num] = {}
  30.     users[num].name = p.getUsers()[num]
  31.     users[num].surface = p.getUserSurface(p.getUsers()[num])
  32.     displayText(welcomeText,users[num].surface)
  33. end
  34.  
  35. function nextScreen(player)
  36.     for i = 1, #users do
  37.         if player == users[i].name then
  38.             displayText(nextText,users[i].surface)
  39.         end
  40.     end
  41. end
  42.  
  43. while true do
  44.     os.queueEvent("wait")
  45.     evt, p1, p2, p3 = os.pullEvent()
  46.     if #p.getUsers() ~= #users then
  47.         newUser()
  48.     elseif evt =="chat_command" and #users > 0 and cmd == "sleep" then
  49.         nextScreen(p2)
  50.     else
  51.         sleep(0)
  52.         os.queueEvent("wait")
  53.     end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement