Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DiscordHook = require("DiscordHook")
- local speaker = peripheral.find("speaker")
- local detector = peripheral.find("playerDetector")
- local playersInBase = {}
- if speaker == nil then
- error("Aucun 'speaker' détecté")
- return
- end
- if detector == nil then
- error("Aucun 'playerDetector' détecté")
- return
- end
- -- Fonction pour échapper les caractères spéciaux dans le pseudo
- local function escapeUsername(playerName)
- -- Liste des caractères spéciaux à échapper dans Discord
- local specialChars = {"*", "_", "~", "`", "|"}
- local escapedName = playerName
- -- Remplacer chaque caractère spécial par son équivalent échappé
- for _, char in ipairs(specialChars) do
- escapedName = escapedName:gsub(char, "\\" .. char)
- end
- return escapedName
- end
- local function isPlayerInBase(playerName)
- for _, name in ipairs(playersInBase) do
- if name == playerName then
- return true
- end
- end
- return false
- end
- local function isPlayerInList(player, list)
- for _, name in ipairs(list) do
- if name == player then
- return true
- end
- end
- return false
- end
- local function removeFromList(list, player)
- for i, name in ipairs(list) do
- if name == player then
- table.remove(list, i)
- return
- end
- end
- end
- local function detectNewPlayers()
- local players = detector.getPlayersInRange(200)
- local playersToRemove = {}
- for _, player in ipairs(playersInBase) do
- if not isPlayerInList(player, players) then
- table.insert(playersToRemove, player)
- end
- end
- for _, player in ipairs(playersToRemove) do
- removeFromList(playersInBase, player)
- print(string.format("%s a quitté la base", player))
- local success, hook = DiscordHook.createWebhook("https://discord.com/api/webhooks/1254412774172393482/yp196njdT93B7z8FO2KbykMj6bmad-kHpXE5OgH7Ta_xHqfU_UnimQOM91TlF1dgeFtn")
- if not success then
- error("Webhook connection failed! Reason: " .. hook)
- end
- if success then
- local message = string.format("TsykiBase> %s a quitté la base", escapeUsername(player))
- hook.send(message, "Server")
- end
- end
- if players and #players > 0 then
- for _, player in ipairs(players) do
- if not isPlayerInBase(player) then
- table.insert(playersInBase, player)
- print(string.format("%s a rejoint la base", player))
- speaker.playNote("harp", 1, 1)
- local success, hook = DiscordHook.createWebhook("https://discord.com/api/webhooks/1254412774172393482/yp196njdT93B7z8FO2KbykMj6bmad-kHpXE5OgH7Ta_xHqfU_UnimQOM91TlF1dgeFtn")
- if not success then
- error("Webhook connection failed! Reason: " .. hook)
- end
- if success then
- local message = string.format("TsykiBase> %s a rejoint la base", escapeUsername(player))
- hook.send(message, "Server")
- end
- end
- end
- end
- end
- while true do
- detectNewPlayers()
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement