Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Solved] How to make a chance system?

Asked by
xJigoku 17
5 years ago
Edited 5 years ago

This inserts the pets chance into a table where it will get a random one. The chance is the number next to the pets name (Code Block 2 for the module/pets)

local canGetPets = {}

local rar = eggModule[egg].Rarities
for currentPlace = 1,#rar do
    local mathmatical = math.max(rar[currentPlace][2])
    for i = 1,mathmatical do
                table.insert(canGetPets, rar[currentPlace][1])
    end
end

(Egg module script with pets and their chance)

local eggs = {

    ["Basic Egg"] = {
        Cost = {"Cash", 0};
        Rarities = {
            {"Dog", 55};
            {"Cat", 45};
            {"Bear", 30};
            {"Wolf", 15};
            {"Vespertillius", 0.002};
        }
    };


}

return eggs

The problem is is that it can't insert 0.002 of a pet into a table (obviously) I just don't know how else to do it.

0
Is the number supposed to be a percentage? User#24403 69 — 5y
0
Yes it is xJigoku 17 — 5y
0
Maybe you can use some smart mathing, like for example let's say you got 20% on a pet, it would make sense to do math.random(1, 5), and check if its 2 for example, that'sa logicall way to do it, cuz math.random(1, 5) has a 20% chance of returning 2, its pretty much trying to use fractions starmaq 1290 — 5y
0
math.random(100) or math.random(1,100) would do (first selects number 0-100, second selects number 1-100) LoganboyInCO 150 — 5y
View all comments (5 more)
0
45+55+30+15+0.02 is bigger than 100 farizarps 132 — 5y
0
you can multiply everything by 100 farizarps 132 — 5y
0
@loganboyinco yah maybe, thats a cool idea starmaq 1290 — 5y
0
If I multiply it by the amount that it take for the decimal to become 1, it will lag, a lot xJigoku 17 — 5y
0
Came back to say the problem was that I was printing causing an overload in the output, causing lag. Thanks for the help though xJigoku 17 — 5y

Answer this question