Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- The name of the player to check for
- local targetPlayer = "PlayerName"
- -- Redstone output side (right)
- local redstoneSide = "right"
- -- Get the peripheral for the player detector, default to 'back'
- local playerDetector = peripheral.wrap("back") -- Adjust the peripheral name if needed
- -- Check if playerDetector is connected
- if not playerDetector then
- error("Player detector peripheral not found on 'back'. Please check the connection.")
- end
- -- Function to display the splash screen
- function displaySplashScreen(isPlayerOnline)
- if isPlayerOnline then
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- local screenWidth, screenHeight = term.getSize()
- local message = "Lag Reducer 3001"
- local status = targetPlayer .. " is ONLINE!"
- local x1 = math.floor((screenWidth - #message) / 2)
- local y1 = math.floor(screenHeight / 2) - 1
- local x2 = math.floor((screenWidth - #status) / 2)
- local y2 = math.floor(screenHeight / 2) + 1
- term.setCursorPos(x1, y1)
- term.write(message)
- term.setCursorPos(x2, y2)
- term.write(status)
- else
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- local screenWidth, screenHeight = term.getSize()
- local message = "Lag Reducer 3001"
- local status = targetPlayer .. " is OFFLINE."
- local x1 = math.floor((screenWidth - #message) / 2)
- local y1 = math.floor(screenHeight / 2) - 1
- local x2 = math.floor((screenWidth - #status) / 2)
- local y2 = math.floor(screenHeight / 2) + 1
- term.setCursorPos(x1, y1)
- term.write(message)
- term.setCursorPos(x2, y2)
- term.write(status)
- end
- end
- -- Function to check if the target player is online
- function checkPlayerOnline()
- -- Get a list of online players from the playerDetector peripheral
- local onlinePlayers = playerDetector.getOnlinePlayers()
- -- Check if the target player is in the list of online players
- for _, player in ipairs(onlinePlayers) do
- if player == targetPlayer then
- return true -- Player is online
- end
- end
- return false -- Player is not online
- end
- -- Function to set the redstone output based on player status
- function setRedstoneOutput(isPlayerOnline)
- if isPlayerOnline then
- redstone.setOutput(redstoneSide, true) -- Emit redstone signal
- else
- redstone.setOutput(redstoneSide, false) -- Turn off redstone signal
- end
- end
- -- Continuously check every few seconds
- while true do
- local isOnline = checkPlayerOnline() -- Check if the player is online
- displaySplashScreen(isOnline) -- Show splash screen with player's status
- setRedstoneOutput(isOnline) -- Set the redstone output accordingly
- sleep(5) -- Check every 5 seconds
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement