Piifafa
Member
- Joined
- Apr 16, 2023
- Messages
- 68
- Reaction score
- 16
I have a little chest on my server that will give an item every 16 hours, but I would like there to also be an item that is always fixed, I managed to do that but I would like the message to be shown to the player about what he received.
In my case it only shows 1 message about the first item he receives, but he always gets 2 items.
LUA:
-- Dungeon dos soldir infernal e etc, tematica de fogo.
local config = {
storage = 45395,
exstorage = 40825,
guaranteedReward = {
{itemid = 5494, count = 1}, -- Item de recompensa garantida
},
days = {
["Monday"] = {
{itemid = 3043, count = {1, 45}},
{itemid = 5495, count = {1, 7}},
{itemid = 5189, count = {1, 8}},
{itemid = 5498, count = {1}},
{itemid = 5399, count = {1}},
{itemid = 5526, count = {1, 18}}
},
["Tuesday"] = {
{itemid = 3043, count = {1, 25}},
{itemid = 5495, count = {1, 5}},
{itemid = 5189, count = {1, 6}},
{itemid = 5526, count = {1, 10}},
{itemid = 5494, count = {1}}
},
["Wednesday"] = {
{itemid = 3043, count = {1, 45}},
{itemid = 5495, count = {1, 10}},
{itemid = 5189, count = {1, 15}},
{itemid = 5494, count = {1}},
{itemid = 5498, count = {1}},
{itemid = 5526, count = {1, 10}},
{itemid = 3606, count = {1}}
},
["Thursday"] = {
{itemid = 3043, count = {1, 45}},
{itemid = 5495, count = {1, 5}},
{itemid = 5189, count = {1, 3}},
{itemid = 5498, count = {1}},
{itemid = 5399, count = {1}},
{itemid = 5494, count = {1}}
},
["Friday"] = {
{itemid = 3043, count = {1, 45}},
{itemid = 5495, count = {1, 7}},
{itemid = 5189, count = {1, 8}},
{itemid = 5494, count = {1}},
{itemid = 5498, count = {1}},
{itemid = 5526, count = {1, 15}},
{itemid = 3606, count = {1}}
},
["Saturday"] = {
{itemid = 3043, count = {1, 25}},
{itemid = 5495, count = {1, 13}},
{itemid = 5189, count = {1, 15}},
{itemid = 5526, count = {1, 15}},
{itemid = 5399, count = {1}},
{itemid = 5494, count = {1}}
},
["Sunday"] = {
{itemid = 3043, count = {1, 45}},
{itemid = 5526, count = {1, 10}},
{itemid = 5495, count = {1, 10}},
{itemid = 5189, count = {1, 10}},
{itemid = 5494, count = {1}},
{itemid = 5498, count = {1}},
{itemid = 5399, count = {1}}
}
}
}
function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
local player = Player(cid)
local x = config.days[os.date("%A")]
if player:getStorageValue(config.storage) == tonumber(os.date("%w")) and player:getStorageValue(config.exstorage) > os.time() then
return player:sendCancelMessage("The chest is empty, come back tomorrow for a new reward.")
end
-- Adiciona a recompensa garantida
for _, reward in ipairs(config.guaranteedReward) do
local itemx = Game.createItem(reward.itemid, reward.count)
if player:addItemEx(itemx) ~= RETURNVALUE_NOERROR then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have found a reward weighing " .. itemx:getWeight() .. " oz. It is too heavy or you have not enough space.")
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received " .. reward.count .. " " .. ItemType(reward.itemid):getPluralName() .. ".")
end
end
-- Adiciona os outros itens aleatórios
for _, reward in ipairs(x) do
local info, count = ItemType(reward.itemid), reward.count[2] and math.random(reward.count[1], reward.count[2]) or reward.count[1]
local itemx = Game.createItem(reward.itemid, count)
if player:addItemEx(itemx) ~= RETURNVALUE_NOERROR then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
player:setStorageValue(config.storage, tonumber(os.date("%w")))
player:setStorageValue(config.exstorage, os.time() + 16*60*60)
return true
end