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

Random Reward Chest TFS 0.3.6

Carlitos Flow

Developer (lvl*1)
Joined
Mar 2, 2011
Messages
156
Solutions
4
Reaction score
10
Good day guys, im trying to create a chest with randoms items (from a list) and the player can win por example, if there are 20 items on the list, the player win 5 items, the player two win 2 items, the player three win 10 items, its just an example, not ever the same rewards, and ofc with minimum chance of rare items. Also if item is stackable like 100 cc, it could win math.random(1,100). If is possible when player take his reward it need say: --If not cap then (error) and-- if cap "You take the following items of your reward chest "..items.." (if not its ok).

Sorry for my bad english, thanks in advance.
TFS 0.3.6
 
Solution
Thanks bro, the problem now is than the chest repeat items of the list, for exemple 3 demons legs, i only want 1 of each.
Lua:
local config = {
   max_items = 10, -- MAX 20.
   max_random_roll = 100, -- used for calculating chance
                       -- 1/100 = 1% chance
                       -- 1/10000 = 0.01% chance
   
   -- if player doesn't roll uncommon or rare item, defaults to giving common
   common_items = { {2467, 1}, {2148, 100} },
                   -- {item_id, max_amount}
   
   uncommon_chance = 15, -- 15% chance . . 15/100
   uncommon_items = { {2189, 1}, {2152, 100} },
   
   rare_chance = 3, -- 3% chance . . 3/100
   rare_items = { {2187, 1}, {2160, 100} }
}

function onUse(cid, item, fromPosition, itemEx...
Actually my script:
I have no idea how to set the player to add 1, or 5, of all items, or all if he is lucky, also add rare items. And if there is no cap, the items will not be added.


Lua:
function onUse(cid, item, frompos, item2, topos)
local items = {
    [0] = { 2160, 8820, 2468, 2509, 2643, 2190, 2643, 8923, 8892, 2481, 2389},
    [1] = { 2160, 8820, 2468, 2509, 2643, 2190, 2643, 8923, 8892, 2481, 2389},
    [2] = { 2160, 8820, 2468, 2509, 2643, 2182, 2643, 8923, 8892, 2481, 2389},
    [3] = { 2160, 2643, 8923, 8892, 2481, 2389, 2643, 8923, 8892, 2481, 2389},
    [4] = { 2160, 2643, 8923, 8892, 2481, 2389, 2643, 8923, 8892, 2481, 7735},
    [5] = { 2160, 2643, 8923, 8892, 2481, 2389, 2643, 8923, 8892, 2481, 2389},
    [6] = { 2160, 2643, 8923, 8892, 2481, 2389, 2643, 8923, 8892, 2481, 2389},
    [7] = { 2160, 2643, 8923, 8892, 2481, 2389, 2643, 8923, 8892, 2481, 2389},
    [8] = { 2160, 2643, 8923, 8892, 2481, 2389, 2643, 8923, 8892, 2481, 2389},
    [9] = { 2160, 2643, 8923, 8892, 2481, 2389, 2643, 8923, 8892, 2481, 2389},
    [10] = { 2160, 2643, 8923, 8892, 2481, 2389, 2643, 8923, 8892, 2481, 2389}
                       
}
    if item.uid == 22110 then
        for v, item in pairs(items) do
            if getPlayerLevel(cid) > 10 or getPlayerLevel(cid) < 10 then
             local i = math.random(#items)
            doPlayerAddItem(cid, items[i][math.random(1, 11)])
            end
            end
       end
       return true
   end
 
Lua:
local config = {
   max_items = 10, -- MAX 20.
   max_random_roll = 100, -- used for calculating chance
                       -- 1/100 = 1% chance
                       -- 1/10000 = 0.01% chance
  
   -- if player doesn't roll uncommon or rare item, defaults to giving common
   common_items = { {2467, 1}, {2148, 100} },
                   -- {item_id, max_amount}
  
   uncommon_chance = 15, -- 15% chance . . 15/100
   uncommon_items = { {2189, 1}, {2152, 100} },
  
   rare_chance = 3, -- 3% chance . . 3/100
   rare_items = { {2187, 1}, {2160, 100} }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
  
   local rand_amount = math.random(config.max_items)
   local c_ = 1988
   if rand_amount < 9 then
       c_ = 1987
   end
   local container = doCreateItemEx(c_, 1)
   for i = 1, rand_amount do
       local rand = math.random(config.max_random_roll)
       local tmp = 0
       if rand <= config.rare_chance then
           rand = math.random(#config.rare_items)
           tmp = doCreateItemEx(config.rare_items[rand][1], math.random(config.rare_items[rand][2]))
       elseif rand <= config.uncommon_chance then
           rand = math.random(#config.uncommon_items)
           tmp = doCreateItemEx(config.uncommon_items[rand][1], math.random(config.uncommon_items[rand][2]))
       else
           rand = math.random(#config.common_items)
           tmp = doCreateItemEx(config.common_items[rand][1], math.random(config.common_items[rand][2]))
       end      
       doAddContainerItemEx(container, tmp)
   end
  
   if doPlayerAddItemEx(cid, container, false) == RETURNVALUE_NOERROR then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found a " .. getItemNameById(c_) .. "!")
   else
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enough free capacity or room to obtain your reward.")
   end
  
   return true
end
 
Lua:
local config = {
   max_items = 10, -- MAX 20.
   max_random_roll = 100, -- used for calculating chance
                       -- 1/100 = 1% chance
                       -- 1/10000 = 0.01% chance
 
   -- if player doesn't roll uncommon or rare item, defaults to giving common
   common_items = { {2467, 1}, {2148, 100} },
                   -- {item_id, max_amount}
 
   uncommon_chance = 15, -- 15% chance . . 15/100
   uncommon_items = { {2189, 1}, {2152, 100} },
 
   rare_chance = 3, -- 3% chance . . 3/100
   rare_items = { {2187, 1}, {2160, 100} }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
 
   local rand_amount = math.random(config.max_items)
   local c_ = 1988
   if rand_amount < 9 then
       c_ = 1987
   end
   local container = doCreateItemEx(c_, 1)
   for i = 1, rand_amount do
       local rand = math.random(config.max_random_roll)
       local tmp = 0
       if rand <= config.rare_chance then
           rand = math.random(#config.rare_items)
           tmp = doCreateItemEx(config.rare_items[rand][1], math.random(config.rare_items[rand][2]))
       elseif rand <= config.uncommon_chance then
           rand = math.random(#config.uncommon_items)
           tmp = doCreateItemEx(config.uncommon_items[rand][1], math.random(config.uncommon_items[rand][2]))
       else
           rand = math.random(#config.common_items)
           tmp = doCreateItemEx(config.common_items[rand][1], math.random(config.common_items[rand][2]))
       end     
       doAddContainerItemEx(container, tmp)
   end
 
   if doPlayerAddItemEx(cid, container, false) == RETURNVALUE_NOERROR then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found a " .. getItemNameById(c_) .. "!")
   else
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enough free capacity or room to obtain your reward.")
   end
 
   return true
end
Thanks bro, the problem now is than the chest repeat items of the list, for exemple 3 demons legs, i only want 1 of each.
 
Thanks bro, the problem now is than the chest repeat items of the list, for exemple 3 demons legs, i only want 1 of each.
Lua:
local config = {
   max_items = 10, -- MAX 20.
   max_random_roll = 100, -- used for calculating chance
                       -- 1/100 = 1% chance
                       -- 1/10000 = 0.01% chance
   
   -- if player doesn't roll uncommon or rare item, defaults to giving common
   common_items = { {2467, 1}, {2148, 100} },
                   -- {item_id, max_amount}
   
   uncommon_chance = 15, -- 15% chance . . 15/100
   uncommon_items = { {2189, 1}, {2152, 100} },
   
   rare_chance = 3, -- 3% chance . . 3/100
   rare_items = { {2187, 1}, {2160, 100} }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
   
   local t = {}
   local rand_amount = math.random(config.max_items)
   local c_ = 1988
   if rand_amount < 9 then
       c_ = 1987
   end
   local container = doCreateItemEx(c_, 1)
   for i = 1, rand_amount do
       local rand = math.random(config.max_random_roll)
       local tmp = 0
       if rand <= config.rare_chance then
           rand = math.random(#config.rare_items)
           if not t[rand + 2000] then
               t[rand + 2000] = 1
               tmp = doCreateItemEx(config.rare_items[rand][1], math.random(config.rare_items[rand][2]))
           end
       elseif rand <= config.uncommon_chance then
           rand = math.random(#config.uncommon_items)
           if not t[rand + 1000] then
               t[rand + 1000] = 1
               tmp = doCreateItemEx(config.uncommon_items[rand][1], math.random(config.uncommon_items[rand][2]))
           end
       else
           rand = math.random(#config.common_items)
           if not t[rand] then
               t[rand] = 1
               tmp = doCreateItemEx(config.common_items[rand][1], math.random(config.common_items[rand][2]))
           end
       end
       if tmp ~= 0 then
           doAddContainerItemEx(container, tmp)
       end
   end
   
   if doPlayerAddItemEx(cid, container, false) == RETURNVALUE_NOERROR then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found a " .. getItemNameById(c_) .. "!")
   else
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enough free capacity or room to obtain your reward.")
   end
   
   return true
end
 
Solution
Thank you bro :)
Lua:
local config = {
   max_items = 10, -- MAX 20.
   max_random_roll = 100, -- used for calculating chance
                       -- 1/100 = 1% chance
                       -- 1/10000 = 0.01% chance
  
   -- if player doesn't roll uncommon or rare item, defaults to giving common
   common_items = { {2467, 1}, {2148, 100} },
                   -- {item_id, max_amount}
  
   uncommon_chance = 15, -- 15% chance . . 15/100
   uncommon_items = { {2189, 1}, {2152, 100} },
  
   rare_chance = 3, -- 3% chance . . 3/100
   rare_items = { {2187, 1}, {2160, 100} }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
  
   local t = {}
   local rand_amount = math.random(config.max_items)
   local c_ = 1988
   if rand_amount < 9 then
       c_ = 1987
   end
   local container = doCreateItemEx(c_, 1)
   for i = 1, rand_amount do
       local rand = math.random(config.max_random_roll)
       local tmp = 0
       if rand <= config.rare_chance then
           rand = math.random(#config.rare_items)
           if not t[rand + 2000] then
               t[rand + 2000] = 1
               tmp = doCreateItemEx(config.rare_items[rand][1], math.random(config.rare_items[rand][2]))
           end
       elseif rand <= config.uncommon_chance then
           rand = math.random(#config.uncommon_items)
           if not t[rand + 1000] then
               t[rand + 1000] = 1
               tmp = doCreateItemEx(config.uncommon_items[rand][1], math.random(config.uncommon_items[rand][2]))
           end
       else
           rand = math.random(#config.common_items)
           if not t[rand] then
               t[rand] = 1
               tmp = doCreateItemEx(config.common_items[rand][1], math.random(config.common_items[rand][2]))
           end
       end
       if tmp ~= 0 then
           doAddContainerItemEx(container, tmp)
       end
   end
  
   if doPlayerAddItemEx(cid, container, false) == RETURNVALUE_NOERROR then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found a " .. getItemNameById(c_) .. "!")
   else
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have enough free capacity or room to obtain your reward.")
   end
  
   return true
end
 
Back
Top