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

Chest reward ( random item )

Nuelman

Member
Joined
Nov 9, 2017
Messages
98
Solutions
1
Reaction score
6
V 10.99 tfs 1.x
Hello,
Already I have this script:
Lua:
local rewards = {
  { item = 9019, count = 1 },
  { item = 5809, count = 1 },
  { item = 8982, count = 1 }
}   

local YOUR_STORAGE_NUMBER = 5000

function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if player:getStorageValue(YOUR_STORAGE_NUMBER) ~= 1 then
        local random = math.random(1, #rewards)
        player:addItem(rewards[random].item, rewards[random].count)
        player:sendTextMessage(36, 'You have found '.. ItemType(rewards[random].item):getName() ..'.')
        player:setStorageValue(YOUR_STORAGE_NUMBER, 1)
    else
         player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already opened this chest.")
    end
    return true
end

I would like to change the possibility of obtaining for each object. (chance)

I would also like to add, that you can use the reward chest again after 10 hours.

Is it possible?

+rep
 
Solution
But is diferent versión tfs.
THIS work for 10.99m

And On the question, to use the chest again after a few hours, is there a solution? Thank you
Post automatically merged:

Up
This should work.

-- minor edit to code to fix a small issue on line 27
Lua:
local rewards = {
    { item = 9019, count = 1, chance = 50 },
    { item = 5809, count = 1, chance = 50 },
    { item = 8982, count = 1, chance = 50 }
}

local YOUR_STORAGE_NUMBER = 5000
local delay_timer = 36000 -- in seconds 60*60*10 = 10 hours ()

function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)

    local cur_time, cur_storage = os.time(), player:getStorageValue(YOUR_STORAGE_NUMBER)
 
    if cur_storage > cur_time then...
@Xikini can you make give reward in bag?
 
Is there a way to make sure you get only 1 reward out of the suggested reward items?
100% chance, no cd, only 1 out of x items.
Thanks.
 
Is there a way to make sure you get only 1 reward out of the suggested reward items?
100% chance, no cd, only 1 out of x items.
Thanks.
Just make sure that the total % adds up to a 100%
Example:
Lua:
local rewards = {
    { item = 28552, count = 500, chance = 16 },
    { item = 28553, count = 500, chance = 16 },
    { item = 28554, count = 500, chance = 16 },
    { item = 28555, count = 500, chance = 16 },
    { item = 28556, count = 500, chance = 16 },
    { item = 28557, count = 500, chance = 16 }
}
 
Back
Top