#I need help with a rarity system

1 messages · Page 1 of 1 (latest)

olive thorn
#

I have the system

sand cave
#

hi!

#

i can try to help you

#

do u need a system from scratch, or edit a pre existing one

#

oh nvm

olive thorn
#

do u think u can help me out with this lua function Bnum.rollRarity(items: any, luck: any) local total = '0e0' luck = luck or '1e0' local adjust = {} for _, item in ipairs(items) do local invLuck = Bnum.toStr(Bnum.div('1e0', luck)) local adj = Bnum.toStr(Bnum.pow(item.Chance, invLuck)) adjust = { Item = item, Chance = adj } total = Bnum.toStr(Bnum.add(total, adj)) end local roll = Bnum.toStr(Bnum.clamp(Bnum.mul(math.random(), total), '0e0', total)) for _, item in ipairs(items) do roll = Bnum.toStr(Bnum.sub(roll, item.Chance)) if Bnum.leeq(roll, {0,0}) then return item end end return items[#items] end
but when i do lua function populateRarityList(scrollFrame, rarities) clearChildren(scrollFrame) sortByChance(rarities) local totalBase = '0e0' for _, r in ipairs(rarities) do totalBase = Bnum.add(totalBase, r.Chance) end local totalAdjusted = '0e0' for _, r in ipairs(rarities) do totalAdjusted = Bnum.add(totalAdjusted, computeAdjustedChance(r, Luck.Value)) end for index, r in ipairs(rarities) do local adjChance = computeAdjustedChance(r, Luck.Value) local yourChance = Bnum.mul(Bnum.div(adjChance, totalAdjusted), 100) local baseChance = Bnum.mul(Bnum.div(r.Chance, totalBase), 100) end end the chances here it not doing what i want

olive thorn
#

for some reason some show less then others

sand cave
#

i have a weighted chance system i made, i can send it to you if youd like, youll have to add your spesific luck stats n stuff tho

#

its accurate and all that

olive thorn
#

but is urs based off of using Bnum lol

olive thorn
sand cave
#

it does

silver craneBOT
#

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

sand cave
#

hold on ill pull it up

olive thorn
#

ive been at this for hrs but at least i got the stud ratio setup

#

all i did was / 12 from chance but the board shows a different story

sand cave
#
    if not eggTable then return nil end

    local baseLuck = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Luck").Value
    local effectiveLuck = baseLuck

    local entries = {}
    local maxWeight = 0
    -- rest unchanged until the adjustment loop...

    -- Find original max weight
    for _, pet in pairs(eggTable) do
        if typeof(pet.Weight) == "number" and pet.Weight > 0 then
            maxWeight = math.max(maxWeight, pet.Weight)
        end
    end
    if maxWeight == 0 then return nil end

    -- Adjust weights with effectiveLuck instead of luck
    for _, pet in pairs(eggTable) do
        local w = pet.Weight
        -- Single calculation for tier boost based on weight and effectiveLuck
        local tierBoost = 1 + (effectiveLuck / 10000) * (math.exp(3.5 * (1 - math.log10(w))) - 1) / 2
        local newWeight = math.max(w * tierBoost, 0.001)
        table.insert(entries, {Name = pet.Name, Weight = newWeight})
    end
    local total = 0
    local POWER = 1
    for _, pet in ipairs(entries) do
        pet.Weight = pet.Weight ^ POWER
        total += pet.Weight
    end
    local roll = math.random() * total
    local cumulative = 0
    for _, pet in ipairs(entries) do
        cumulative += pet.Weight
        if roll <= cumulative then
            return pet.Name
        end
    end
    return entries[#entries].Name
end```
#

i can chance stuff, but this the chance function i use

#

the table looks like ``` ["Basic"] = {

    -- COMMON
    ["Dog"] = {Name = "Dog", Weight = 25},
    ["Cat"] = {Name = "Cat", Weight = 22},
    ["Bunny"] = {Name = "Bunny", Weight = 20},} ```
#

then js change weight based on how rare you want it

#

it was for a pet game, so if you do end up using it youll have to change stuff

#

like "eggTable"

olive thorn
# sand cave like "eggTable"

isnt mine basically the same but im using my module that converts to 1e32 as ex from {1, 32} which is 100000000000000000000000000000000

olive thorn
# sand cave then js change weight based on how rare you want it

isn't there a way to fix this lua function Bnum.rollRarity(items: any, luck: any) local total = '0e0' luck = luck or '1e0' local adjust = {} for _, item in ipairs(items) do local invLuck = Bnum.toStr(Bnum.div('1e0', luck)) local adj = Bnum.toStr(Bnum.pow(item.Chance, invLuck)) adjust = { Item = item, Chance = adj } total = Bnum.toStr(Bnum.add(total, adj)) end local roll = Bnum.toStr(Bnum.clamp(Bnum.mul(math.random(), total), '0e0', total)) for _, item in ipairs(items) do roll = Bnum.toStr(Bnum.sub(roll, item.Chance)) if Bnum.leeq(roll, {0,0}) then return item end end return items[#items] end
its just using BN as in just math but in higher format

#

and math.pow(1, pet.Chance) is better lol

#

or pet.Weight

sand cave
#

hold up, whats the problem again

#

sorry

#

just confused a bit

olive thorn
#

its basically going to help me with rarity studs and runes rarity roll system

olive thorn
#

def not smart @analog timber u should be s1 if u dont know what leeq, le, eq, me, meeq means

analog timber
#

because if leeq is lessthan-equal, than what is le

#

your acronyms are wrong?

slate holly
slate holly
analog timber
olive thorn
#

meeq, me, eq, le, leeq

=, >, ==, <, <=

analog timber
olive thorn
#

sad ur not smart

slate holly
#

@lofty monolith i c u

analog timber
olive thorn
#

plus u cant get help in scripting channel

slate holly
analog timber
#

one would think their bignum module would use operator overloads anyway, avoiding this confusion entirely?

slate holly
analog timber
#

ya they do, they're defined in metatables

slate holly
#

i mean just

x = function(a, b)
x = function(a, b, c)

#

C features it so I don’t see why Lua can’t

analog timber