• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

RevScripts Addon chest with math random

Belfahar

New Member
Joined
Jul 21, 2016
Messages
25
Reaction score
3
Hello everyone, how are you?

I'm looking for a script where the player can click on a chest every 20 hours.In this chest he has a 10% chance of getting an outfit and a 90% chance of getting crystal coins.

Does anyone know how to do it for Canary?
 
not tested.
If an error appears in the console, go ahead and correct it yourself, it's not difficult.


Lua:
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
 
Last edited:
Back
Top