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

How do I make this script print the item name?

Asked by
Uluomis 32
4 years ago
Edited 4 years ago

So I have this script that selects a random item in the pets table but it prints the amount of characters the name contains rather than the actual name. An example of this would be "Selected 5". I am wondering how to change this to make it print the item name. An example would be "Selected Fire Sword".

local Pets = {
    rarities = {0.6,0.4};
    pets = {
        {
            name="Part";
            rarity="Rare";
        };  
        {
            name="Part2";
            rarity="Legendary";
        };  
    };
};

local totalweight = 0

for _,v in ipairs(Pets.rarities) do
    totalweight = totalweight + v
end

local at = math.random() * totalweight

for i,v in pairs(Pets.rarities) do
    if at < v then
        print(Pets.pets[i] .. " has been chosen!")
        break
    end
    at = at - v
end

1 answer

Log in to vote
0
Answered by
oftenz 367 Moderation Voter
4 years ago

This seems like the obvious solution:

print(Pets.pets[i] .. " has been chosen!")

Change to

print(Pets.pets[i].name .. " has been chosen!")
0
It still prints the amount of characters of the name Uluomis 32 — 4y
1
nvm for some reason it doesn't like if you do #Pets so I had to do Pets thanks alot! Uluomis 32 — 4y
Ad

Answer this question