• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[TFS 1.0] Quest Chest Has x% Chance of Giving X Item OR Y Item OR Z Item

Jaed Le Raep

★Gaeming★
Joined
Sep 3, 2007
Messages
1,298
Reaction score
446
Hey guys, could someone be kind enough to create a quest chest script in which when a player uses it, there's a chance he'll get 1 of 3 total items? The chest should be immovable and work with configurable Storage and Action IDs :)
 
Solution
LUA:
-- 100 = accuracy 99%
-- 1000 = accuracy 99.9%
-- 10000 = accuracy 99.99% and so on...
hundredpercent = 10000
item1 = hundredpercent * 0.1 -- 10%
item2 = hundredpercent * 0.4 -- 40%
item3 = hundredpercent * 0.5 -- 50%
-- Make sure all items will equal to 1.0 in total

-- calibrate item 2 and 3
item2 = item2 + item1
item3 = item3 + item2

lotteryNumber = Math.random(1, hundredpercent)
if lotteryNumber < item2 then
    -- item 1 reward
elseif lotteryNumber < item3 then
    -- item2 reward
else
    -- item3 reward
end

Probably a better way but ive been drinknig and this should work.
It's more than the math, it's also the immovable state and etc. There are a lot of basics I've forgotten, so it's difficult for me to really think through on how to script it.
 
LUA:
-- 100 = accuracy 99%
-- 1000 = accuracy 99.9%
-- 10000 = accuracy 99.99% and so on...
hundredpercent = 10000
item1 = hundredpercent * 0.1 -- 10%
item2 = hundredpercent * 0.4 -- 40%
item3 = hundredpercent * 0.5 -- 50%
-- Make sure all items will equal to 1.0 in total

-- calibrate item 2 and 3
item2 = item2 + item1
item3 = item3 + item2

lotteryNumber = Math.random(1, hundredpercent)
if lotteryNumber < item2 then
    -- item 1 reward
elseif lotteryNumber < item3 then
    -- item2 reward
else
    -- item3 reward
end

Probably a better way but ive been drinknig and this should work.
 
Solution
Back
Top