Ad
Log in to vote
1

How to make a tame chance system?

Asked by 1 month ago

So Im starting on a game where you go around tame animals then you can turn into them. I just dont know how to set up a tame chanse like. If the tame chanse is 80% how to I make it theres only 20% of the tame failing? Thank you in advanced.

2 answers

Log in to vote
2
Answered by
TGazza 799 Moderation Voter
1 month ago
local Chance= 80

local Tamed = 0
local Nope = 0

while true do
    local Percent= math.floor( (math.random()*100)+0.5) -- Custom Round since Lua don't have a math.round function!
    if(Percent <= Chance) then
        Tamed  = Tamed + 1
    else
        Nope = Nope + 1
    end
    print("Tame Success =", Tamed," : Nope = ", Nope)
    wait()
end

The above script will print out how many times it succeeds and how many times it fails. The only bit you need is

local Chance= 80
local Percent= math.floor( (math.random()*100)+0.5) -- Custom Round since Lua don't have a math.round function!
if(Percent<= Chance) then
-- Do stuff on Tamed!
end

I just made the script loop through possible rolls as if you're trying with an unlimited amount of tries.

Hope this helps! :)

Ad
Log in to vote
0
Answered by 1 month ago
Edited 1 month ago

Here this should help. I'm not that advanced so Im not sure how to shorten the 'or' statement lol sorry. Also instead of the prints put the script that makes it tamed or not.

local randomnumber = math.random(1,100)
print(randomnumber)
if randomnumber == 1 or randomnumber == 2 or randomnumber == 3 or randomnumber == 4 or randomnumber == 5 or randomnumber == 6 or randomnumber == 7 or randomnumber == 8 or randomnumber == 9 or randomnumber == 10 or randomnumber == 11 or randomnumber == 12 or randomnumber == 13 or randomnumber == 14 or randomnumber == 15 or randomnumber == 16 or randomnumber == 17 or randomnumber == 18 or randomnumber == 19 or randomnumber == 20 then
    print("Failed")
else
    print("Tamed")
end
1
Also copy it from the source xX02Dire_Wolf20Xx 9 — 1mo
0
Instead of all the inefficient if/or statements, why not just do ``if randomnumber <= 20 then``... It'll do the same thing. xInfinityBear 1154 — 1mo

Answer this question