0% found this document useful (0 votes)
24 views4 pages

Alerta Plunder - Lua

The document is a Lua script designed for a game, which includes configurations for sound alerts based on various in-game events such as low capacity, low supply of items, and player presence. It sets up a user interface (HUD) to display alert statuses and allows toggling of these alerts. Additionally, it incorporates timers to check conditions and play corresponding alert sounds when specific criteria are met.

Uploaded by

mszaumfortao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

Alerta Plunder - Lua

The document is a Lua script designed for a game, which includes configurations for sound alerts based on various in-game events such as low capacity, low supply of items, and player presence. It sets up a user interface (HUD) to display alert statuses and allows toggling of these alerts. Additionally, it incorporates timers to check conditions and play corresponding alert sounds when specific criteria are met.

Uploaded by

mszaumfortao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

-- Autor: @Leozaow 🧙

-- Para mais scripts free: https://discord.gg/zQGKqnc93w

local soundsFolder = Engine.getScriptsDirectory() .. "/Sounds/"

local alertConfig = {
lowCap = { file = 'LowCap.wav', interval = 5 },
lowSupply = { file = 'LowSupply.wav', interval = 5 },
fullDusts = { file = 'FullDusts.wav', interval = 5 },
patriarch = { file = 'Patriarch.wav', interval = 5 },
unjustified = { file = 'Unjustified.wav', interval = 5 },
player = { file = 'PlayerOnScreen.wav', interval = 5 }
}

local scriptActivationConfig = {

Plunder = true,
}

local MinCapacityConfig = 500

local supplyConfig = {
--runes
{ ItemId = 3155, Quantity = 100, Active = false, Name = "Sudden Death Rune" },
{ ItemId = 3161, Quantity = 100, Active = false, Name = "Avalanche Rune" },
{ ItemId = 3191, Quantity = 100, Active = false, Name = "Great Fireball
Rune" },
{ ItemId = 3175, Quantity = 100, Active = false, Name = "Stone Shower Rune" },
{ ItemId = 3202, Quantity = 100, Active = false, Name = "Thunderstorm Rune" },
{ ItemId = 3192, Quantity = 100, Active = false, Name = "Fire Bomb Rune" },
{ ItemId = 3149, Quantity = 100, Active = false, Name = "Energy Bomb Rune" },
{ ItemId = 3173, Quantity = 100, Active = false, Name = "Poison Bomb Rune" },
{ ItemId = 3160, Quantity = 100, Active = false, Name = "Ultimate Healing Rune"
},
{ ItemId = 3156, Quantity = 100, Active = false, Name = "Wild Growth Rune" },
{ ItemId = 3180, Quantity = 100, Active = false, Name = "Magic Wall Rune" },
--mana
{ ItemId = 23373, Quantity = 100, Active = false, Name = "Ultimate Mana Potion"
},
{ ItemId = 23374, Quantity = 100, Active = false, Name = "Ultimate Spirit
Potion" },
{ ItemId = 237, Quantity = 100, Active = false, Name = "Strong Mana Potion" },
--health
{ ItemId = 23375, Quantity = 100, Active = false, Name = "Supreme Health
Potion" },
--arrow
{ ItemId = 35901, Quantity = 100, Active = false, Name = "Diamond Arrow" }
}

local ignoreSkullGreen = true


local ignoreSameGuild = true

local COR_ATIVO = { r = 0, g = 255, b = 0 }


local COR_INATIVO = { r = 255, g = 0, b = 0 }
local COR_NEUTRA = { r = 255, g = 255, b = 255 }

local SPACE = 30
local STARTING_POSITION = { x = 30, y = 540 }
local UPDATE_HUD_FRAMERATE = 50
local function toggleAlertStatus(alertType)
scriptActivationConfig[alertType] = not scriptActivationConfig[alertType]
end

local function changeHUDColorBasedOnStatus(hud, status)


if status then
hud:setColor(COR_ATIVO.r, COR_ATIVO.g, COR_ATIVO.b)
else
hud:setColor(COR_INATIVO.r, COR_INATIVO.g, COR_INATIVO.b)
end
end

local draggerHUD = HUD(STARTING_POSITION.x, STARTING_POSITION.y, "", true)


draggerHUD:setColor(COR_NEUTRA.r, COR_NEUTRA.g, COR_NEUTRA.b)
draggerHUD:setDraggable(false)

local alertHUDs = {}

local function createAlertHUDs()


local yPos = STARTING_POSITION.y + SPACE
for alertType, config in pairs(scriptActivationConfig) do

local alertHUD = HUD(STARTING_POSITION.x, yPos, alertType .. " (" ..


(config and "ON" or "OFF") .. ")", true)
alertHUD:setCallback(function() toggleAlertStatus(alertType) end)
changeHUDColorBasedOnStatus(alertHUD, config)
yPos = yPos + SPACE

alertHUDs[alertType] = alertHUD
end
end

createAlertHUDs()

Timer("updateHUDs", function()
for alertType, hud in pairs(alertHUDs) do
if scriptActivationConfig[alertType] ~= nil then
local status = scriptActivationConfig[alertType]
hud:setText(alertType .. " (" .. (status and "ON" or "OFF") .. ")")
changeHUDColorBasedOnStatus(hud, status)
end
end
end, UPDATE_HUD_FRAMERATE)

local lastPlayedTimes = {}

local function playAlertSound(alertType)


local currentTime = os.clock()
if not lastPlayedTimes[alertType] or currentTime - lastPlayedTimes[alertType]
>= alertConfig[alertType].interval then
Sound.play(soundsFolder .. alertConfig[alertType].file)
lastPlayedTimes[alertType] = currentTime
end
end

local function checkAlerts()


local cap = Player.getCapacity()
if cap < MinCapacityConfig * 100 and scriptActivationConfig.lowCap then
playAlertSound('lowCap')
end

for _, itemData in ipairs(supplyConfig) do


if itemData.Active and scriptActivationConfig.lowSupply then
local itemQuantity = Game.getItemCount(itemData.ItemId)
if itemQuantity < itemData.Quantity then
playAlertSound('lowSupply')
break
end
end
end

local players = Map.getCreatureIds(true, true)


if players then
for _, playerId in ipairs(players) do
local player = Creature(playerId)
local shouldIgnore = (ignoreSkullGreen and player:getSkull() ==
Enums.Skulls.SKULL_GREEN) or
(ignoreSameGuild and player:getGuildEmblem() ==
Enums.GuildEmblem.GUILDEMBLEM_MEMBER)
if not shouldIgnore and player:getId() ~= Player.getId() and
scriptActivationConfig.playerOnScreen then
playAlertSound('player')
break
end
end
end

local creatures = Map.getCreatureIds(true, false)


if creatures then
for _, creatureId in ipairs(creatures) do
local creature = Creature(creatureId)
if creature then
local creatureType = creature:getType()
local creatureName = creature:getName()

if creatureType and creatureName and creatureType ==


Enums.CreatureTypes.CREATURETYPE_MONSTER and scriptActivationConfig.Plunder then
if creatureName:lower() == "plunder patriarch" then
playAlertSound('patriarch')
break
end
end
end
end
end
end

local function onTextMessage(messageData)


local dustValue1, dustValue2 = string.match(messageData.text, "dust value is:
(%d+)/(%d+)")
if not dustValue1 or not dustValue2 then
dustValue1, dustValue2 = string.match(messageData.text, "now have (%d+) out
of a maximum of (%d+) dusts")
end
if dustValue1 and dustValue2 and tonumber(dustValue1) >= tonumber(dustValue2)
then
if scriptActivationConfig.fullDusts then
playAlertSound('fullDusts')
end
elseif string.match(messageData.text, "because you have already reached the
maximum") then
if scriptActivationConfig.fullDusts then
playAlertSound('fullDusts')
end
end

if string.match(messageData.text, "murder of (.+) was not justified") and


scriptActivationConfig.unjustified then
playAlertSound('unjustified')
end
end

Game.registerEvent(Game.Events.TEXT_MESSAGE, onTextMessage)

Timer("alerts", checkAlerts, 50)

You might also like