• 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!

TFS 0.X Custom Reward Shrine

Paco

Member
Joined
Jan 4, 2009
Messages
139
Reaction score
27
Location
Zapotlán del Rey, Jalisco, México.
Hello, I've made this script for my server. However, it works with cooldown per day. I'm messed up, think you can help me to make this code to get a storage as real tibia does it?

I thought maybe using this function:
Lua:
function getDayName()
    local days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
    return days[os.date("*t")["wday"]]
end


But I don't know, you guys have a better idea? Here's my code:

Code:
local waitClaimedReward = 86400 -- 24 hours cooldown
local claimedReward = 280001
local days = 280002 -- storage that determines if you recieve double exp or not

local waitLock = 72000 -- 20 hours cooldown
local lock = 280003 -- storage to check if you already picked your daily reward

local config = {
    rate = 1.5, -- 50% exp rate
    time = 1, -- hours of exp time
    expBoost = 1451223 -- storage for active double exp
}
local function endExpRate(cid)
    if isPlayer(cid) == TRUE then
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate) -- config.lua rate
        setPlayerStorageValue(cid, config.expBoost, -1)
        doPlayerSendTextMessage(cid,18, "Your %50 experience time has ended.")
    end
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
 if getPlayerGroupId(cid) == 4 then
    return doPlayerSendTextMessage(cid,  18, "You do not have enough capacity to claim the reward.")
 end
 if getPlayerLevel(cid) < 8 then
    return doCreatureSay(cid, "Only players of level 8 or higher may recive a daily reward." , TALKTYPE_ORANGE_1)
 end
 if(getCreatureStorage(cid, lock) > os.time()) then -- 20 hours lock for reward
 local remainingHours = math.ceil((getCreatureStorage(cid, lock) - os.time()) / (60 * 60))
 return doCreatureSay(cid, "You need to wait ".. remainingHours .." hours to claim your daily reward.", TALKTYPE_ORANGE_1)
 end

 if(getCreatureStorage(cid, claimedReward) < os.time()) then
    setPlayerStorageValue(cid, days, 1)
    doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
    doCreatureSetStorage(cid, lock, os.time() + waitLock)
    doPlayerSendTextMessage(cid,18, "Your daily reward streak has been reseted. Use the reward shrine 7 days in a row or more to claim 1 hour of daily DOUBLE EXPERIENCE boost! Thank You for playing Rookgaard Tales!")
 end
-- level 8
if (getPlayerLevel(cid) >= 8 and getPlayerLevel(cid) < 50) then
    if(getPlayerStorageValue(cid, days) >= 1 and getCreatureStorage(cid, claimedReward) > os.time()) then
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        doCreatureSay(cid, "You have collected a daily reward." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward1 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward1,7618,5)
        doAddContainerItem(reward1,7620,5)
        doAddContainerItem(reward1,2306,5)
        doAddContainerItem(reward1,2276,5)
    end
    if(getPlayerStorageValue(cid, days) >= 7 and getCreatureStorage(cid, claimedReward) > os.time()) then
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.expBoost, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doCreatureSay(cid, "You have collected DOUBLE daily reward! You now have 50% EXPERIENCE rate. It will last for ".. config.time .." hour." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward2 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward2,7618,10)
        doAddContainerItem(reward2,7620,10)
        doAddContainerItem(reward2,2306,10)
        doAddContainerItem(reward2,2276,10)
    end
 end
-- level 50
if (getPlayerLevel(cid) >= 50 and getPlayerLevel(cid) < 80) then
    if(getPlayerStorageValue(cid, days) >= 1 and getCreatureStorage(cid, claimedReward) > os.time()) then
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        doCreatureSay(cid, "You have collected a daily reward." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward3 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward3,7588,5)
        doAddContainerItem(reward3,7589,5)
        doAddContainerItem(reward3,2268,5)
        doAddContainerItem(reward3,2300,5)
    end
    if(getPlayerStorageValue(cid, days) >= 7 and getCreatureStorage(cid, claimedReward) > os.time()) then
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.expBoost, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doCreatureSay(cid, "You have collected DOUBLE daily reward! You now have 50% EXPERIENCE rate. It will last for ".. config.time .." hour." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward4 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward4,7588,10)
        doAddContainerItem(reward4,7589,10)
        doAddContainerItem(reward4,2268,10)
        doAddContainerItem(reward4,2300,10)
        doAddContainerItem(reward7,18654,1)
    end
 end
-- level 80
if (getPlayerLevel(cid) >= 80  and getPlayerLevel(cid) < 130) then
    if(getPlayerStorageValue(cid, days) >= 1 and getCreatureStorage(cid, claimedReward) > os.time()) then
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        doCreatureSay(cid, "You have collected a daily reward." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward5 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward5,7591,5)
        doAddContainerItem(reward5,7590,5)
        doAddContainerItem(reward5,8472,5)
        doAddContainerItem(reward5,2268,5)
        doAddContainerItem(reward5,2300,5)
    end
    if(getPlayerStorageValue(cid, days) >= 7 and getCreatureStorage(cid, claimedReward) > os.time()) then
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.expBoost, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doCreatureSay(cid, "You have collected DOUBLE daily reward! You now have 50% EXPERIENCE rate. It will last for ".. config.time .." hour." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward6 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward6,7591,10)
        doAddContainerItem(reward6,7590,10)
        doAddContainerItem(reward6,8472,10)
        doAddContainerItem(reward6,2268,10)
        doAddContainerItem(reward6,2300,10)
        doAddContainerItem(reward6,18654,1)
    end
 end
-- level 130
if (getPlayerLevel(cid) >= 130 and getPlayerLevel(cid) < 200) then
    if(getPlayerStorageValue(cid, days) >= 1 and getCreatureStorage(cid, claimedReward) > os.time()) then
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        doCreatureSay(cid, "You have collected a daily reward." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward7 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward7,8473,5)
        doAddContainerItem(reward7,13982,5)
        doAddContainerItem(reward7,13983,5)
        doAddContainerItem(reward7,2268,5)
        doAddContainerItem(reward7,2300,5)
    end
    if(getPlayerStorageValue(cid, days) >= 7 and getCreatureStorage(cid, claimedReward) > os.time()) then
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.expBoost, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doCreatureSay(cid, "You have collected DOUBLE daily reward! You now have 50% EXPERIENCE rate. It will last for ".. config.time .." hour." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward8 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward8,8473,10)
        doAddContainerItem(reward8,13982,10)
        doAddContainerItem(reward8,13983,10)
        doAddContainerItem(reward8,2268,10)
        doAddContainerItem(reward8,2300,10)
        doAddContainerItem(reward8,18654,1)
    end
 end
-- level 200
if (getPlayerLevel(cid) >= 200 and getPlayerLevel(cid) < 250) then
    if(getPlayerStorageValue(cid, days) >= 1 and getCreatureStorage(cid, claimedReward) > os.time()) then
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        doCreatureSay(cid, "You have collected a daily reward." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward9 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward9,8473,5)
        doAddContainerItem(reward9,13982,5)
        doAddContainerItem(reward9,13983,5)
        doAddContainerItem(reward9,13984,5)
        doAddContainerItem(reward9,2268,5)
        doAddContainerItem(reward9,2300,5)
    end
    if(getPlayerStorageValue(cid, days) >= 7 and getCreatureStorage(cid, claimedReward) > os.time()) then
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.expBoost, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doCreatureSay(cid, "You have collected DOUBLE daily reward! You now have 50% EXPERIENCE rate. It will last for ".. config.time .." hour." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward10 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward10,8473,5)
        doAddContainerItem(reward10,13982,5)
        doAddContainerItem(reward10,13983,5)
        doAddContainerItem(reward10,13984,5)
        doAddContainerItem(reward10,2268,5)
        doAddContainerItem(reward10,2300,5)
        doAddContainerItem(reward10,18654,1)
    end
 end
-- level 250
    if getPlayerLevel(cid) >= 250 then
      if(getPlayerStorageValue(cid, days) >= 1 and getCreatureStorage(cid, claimedReward) > os.time()) then
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        doCreatureSay(cid, "You have collected a daily reward." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward11 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward11,8473,5)
        doAddContainerItem(reward11,13982,5)
        doAddContainerItem(reward11,13983,5)
        doAddContainerItem(reward11,13984,5)
        doAddContainerItem(reward11,2268,5)
        doAddContainerItem(reward11,2300,5)
    end
    if(getPlayerStorageValue(cid, days) >= 7 and getCreatureStorage(cid, claimedReward) > os.time()) then
        doCreatureSetStorage(cid, claimedReward, os.time() + waitClaimedReward)
        doCreatureSetStorage(cid, lock, os.time() + waitLock)
        setPlayerStorageValue(cid, days, getPlayerStorageValue(cid, days)  + 1)
        doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
        setPlayerStorageValue(cid, config.expBoost, os.time() + config.time * 3600)
        addEvent(endExpRate, config.time * 3600 * 1000, cid)
        doCreatureSay(cid, "You have collected DOUBLE daily reward! You now have 50% EXPERIENCE rate. It will last for ".. config.time .." hour." , TALKTYPE_ORANGE_1)
        doSendMagicEffect(toPosition, 2)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS)
        local reward12 = doPlayerAddItem(cid,20332,1)
        doAddContainerItem(reward12,8473,5)
        doAddContainerItem(reward12,13982,5)
        doAddContainerItem(reward12,13983,5)
        doAddContainerItem(reward12,13984,5)
        doAddContainerItem(reward12,2268,5)
        doAddContainerItem(reward12,2300,5)
        doAddContainerItem(reward12,18654,1)
    end
 end

return TRUE
end

I have no idea how real tibia works, but the guys at server say u get ur storage per day and stacks to get better reward if u keep loggin in. I haven't played real tibia in years xD

Thank You guys!
 
I don't know if you're asking about this or not, but this script gives a different reward every day

