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

Lua [TFS 0.X] Boss Room - Chance Reward every 24h

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,402
Solutions
17
Reaction score
150
Location
Brazil
Good afternoon guys, how are you?

I have a boss room that works well, but I wanted to customize one thing: a reward chest that the player can use every 24 hours, which can give 10 different items, each with a specific chance. Could you help me create this script?
 
Solution
I need to put an array of 10 itens with chance too, i have the entrance and tp system done
Lua:
local storage = 1000 -- change this value
local cooldown = 24 -- hours
local effect = CONST_ME_MAGIC_BLUE
local items = {
    { itemId = 2160, itemCount = 1, itemChance = 50 },
    { itemId = 2160, itemCount = 1, itemChance = true }, -- set itemChance = true for 100%
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local storageValue = getCreatureStorage(cid, storage)
    if storageValue - os.time() >= 1 then
        doPlayerSendTextMessage(cid, MSG_STATUS_SMALL, "You have received this reward, must wait.")
        return true
    end

    local tmp = {}
    for i = 1, #items do
        local chance =...
Good afternoon guys, how are you?

I have a boss room that works well, but I wanted to customize one thing: a reward chest that the player can use every 24 hours, which can give 10 different items, each with a specific chance. Could you help me create this script?
Post your script or simply use
Lua:
getPlayerStorageValue(cid, STORAGE NUMBER) <= os.time() then

setPlayerStorageValue(cid, STORAGE NUMBER, os.time() + 24 * 60 * 60)
 
Post your script or simply use
Lua:
getPlayerStorageValue(cid, STORAGE NUMBER) <= os.time() then

setPlayerStorageValue(cid, STORAGE NUMBER, os.time() + 24 * 60 * 60)
I need to put an array of 10 itens with chance too, i have the entrance and tp system done
 
I need to put an array of 10 itens with chance too, i have the entrance and tp system done
Lua:
local storage = 1000 -- change this value
local cooldown = 24 -- hours
local effect = CONST_ME_MAGIC_BLUE
local items = {
    { itemId = 2160, itemCount = 1, itemChance = 50 },
    { itemId = 2160, itemCount = 1, itemChance = true }, -- set itemChance = true for 100%
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local storageValue = getCreatureStorage(cid, storage)
    if storageValue - os.time() >= 1 then
        doPlayerSendTextMessage(cid, MSG_STATUS_SMALL, "You have received this reward, must wait.")
        return true
    end

    local tmp = {}
    for i = 1, #items do
        local chance = items[i].itemChance
        if (chance == true or math.random(1, 100) <= chance) then
            local id = items[i].itemId
            local count = items[i].itemCount
            if not getItemInfo(id).stackable then
                for i = 1, #count do
                    doPlayerAddItem(cid, id, 1)
                end
            else
                doPlayerAddItem(cid, id, count)
            end
            table.insert(tmp, count .. " " .. getItemNameById(id))
        end
    end

    if effect then
        doSendMagicEffect(getThingPosition(cid), effect)
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You have received " .. table.concat(tmp, ", ") .. " .")
    doCreatureSetStorage(cid, storage, os.time() + (60 * 60 * cooldown))
    return true
end
 
Last edited:
Solution
Lua:
local items = {
    { itemId = 2160, itemCount = 1, itemChance = 50 },
    { itemId = 2160, itemCount = 1, itemChance = 50 }, -- set itemChance true for 100%
}

for i = 1, #items do
    local chance = items[i].itemChance
    if (chance == true or math.random(1, 100) <= chance) then
        local id = items[i].itemId
        local count = items[i].itemCount
        if not getItemInfo(id).stackable then
            for i = 1, #count do
                doPlayerAddItem(cid, id, 1)
            end
        else
            doPlayerAddItem(cid, id, count)
        end
    end
end
Thanks for another reply @Alberto Cabrera, you're amazing.Can u post entire code with storage with 24h cooldown? For this, i set an action script in chest?
 
I have edited my first reply
Got error:

2022-05-08 11:21:54 - [Error - Action Interface]
2022-05-08 11:21:54 - data/actions/scripts/zalaboss.lua:eek:nUse
2022-05-08 11:21:54 - Description:
2022-05-08 11:21:54 - data/actions/scripts/zalaboss.lua:27: attempt to get length of local 'count' (a number value)
2022-05-08 11:21:54 - stack traceback:
2022-05-08 11:21:54 - data/actions/scripts/zalaboss.lua:27: in function <data/actions/scripts/zalaboss.lua:13>


My actual script:

Lua:
local storage = 5964 -- change this value
local cooldown = 24 -- hours
local effect = CONST_ME_MAGIC_BLUE
local items = {
    { itemId = 5162, itemCount = 1, itemChance = 1 },
    { itemId = 5599, itemCount = 1, itemChance = 10 },
    { itemId = 5166, itemCount = 20, itemChance = 30 },
    { itemId = 5114, itemCount = 1, itemChance = 50 },
    { itemId = 5263, itemCount = 50, itemChance = 70 },
    { itemId = 2160, itemCount = 30, itemChance = true }, -- set itemChance = true for 100%
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local storageValue = getCreatureStorage(cid, storage)
    if storage - os.time() >= 1 then
        doPlayerSendTextMessage(cid, MSG_STATUS_SMALL, "You have received this reward, must wait.")
        return true
    end

    local tmp = {}
    for i = 1, #items do
        local chance = items[i].itemChance
        if (chance == true or math.random(1, 100) <= chance) then
            local id = items[i].itemId
            local count = items[i].itemCount
            if not getItemInfo(id).stackable then
                for i = 1, #count do
                    doPlayerAddItem(cid, id, 1)
                end
            else
                doPlayerAddItem(cid, id, count)
            end
            table.insert(tmp, count .. " " .. getItemNameById(id))
        end
    end

    if effect then
        doSendMagicEffect(getThingPosition(cid), effect)
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You have received " .. table.concat(tmp, ", ") .. " .")
    doCreatureSetStorage(cid, storage, os.time() + (60 * 60 * cooldown))
    return true
end
 
Got error:

2022-05-08 11:21:54 - [Error - Action Interface]
2022-05-08 11:21:54 - data/actions/scripts/zalaboss.lua:eek:nUse
2022-05-08 11:21:54 - Description:
2022-05-08 11:21:54 - data/actions/scripts/zalaboss.lua:27: attempt to get length of local 'count' (a number value)
2022-05-08 11:21:54 - stack traceback:
2022-05-08 11:21:54 - data/actions/scripts/zalaboss.lua:27: in function <data/actions/scripts/zalaboss.lua:13>


My actual script:

Lua:
local storage = 5964 -- change this value
local cooldown = 24 -- hours
local effect = CONST_ME_MAGIC_BLUE
local items = {
    { itemId = 5162, itemCount = 1, itemChance = 1 },
    { itemId = 5599, itemCount = 1, itemChance = 10 },
    { itemId = 5166, itemCount = 20, itemChance = 30 },
    { itemId = 5114, itemCount = 1, itemChance = 50 },
    { itemId = 5263, itemCount = 50, itemChance = 70 },
    { itemId = 2160, itemCount = 30, itemChance = true }, -- set itemChance = true for 100%
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local storageValue = getCreatureStorage(cid, storage)
    if storage - os.time() >= 1 then
        doPlayerSendTextMessage(cid, MSG_STATUS_SMALL, "You have received this reward, must wait.")
        return true
    end

    local tmp = {}
    for i = 1, #items do
        local chance = items[i].itemChance
        if (chance == true or math.random(1, 100) <= chance) then
            local id = items[i].itemId
            local count = items[i].itemCount
            if not getItemInfo(id).stackable then
                for i = 1, #count do
                    doPlayerAddItem(cid, id, 1)
                end
            else
                doPlayerAddItem(cid, id, count)
            end
            table.insert(tmp, count .. " " .. getItemNameById(id))
        end
    end

    if effect then
        doSendMagicEffect(getThingPosition(cid), effect)
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You have received " .. table.concat(tmp, ", ") .. " .")
    doCreatureSetStorage(cid, storage, os.time() + (60 * 60 * cooldown))
    return true
end
Line 27
Change #count to count
 
Now works, but have another problem:

Its getting 3, 4 or 5 itens each time i use chest (need just one in array of items). And not getting delay of 24 hours, using soo many times i click.
Lua:
local storage = 5964 -- change this value
local cooldown = 24 -- hours
local effect = CONST_ME_MAGIC_BLUE
local items = {
    { itemId = 5162, itemCount = 1, itemChance = 1 },
    { itemId = 5599, itemCount = 1, itemChance = 10 },
    { itemId = 5166, itemCount = 20, itemChance = 30 },
    { itemId = 5114, itemCount = 1, itemChance = 50 },
    { itemId = 5263, itemCount = 50, itemChance = 70 },
    { itemId = 2160, itemCount = 30, itemChance = true }, -- set itemChance = true for 100%
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local storageValue = getCreatureStorage(cid, storage)
    if storageValue - os.time() >= 1 then
        doPlayerSendTextMessage(cid, MSG_STATUS_SMALL, "You have received this reward, must wait.")
        return true
    end

    local tmp = {}
    for i = 1, #items do
        local chance = items[i].itemChance
        if (chance == true or math.random(1, 100) <= chance) then
            local id = items[i].itemId
            local count = items[i].itemCount
            if not getItemInfo(id).stackable then
                for i = 1, count do
                    doPlayerAddItem(cid, id, 1)
                end
            else
                doPlayerAddItem(cid, id, count)
            end
            table.insert(tmp, count .. " " .. getItemNameById(id))
            break
        end
    end

    if effect then
        doSendMagicEffect(getThingPosition(cid), effect)
    end

    local text = #tmp == 0 and "You have no received nothing. :(" or string.format("You have received %s.", table.concat(tmp, ", "))
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, text)
    doCreatureSetStorage(cid, storage, os.time() + (60 * 60 * cooldown))
    return true
end
 
Lua:
local storage = 5964 -- change this value
local cooldown = 24 -- hours
local effect = CONST_ME_MAGIC_BLUE
local items = {
    { itemId = 5162, itemCount = 1, itemChance = 1 },
    { itemId = 5599, itemCount = 1, itemChance = 10 },
    { itemId = 5166, itemCount = 20, itemChance = 30 },
    { itemId = 5114, itemCount = 1, itemChance = 50 },
    { itemId = 5263, itemCount = 50, itemChance = 70 },
    { itemId = 2160, itemCount = 30, itemChance = true }, -- set itemChance = true for 100%
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local storageValue = getCreatureStorage(cid, storage)
    if storageValue - os.time() >= 1 then
        doPlayerSendTextMessage(cid, MSG_STATUS_SMALL, "You have received this reward, must wait.")
        return true
    end

    local tmp = {}
    for i = 1, #items do
        local chance = items[i].itemChance
        if (chance == true or math.random(1, 100) <= chance) then
            local id = items[i].itemId
            local count = items[i].itemCount
            if not getItemInfo(id).stackable then
                for i = 1, count do
                    doPlayerAddItem(cid, id, 1)
                end
            else
                doPlayerAddItem(cid, id, count)
            end
            table.insert(tmp, count .. " " .. getItemNameById(id))
            break
        end
    end

    if effect then
        doSendMagicEffect(getThingPosition(cid), effect)
    end

    local text = #tmp == 0 and "You have no received nothing. :(" or string.format("You have received %s.", table.concat(tmp, ", "))
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, text)
    doCreatureSetStorage(cid, storage, os.time() + (60 * 60 * cooldown))
    return true
end
something still seems wrong. I tried to pick with a char, nothing happens, no message (or error) in console or game.
 
Back
Top