#luck boost system:

1 messages · Page 1 of 1 (latest)

blissful ocean
#

hello, i want to add a lcuk boost system and ive tried everythiong i could, yet it didnt work so i decided to delete it and ask it here:

local module = {}
local food = script.Parent.Parent.Parent.Parent.Food

module.food = {
    ["6"] = food.Waffle,
    ["5"] = food.DarkPoisonPizza,
    ["4"] = food.Burger,
    ["3"] = food.Donut,
    ["2"] = food.Pizza,
    ["1"] = food.Chocolate,
}

module.rarities ={
    ["6"] = 1,
    ["5"] = 1,
    ["4"] = 50,
    ["3"] = 19,
    ["2"] = 51,
    ["1"] = 50,
}

module.prices = {
    [6] = 20000,
    [5] = 10000,
    [4] = 1000,
    [3] = 300,
    [2] = 100,
    [1] = 85,
}

module.ingredients = {
    ["Egg"] = 2, --times 2 luck boost
    ["Butter"] = 2, --times 2 luck boost
    ["Ice cubes"] = 2, --times 2 luck boost

}

module.ChooseFood = function()
    local random = math.random(1, 172)
    local counter = 0

    for rarity, weight in module.rarities do
        counter += weight
        if random <= counter then
            local price = module.prices[tonumber(rarity)]
            return module.food[rarity], rarity, price
        end
    end
end

return module

so i want to check if the player has the ingredient in their inventory and if so apply the luck boost, please help

#

i would appreciate any help

#

please ping me if you reply

foggy cobalt
#

@Jim Hello

#

@blissful ocean

blissful ocean
#

hello

foggy cobalt
#

You're trying to implement a weighted random selection system

#

am I right

blissful ocean
#

yes

#

everything weorks exept idk how to make a luckboost

#

it should scan all ym items in my inventory to see which boosts i need to get

#

so if i have 10 eggs i should gte x20 luck

#

or 5 eggs and 5 butter i should get x20 luck

#

if that makes sense

foggy cobalt
#

So your inventory gives u more luck?

blissful ocean
#

yes

#

the items in the table do

#

the number next to the item is the luckboost

#

in the module.ingredients

foggy cobalt
#

Alright

#

First I'd advice you store your items and their rarity inside a table

#

Each sub-table should have the item, and a weight

#

smth like

#
{name = "Common", weight = 60,}```
blissful ocean
#

hm ok

foggy cobalt
#

Also, rather than hardcoding the totalWeight

#

calc it

blissful ocean
#

im already lost :( im just starting out

limber berryBOT
#

studio** You are now Level 7! **studio

tall wren
#

bla bla, luck be normalized (1/50 = 2/100), so it's hard "double" it. You simply move the mean (e.g. from 50/100 on average to 75/100 on average).

How you wish to do this depends on how you want it to behave

foggy cobalt
#

You have a table containing sub-tables, one for each item

#

each has two extra variables, weight and Baseweight

#

btw, You can tell me if anything's confusing

blissful ocean
#

alr so what does baseweight mean

#

what do i put as the vaue

foggy cobalt
#

actually wait a second

#

Lemme think of a better approach rq

chilly tapir
#

local module = {}
local food = script.Parent.Parent.Parent.Parent.Food

module.food = {
["6"] = food.Waffle,
["5"] = food.DarkPoisonPizza,
["4"] = food.Burger,
["3"] = food.Donut,
["2"] = food.Pizza,
["1"] = food.Chocolate,
}

module.rarities = {
["6"] = 1,
["5"] = 1,
["4"] = 50,
["3"] = 19,
["2"] = 51,
["1"] = 50,
}

module.prices = {
[6] = 20000,
[5] = 10000,
[4] = 1000,
[3] = 300,
[2] = 100,
[1] = 85,
}

module.ingredients = {
["Egg"] = 2, --times 2 luck boost
["Butter"] = 2, --times 2 luck boost
["Ice cubes"] = 2, --times 2 luck boost
}

-- Calculates the luck boost multiplier based on owned ingredients
local function getLuckBoost(ownedIngredients)
local boost = 1
for ingredient, multiplier in pairs(module.ingredients) do
if ownedIngredients and ownedIngredients[ingredient] then
boost = boost * multiplier
end
end
return boost
end

-- ownedIngredients is a table like {["Egg"]=true, ["Butter"]=true}
module.ChooseFood = function(ownedIngredients)
-- Calculate total weight with luck boost
local luckBoost = getLuckBoost(ownedIngredients)
local totalWeight = 0
for rarity, weight in pairs(module.rarities) do
if tonumber(rarity) >= 4 then -- Boost rarities 4, 5, 6
totalWeight = totalWeight + weight * luckBoost
else
totalWeight = totalWeight + weight
end
end

local random = math.random(1, totalWeight)
local counter = 0

for rarity, weight in pairs(module.rarities) do
    local currentWeight = weight
    if tonumber(rarity) >= 4 then
        currentWeight = weight * luckBoost
    end
    counter = counter + currentWeight
    if random <= counter then
        local price = module.prices[tonumber(rarity)]
        return module.food[rarity], rarity, price
    end
end

end

return module

#

ai slop type shit

blissful ocean
#

lol

#

i dont want ai

chilly tapir
#

i mean ig its hated but... it works

#

ig

blissful ocean
#

i want to understand it myself

#

i used to use ai

tall wren
foggy cobalt
#

it might throw unexpected results

tall wren
#

All you truly have to do is increase the min.

0,100 - mean = 50
20,100 - mean = 60

chilly tapir
blissful ocean
chilly tapir
blissful ocean
#

chatgpt

#

i want to move away from it

chilly tapir
tall wren
#

Luck is normalized! simply multiplying it won't work

chilly tapir
#

Type shit

foggy cobalt
#

@blissful ocean can u wait rq. ill brb. ill tell u the new approach if it takes

tall wren
blissful ocean
#

i might be eating dinner

chilly tapir
#

I forgot to tell copilot its for roblox and stuff, but yeah roblox will now turn from slop to ai generated slop 😦

limber berryBOT
#

studio** You are now Level 1! **studio

cloud kestrel
#

🌚

foggy cobalt
#

its a lil too simple

#

alr ill brb

tall wren
foggy cobalt
#

ain't that essential for a game with trading?

#

or...

#

wait

#

@blissful ocean

#

Are these items rolled for only personal use?

#

i mean in-game?

#

If there's no trading, the min-shifting approach suffice

blissful ocean
#

There’s no trading

blissful ocean