From 1634a232c59a490b562c90ac0ca7bea557fdbaea Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 25 Dec 2021 16:04:08 +0000 Subject: [PATCH] Update 'player-sensor/ligma.lua' --- player-sensor/ligma.lua | 47 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/player-sensor/ligma.lua b/player-sensor/ligma.lua index efab9ec..fb6afd4 100644 --- a/player-sensor/ligma.lua +++ b/player-sensor/ligma.lua @@ -1,17 +1,15 @@ --- Configuration - local WH_URL = "https://discord.com/api/webhooks/id/token" -local IGNORE = { "player1", "player2" } -- case sensitive -local DIMENSION = "minecraft:overworld" -- dimension the area is in -local AREA = { -- The cubic area to monitor for players - [0] = { x = 100, y = 0, z = 200 }, -- Position 1 - [1] = { x = 200, y = 200, z = 300 } -- Position 2 +local IGNORE = { "player1", "player2" } +local DIMENSION = "minecraft:overworld" +local AREA = { + [0] = { x = 100, y = 0, z = 200 }, + [1] = { x = 200, y = 200, z = 300 } } -local REDSTONE_SIDE = "right" -- pulse a redstone signal to this side whenever a player is detected - --- End of configuration - +local REDSTONE_SIDE = "front" +local MODEM_PORT = 12345 +local modem = peripheral.wrap("back") local sensor = peripheral.find("playerDetector") +local chatbox = peripheral.find("chatBox") local KNOWN_PLAYERS = {} local COOLDOWNS = {} local COOLDOWN = 0.1 @@ -23,6 +21,10 @@ function sendWhMessage(msg) { ["Content-Type"] = "application/json" }) end +function modemMessage(msg) + modem.transmit(MODEM_PORT, MODEM_PORT + 1, msg) +end + function findPlayers() local players = sensor.getPlayersInCoords(AREA[0], AREA[1]) return players @@ -40,12 +42,6 @@ function isInArr(arr, val) return false end -function bell() - redstone.setOutput(REDSTONE_SIDE, true) - sleep(0.1) - redstone.setOutput(REDSTONE_SIDE, false) -end - function timestamp() return (os.day() * 24) + os.time() end @@ -64,6 +60,10 @@ function isIgnore(player) return isInArr(IGNORE, player) ~= false end +function randomRound(num) + return num + math.random(-5, 5) +end + while true do local found = findPlayers() @@ -75,11 +75,17 @@ while true do if pos ~= nil and pos.dimension == DIMENSION and not inArr and not isCooldown(v) and not isIgnore(v) then setCooldown(v) print("Player "..v.." entered area") - bell() + sendWhMessage("Player `"..v.."` entered area ".. "at `"..pos.x..","..pos.y..","..pos.z.."`.") table.insert(KNOWN_PLAYERS, v) + + chatbox.sendMessageToPlayer("You have entered a restricted area. Leave now if you value your balls.", v, "FSF") + + modemMessage(v.." entered at "..randomRound(pos.x) + ..","..randomRound(pos.y)..",".. + randomRound(pos.z)) end end @@ -89,10 +95,13 @@ while true do if pos ~= nil and (not isInArr(found, v) or pos.dimension ~= DIMENSION) and not isCooldown(v) and not isIgnore(v) then setCooldown(v) print("Player "..v.." left area") - bell() sendWhMessage("Player `"..v.."` left area at `".. pos.x..","..pos.y..","..pos.z.."`.") table.remove(KNOWN_PLAYERS, isInArr(KNOWN_PLAYERS, v)) + + modemMessage(v.." left at "..randomRound(pos.x) + ..","..randomRound(pos.y).."," + ..randomRound(pos.z)) end end end