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

[CLOSED] More accurate/efficient rarity chance system?

Asked by
0b1w 13
5 years ago
Edited 5 years ago

Here's what I have made right now:

local Items = {
    ["Blue"] = 500; -- common
    ["Orange"] = 200; -- uncommon
    ["Red"] = 50; -- rare
    ["Purple"] = 1; -- legendary
};

local Spawns = {};

local function setSpawns()
    for i = 1,500 do
        for item,rarity in pairs(Items) do
            if (Items[item] > 0) then
                table.insert(Spawns,item);
                Items[item] = Items[item] - 1;
            end;
        end;
    end;
end;

setSpawns();

local function spawnItem()
    local Item = Spawns[math.random(1,#Spawns)];
    print(Item);
end;

while (wait(1)) do
    spawnItem();
end;

I'm not sure that this is the most accurate/efficient way for a rarity system though. Any help or information would be much appreciated.

0
I believe that what you have is pretty fine. try measuring how much time it takes. but if you really want something you can try not using tables because I remember hearing that they are resource intensive especially when you have 500 indexes. GGRBXLuaGG 417 — 5y
0
yeah what you have is fine royaltoe 5144 — 5y
0
Thanks 0b1w 13 — 5y

Answer this question