local config = {
actionid = 2550,
male = {128, 139},
female = {126, 138},
crystalCoin = 2160
}
local Addonchest = Action()
function Addonchest.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local lastOpened = player:getStorageValue(Storage.ChanceStorage) -- Storing the last chest opening time
local currentTime = os.time() -- Getting the current time in seconds
if (lastOpened == -1 or currentTime >= lastOpened + 20 * 60 * 60) then -- Checking if 20 hours have passed since last opening
player:setStorageValue(Storage.ChanceStorage, currentTime) -- Updating latest opening times
local maleoutfit = config.male -- List of male outfits IDs
local femaleoutfit = config.female -- List of female outfits IDs
local chance = math.random(1, 100)-- Generating a random number from 1 to 100
if (chance <= 10) then
if player:getSex() == PLAYERSEX_MALE then
local randomMaleCloth = maleoutfit[math.random(1, #maleoutfit)]
if not player:hasOutfit(randomMaleCloth) then
player:addOutfit(randomMaleCloth)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You found a male outfit in the trunk!")
end
elseif player:getSex() == PLAYERSEX_FEMALE then
local randomFemaleCloth = femaleoutfit[math.random(1, #femaleoutfit)]
if not player:hasOutfit(randomFemaleCloth) then
player:addOutfit(randomFemaleCloth)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You found a female outfit in the trunk!")
end
end
else
local crystalCoins = math.random(1, 100)
player:addItem(config.crystalCoin, crystalCoins)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You found crystal coins in the chest!")
end
else
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You've already opened the chest recently. Wait a little longer.")
end
return true
end
Addonchest:aid(config.actionid) -- the item is a bau
Addonchest:register() -- this is our footer, it has to be the last function executed