Lua:
local config = {
    storage = 45392,
    exstorage = 40822,
    ["Monday"] = {
        {itemid = 25377, count = math.random(1, 2)}
    },
    ["Tuesday"] = {
        {itemid = 26029, count = math.random(25, 100)},
        {itemid = 8473, count = math.random(25, 100)},
        {itemid = 26030, count = math.random(25, 100)}
    },
    ["Wednesday"] = {
        {itemid = 22396, count = 1},
        {itemid = 22397, count = 1}
    },
    ["Thursday"] = {
        {itemid = 25377, count = math.random(1, 2)}
    },
    ["Friday"] = {
        {itemid = 25172, count = math.random(1, 10)}
    },
    ["Saturday"] = {
        {itemid = 24774, count = math.random(1, 5)}
    },
    ["Sunday"] = {
        {itemid = 9933, count = 1}
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local currentDay = os.date('%A')
    local days = config[currentDay]

    if getPlayerStorageValue(cid, config.storage) == tonumber(os.date("%w")) and getPlayerStorageValue(cid, config.exstorage) > os.time() then
        return doCreatureSay(cid, "The chest is empty, come back tomorrow for a new reward.", TALKTYPE_ORANGE_1)
    end

    for _, reward in ipairs(days) do
        local info, count = reward.itemid, reward.count
        local itemName = getItemInfo(info).name

        if count >= 1 then
            text = count .. " " .. itemName
        else
            text = getItemArticleById(info) .. " " .. itemName
        end

        local itemx = doCreateItemEx(info, count)
        if doPlayerAddItemEx(cid, itemx) ~= RETURNVALUE_NOERROR then
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
            local weight = math.floor(getItemInfo(info).weight * count)
            text = "You have found a reward weighing " ..weight .. " oz. It is too heavy or you do not have enough space."
            else
                text = "You have received " .. text .. "."
                setPlayerStorageValue(cid, config.storage, tonumber(os.date("%w")))
                setPlayerStorageValue(cid, config.exstorage, os.time() + 24 * 60 * 60)
            end

            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
        end

        return true
    end
 
I don't know if you're asking about this or not, but this script gives a different reward every day

Lua:
local config = {
    storage = 45392,
    exstorage = 40822,
    ["Monday"] = {
        {itemid = 25377, count = math.random(1, 2)}
    },
    ["Tuesday"] = {
        {itemid = 26029, count = math.random(25, 100)},
        {itemid = 8473, count = math.random(25, 100)},
        {itemid = 26030, count = math.random(25, 100)}
    },
    ["Wednesday"] = {
        {itemid = 22396, count = 1},
        {itemid = 22397, count = 1}
    },
    ["Thursday"] = {
        {itemid = 25377, count = math.random(1, 2)}
    },
    ["Friday"] = {
        {itemid = 25172, count = math.random(1, 10)}
    },
    ["Saturday"] = {
        {itemid = 24774, count = math.random(1, 5)}
    },
    ["Sunday"] = {
        {itemid = 9933, count = 1}
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local currentDay = os.date('%A')
    local days = config[currentDay]

    if getPlayerStorageValue(cid, config.storage) == tonumber(os.date("%w")) and getPlayerStorageValue(cid, config.exstorage) > os.time() then
        return doCreatureSay(cid, "The chest is empty, come back tomorrow for a new reward.", TALKTYPE_ORANGE_1)
    end

    for _, reward in ipairs(days) do
        local info, count = reward.itemid, reward.count
        local itemName = getItemInfo(info).name

        if count >= 1 then
            text = count .. " " .. itemName
        else
            text = getItemArticleById(info) .. " " .. itemName
        end

        local itemx = doCreateItemEx(info, count)
        if doPlayerAddItemEx(cid, itemx) ~= RETURNVALUE_NOERROR then
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
            local weight = math.floor(getItemInfo(info).weight * count)
            text = "You have found a reward weighing " ..weight .. " oz. It is too heavy or you do not have enough space."
            else
                text = "You have received " .. text .. "."
                setPlayerStorageValue(cid, config.storage, tonumber(os.date("%w")))
                setPlayerStorageValue(cid, config.exstorage, os.time() + 24 * 60 * 60)
            end

            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
        end

        return true
    end
There's a way to split reward by vocation?
 
There's a way to split reward by vocation?
not tested but should work good
test and tell me if there error
Lua:
local config = {
    storage = 45392,
    exstorage = 40822,
    ["Monday"] = {
        {itemid = 26029, count = math.random(25, 100), vocations = {1,5,9}},
        {itemid = 8473, count = math.random(25, 100), vocations = {2,6,10}},
        {itemid = 26030, count = math.random(25, 100), vocations = {3,7,11}},
        {itemid = 2157, count = math.random(25, 100), vocations = {4,8,12}}
    },
    ["Tuesday"] = {
        {itemid = 26029, count = math.random(25, 100), vocations = {1,5,9}},
        {itemid = 8473, count = math.random(25, 100), vocations = {2,6,10}},
        {itemid = 26030, count = math.random(25, 100), vocations = {3,7,11}},
        {itemid = 2157, count = math.random(25, 100), vocations = {4,8,12}}
    },
    ["Wednesday"] = {
        {itemid = 26029, count = math.random(25, 100), vocations = {1,5,9}},
        {itemid = 8473, count = math.random(25, 100), vocations = {2,6,10}},
        {itemid = 26030, count = math.random(25, 100), vocations = {3,7,11}},
        {itemid = 2157, count = math.random(25, 100), vocations = {4,8,12}}
    },
    ["Thursday"] = {
        {itemid = 26029, count = math.random(25, 100), vocations = {1,5,9}},
        {itemid = 8473, count = math.random(25, 100), vocations = {2,6,10}},
        {itemid = 26030, count = math.random(25, 100), vocations = {3,7,11}},
        {itemid = 2157, count = math.random(25, 100), vocations = {4,8,12}}
    },
    ["Friday"] = {
        {itemid = 26029, count = math.random(25, 100), vocations = {1,5,9}},
        {itemid = 8473, count = math.random(25, 100), vocations = {2,6,10}},
        {itemid = 26030, count = math.random(25, 100), vocations = {3,7,11}},
        {itemid = 2157, count = math.random(25, 100), vocations = {4,8,12}}
    },
    ["Saturday"] = {
        {itemid = 26029, count = math.random(25, 100), vocations = {1,5,9}},
        {itemid = 8473, count = math.random(25, 100), vocations = {2,6,10}},
        {itemid = 26030, count = math.random(25, 100), vocations = {3,7,11}},
        {itemid = 2157, count = math.random(25, 100), vocations = {4,8,12}}
    },
    ["Sunday"] = {
        {itemid = 26029, count = math.random(25, 100), vocations = {1,5,9}},
        {itemid = 8473, count = math.random(25, 100), vocations = {2,6,10}},
        {itemid = 26030, count = math.random(25, 100), vocations = {3,7,11}},
        {itemid = 2157, count = math.random(25, 100), vocations = {4,8,12}}
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local currentDay = os.date('%A')
    local days = config[currentDay]

    if getPlayerStorageValue(cid, config.storage) == tonumber(os.date("%w")) and getPlayerStorageValue(cid, config.exstorage) > os.time() then
        return doCreatureSay(cid, "The chest is empty, come back tomorrow for a new reward.", TALKTYPE_ORANGE_1)
    end

    for _, reward in ipairs(days) do
        local info, count = reward.itemid, reward.count
        local itemName = getItemInfo(info).name

        if count >= 1 then
            text = count .. " " .. itemName
        else
            text = getItemArticleById(info) .. " " .. itemName
        end

        local vocationMatch = false
        for _, vocationID in ipairs(reward.vocations) do
            if getPlayerVocation(cid) == vocationID then
                vocationMatch = true
                break
            end
        end

        if vocationMatch then
            local itemx = doCreateItemEx(info, count)
            if doPlayerAddItemEx(cid, itemx) ~= RETURNVALUE_NOERROR then
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                local weight = math.floor(getItemInfo(info).weight * count)
                text = "You have found a reward weighing " .. weight .. " oz. It is too heavy or you do not have enough space."
                else
                    text = "You have received " .. text .. "."
                    setPlayerStorageValue(cid, config.storage, tonumber(os.date("%w")))
                    setPlayerStorageValue(cid, config.exstorage, os.time() + 24 * 60 * 60)
                end

                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
                return true
            end
        end
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There is no reward available for your vocation today.")
        return true
    end
 
I don't know if you're asking about this or not, but this script gives a different reward every day

Lua:
local config = {
    storage = 45392,
    exstorage = 40822,
    ["Monday"] = {
        {itemid = 25377, count = math.random(1, 2)}
    },
    ["Tuesday"] = {
        {itemid = 26029, count = math.random(25, 100)},
        {itemid = 8473, count = math.random(25, 100)},
        {itemid = 26030, count = math.random(25, 100)}
    },
    ["Wednesday"] = {
        {itemid = 22396, count = 1},
        {itemid = 22397, count = 1}
    },
    ["Thursday"] = {
        {itemid = 25377, count = math.random(1, 2)}
    },
    ["Friday"] = {
        {itemid = 25172, count = math.random(1, 10)}
    },
    ["Saturday"] = {
        {itemid = 24774, count = math.random(1, 5)}
    },
    ["Sunday"] = {
        {itemid = 9933, count = 1}
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local currentDay = os.date('%A')
    local days = config[currentDay]

    if getPlayerStorageValue(cid, config.storage) == tonumber(os.date("%w")) and getPlayerStorageValue(cid, config.exstorage) > os.time() then
        return doCreatureSay(cid, "The chest is empty, come back tomorrow for a new reward.", TALKTYPE_ORANGE_1)
    end

    for _, reward in ipairs(days) do
        local info, count = reward.itemid, reward.count
        local itemName = getItemInfo(info).name

        if count >= 1 then
            text = count .. " " .. itemName
        else
            text = getItemArticleById(info) .. " " .. itemName
        end

        local itemx = doCreateItemEx(info, count)
        if doPlayerAddItemEx(cid, itemx) ~= RETURNVALUE_NOERROR then
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
            local weight = math.floor(getItemInfo(info).weight * count)
            text = "You have found a reward weighing " ..weight .. " oz. It is too heavy or you do not have enough space."
            else
                text = "You have received " .. text .. "."
                setPlayerStorageValue(cid, config.storage, tonumber(os.date("%w")))
                setPlayerStorageValue(cid, config.exstorage, os.time() + 24 * 60 * 60)
            end

            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
        end

        return true
    end
Looks nice but... I'm just looking for a way to have cooldown per day for my original script. Also stack another storage, if players get reward all days in a row, they get double reward.
 
Looks nice but... I'm just looking for a way to have cooldown per day for my original script. Also stack another storage, if players get reward all days in a row, they get double reward.
Hypothesis:
1- You will have one global storage (server), let's say it is 777.
2- Each player will have two storages, let's say: 888 for the last reward and 999 for the sequence of days.
3- Every time the server starts up, you will set storage 777 to os.time.
4- When a player claims the reward, you will check:
4.1- if player's storage 888 is bigger then 777, then this players already tooks today reward.
4.2- If player's storage 888 + 24h is lesser than 777, then they have lost the sequence of days. Storage 999 will be set to 1.
4.3- If player's storage 888 + 24h is greater than the value of 777, then they are in a sequence of days. Storage 999 will be set to the current value of storage 999 + 1.
5- After the player claims the reward, storage 888 will be set to os.time.

make sure to verify, if storage value == -1, then it's treated as 0
 
Last edited:

Similar threads

Back
Top