• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[TFS 1.0][LUA] Chance / Random

Abyss_

Atlantika RPG Owner
Joined
Aug 3, 2014
Messages
195
Reaction score
81
Location
Wonderland
Hi!

I made this script which should transform an item into a random one. There are different chances but it always ends up that its the "silver node" (the first 'elseif') which gets generated.

The code:
Code:
function onStartup()

    local nodePositions = {
    {x = 3749, y = 3526, z = 6, stackpos = 1}
}

    for _, pos in ipairs(nodePositions) do
  
        local node = getTileThingByPos(pos).uid  
        local randnum = math.random(0,100)
      
        if randnum >= 1 and randnum <= 50 then
            doTransformItem(node, 22703) -- copper 50%
        elseif randnum >= 51 and randnum <= 75 then
            doTransformItem(node, 22709) -- silver 25%
        elseif randnum >= 76 and randnum <= 90 then
            doTransformItem(node, 22712) -- gold 15%
        elseif randnum >= 91 and randnum <= 100 then
            doTransformItem(node, 22706) -- mythril 10%
        end
    end
end

How to fix this problem so that not only the silver node gets generated? Thanks!
 
Add math.randomseed(os.time()) below onStartUp() :)
Question, if i add math.randomseed(os.time()) on startUp, does it mean all my math.random() functions are now actually randomized?
Or I still have to run that line on each script where I feel necessary?
 
Back
Top