Basically, I have this shop system and every 24 hours it picks 6 random items from 3 tables to go into the shop
the only problem is I keep getting duplicate items.
here is an excerpt of the code
function getAvailableItems(day)
local rng = Random.new(day)
local shopItems = {}
for i = 1, 6 do
if rng:NextNumber(0,100) < weights.Rare then -- Rare
local item = rareItems[rng:NextInteger(1, #rareItems)]
table.insert(shopItems, item)
elseif rng:NextNumber(0,100) < weights.Legendary then -- Legendary
local item = legendaryItems[rng:NextInteger(1, #legendaryItems)]
table.insert(shopItems, item)
else
local item = commonItems[rng:NextInteger(1, #commonItems)]
table.insert(shopItems, item)
end
end
return shopItems
end
Maybe make it check through what the player has and compare it to the outcome. If that player has that item already, make it so it keeps rerolling until it gets a new item (use some functions if necessary)
Just a quick thing! I don’t know how much help this is gonna give but all the best,
function getAvailableItem(rng)
local item = commonItems[rng:NextInteger(1, #commonItems)]
if rng:NextNumber(0,100) < weights.Rare then -- Rare
item = rareItems[rng:NextInteger(1, #rareItems)]
elseif rng:NextNumber(0,100) < weights.Legendary then -- Legendary
item = legendaryItems[rng:NextInteger(1, #legendaryItems)]
end
return item
end
function getAvailableItems(day)
local rng = Random.new(day)
local shopItems = {}
--keep asking for items, until 6 are found, which aren't duplicates
repeat
local item = getAvailableItem(rng)
if not table.find(shopItems, item) then
table.insert(shopItems, item)
end
until #shopItems == 6
return shopItems
end