Update 'player-sensor/ligma.lua'

This commit is contained in:
Jan 2021-12-25 16:04:08 +00:00
parent 4f6434d16e
commit 1634a232c5

View file

@ -1,17 +1,15 @@
-- Configuration
local WH_URL = "https://discord.com/api/webhooks/id/token" local WH_URL = "https://discord.com/api/webhooks/id/token"
local IGNORE = { "player1", "player2" } -- case sensitive local IGNORE = { "player1", "player2" }
local DIMENSION = "minecraft:overworld" -- dimension the area is in local DIMENSION = "minecraft:overworld"
local AREA = { -- The cubic area to monitor for players local AREA = {
[0] = { x = 100, y = 0, z = 200 }, -- Position 1 [0] = { x = 100, y = 0, z = 200 },
[1] = { x = 200, y = 200, z = 300 } -- Position 2 [1] = { x = 200, y = 200, z = 300 }
} }
local REDSTONE_SIDE = "right" -- pulse a redstone signal to this side whenever a player is detected local REDSTONE_SIDE = "front"
local MODEM_PORT = 12345
-- End of configuration local modem = peripheral.wrap("back")
local sensor = peripheral.find("playerDetector") local sensor = peripheral.find("playerDetector")
local chatbox = peripheral.find("chatBox")
local KNOWN_PLAYERS = {} local KNOWN_PLAYERS = {}
local COOLDOWNS = {} local COOLDOWNS = {}
local COOLDOWN = 0.1 local COOLDOWN = 0.1
@ -23,6 +21,10 @@ function sendWhMessage(msg)
{ ["Content-Type"] = "application/json" }) { ["Content-Type"] = "application/json" })
end end
function modemMessage(msg)
modem.transmit(MODEM_PORT, MODEM_PORT + 1, msg)
end
function findPlayers() function findPlayers()
local players = sensor.getPlayersInCoords(AREA[0], AREA[1]) local players = sensor.getPlayersInCoords(AREA[0], AREA[1])
return players return players
@ -40,12 +42,6 @@ function isInArr(arr, val)
return false return false
end end
function bell()
redstone.setOutput(REDSTONE_SIDE, true)
sleep(0.1)
redstone.setOutput(REDSTONE_SIDE, false)
end
function timestamp() function timestamp()
return (os.day() * 24) + os.time() return (os.day() * 24) + os.time()
end end
@ -64,6 +60,10 @@ function isIgnore(player)
return isInArr(IGNORE, player) ~= false return isInArr(IGNORE, player) ~= false
end end
function randomRound(num)
return num + math.random(-5, 5)
end
while true do while true do
local found = findPlayers() 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 if pos ~= nil and pos.dimension == DIMENSION and not inArr and not isCooldown(v) and not isIgnore(v) then
setCooldown(v) setCooldown(v)
print("Player "..v.." entered area") print("Player "..v.." entered area")
bell()
sendWhMessage("Player `"..v.."` entered area ".. sendWhMessage("Player `"..v.."` entered area "..
"at `"..pos.x..","..pos.y..","..pos.z.."`.") "at `"..pos.x..","..pos.y..","..pos.z.."`.")
table.insert(KNOWN_PLAYERS, v) 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
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 if pos ~= nil and (not isInArr(found, v) or pos.dimension ~= DIMENSION) and not isCooldown(v) and not isIgnore(v) then
setCooldown(v) setCooldown(v)
print("Player "..v.." left area") print("Player "..v.." left area")
bell()
sendWhMessage("Player `"..v.."` left area at `".. sendWhMessage("Player `"..v.."` left area at `"..
pos.x..","..pos.y..","..pos.z.."`.") pos.x..","..pos.y..","..pos.z.."`.")
table.remove(KNOWN_PLAYERS, isInArr(KNOWN_PLAYERS, v)) table.remove(KNOWN_PLAYERS, isInArr(KNOWN_PLAYERS, v))
modemMessage(v.." left at "..randomRound(pos.x)
..","..randomRound(pos.y)..","
..randomRound(pos.z))
end end
end end
end end