Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Initialising Variables
- local users = {} --All
- local num = 0
- local p = peripheral.wrap("top")
- local welcomeText = {{"Welcome to the"},{"ComputerCraft Games!"},{""},{"type $$next in chat to"},{"go to next screen"}}
- local nextText = {{"This is the second"},{"page"},{""},{"Success!"}}
- function displayText(text,surface)
- surface.clear()
- local longestString = 0
- for i = 1, #text do
- text[i][2] = p.getStringWidth(text[i][1])
- if text[i][2] > longestString then
- longestString = text[i][2]
- end
- end
- longestString = longestString + 2
- surface.addBox(0,0,longestString,1000,0xFFFFFF,0.5)
- local line = 1
- for i = 1, #text do
- local textX = math.floor((longestString - text[i][2])/2)
- surface.addText(textX,line,text[i][1],0x000000)
- line = line + 9
- end
- end
- function newUser()
- num = #p.getUsers()
- users[num] = {}
- users[num].name = p.getUsers()[num]
- users[num].surface = p.getUserSurface(p.getUsers()[num])
- displayText(welcomeText,users[num].surface)
- end
- function nextScreen(player)
- for i = 1, #users do
- if player == users[i].name then
- displayText(nextText,users[i].surface)
- end
- end
- end
- while true do
- os.queueEvent("wait")
- evt, p1, p2, p3 = os.pullEvent()
- if #p.getUsers() ~= #users then
- newUser()
- elseif evt =="chat_command" and #users > 0 and cmd == "sleep" then
- nextScreen(p2)
- else
- sleep(0)
- os.queueEvent("wait")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement