Hello, I have a problem with the daily boss chest. When I try to make the rewards appear in a bag, it suddenly stops assigning any rewards at all. This chest is supposed to give random rewards.
Additionally, an error message appears in the console:

LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- KONFIGURACJA
local CHEST_UID = 5802
local CHEST_COOLDOWN = 86400 -- 24h w sekundach
local CHEST_STORAGE = 40001 -- Storage do zapisu czasu ostatniego użycia
local BAG_ID = 1987 -- ID torby (sprawdź czy 1987 to faktycznie bag w Twoim items.xml)
-- Pula nagród z procentową szansą (w "promilach", np. 2000 = 20%)
local possibleRewards = {
{itemId = 2169, minCount = 1, maxCount = 1, name = "Ring of Healing", chance = 5000}, -- 5%
{itemId = 2148, minCount = 50, maxCount = 100, name = "Gold Coins", chance = 5000}, -- 40%
{itemId = 2152, minCount = 2, maxCount = 5, name = "Platinum Coins", chance = 5000}, -- 20%
{itemId = 7620, minCount = 1, maxCount = 3, name = "Mana Potions", chance = 5000}, -- 20%
{itemId = 7588, minCount = 1, maxCount = 2, name = "Strong Health Potions", chance = 5000} -- 15%
}
-- Funkcja do wylosowania JEDNEGO przedmiotu z puli (wg pola 'chance')
local function getRandomReward()
local totalChance = 0
for _, reward in ipairs(possibleRewards) do
totalChance = totalChance + reward.chance
end
local roll = math.random(1, totalChance)
local runningSum = 0
for _, reward in ipairs(possibleRewards) do
runningSum = runningSum + reward.chance
if roll <= runningSum then
local count = math.random(reward.minCount, reward.maxCount)
return reward.itemId, count, reward.name
end
end
-- Zapasowo, gdyby nic się nie wylosowało (teoretycznie niemożliwe):
return 2148, 1, "Gold Coin"
end
-- Sprawdzamy, czy to właściwy UID skrzyni
if item.uid == CHEST_UID then
local lastUse = player:getStorageValue(CHEST_STORAGE)
if lastUse < 1 then
lastUse = 0
end
local timeSinceLast = os.time() - lastUse
if timeSinceLast < CHEST_COOLDOWN then
local timeLeft = CHEST_COOLDOWN - timeSinceLast
player:sendTextMessage(MESSAGE_INFO_DESCR,
string.format("You have to wait %d seconds to open this chest again.", timeLeft))
return true
end
-- Próba dodania do ekwipunku torby (bag)
local bag = player:addItem(BAG_ID, 1)
if not bag then
player:sendTextMessage(MESSAGE_STATUS_WARNING,
"You don't have enough capacity to receive the bag.")
return true
end
-- Sprawdzamy, czy jest kontenerem
if not bag:isContainer() then
player:sendTextMessage(MESSAGE_STATUS_WARNING,
"The item ID " .. BAG_ID .. " is not recognized as a container.")
return true
end
local container = bag:getContainer()
if not container then
player:sendTextMessage(MESSAGE_STATUS_WARNING,
"Unexpected error: cannot open bag container in script.")
return true
end
-- Losujemy JEDEN przedmiot i dodajemy go do torby
local itemId, itemCount, itemName = getRandomReward()
container:addItem(itemId, itemCount)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE,
string.format("You have found a bag containing %dx %s.", itemCount, itemName))
-- Ustawiamy timestamp w storage, by naliczyć cooldown 24h
player:setStorageValue(CHEST_STORAGE, os.time())
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There is nothing here.")
end
return true
end
Additionally, an error message appears in the console:
