• 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.X+ bad argument #2 to 'random' (interval is empty)

Svira

Active Member
Joined
Jan 27, 2008
Messages
268
Solutions
11
Reaction score
36
Hello, I have the following problem:
Lua:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/stats.lua:onHealthChange
data/stats.lua:1573: bad argument #2 to 'random' (interval is empty)
I paste the script below, maybe you can see the solution. (from 1573)
Code:
local hp_d = math.random(1, math.floor(math.random(0, tonumber(cur_slots[i][2]))))
if hp_d > 0 then
doTargetCombatHealth(aid, cid, COMBAT_LIFEDRAIN, -hp_d, -hp_d, CONST_ME_MAGIC_RED)
attacker:addHealth(hp_d)
end

its TFS 1.2
 
Code:
hp_d

for this reason this part is not transferred
Lua:
doTargetCombatHealth(aid, cid, COMBAT_LIFEDRAIN, -hp_d, -hp_d, CONST_ME_MAGIC_RED)
attacker:addHealth(hp_d)
 
Lua:
local maxDrain = tonumber(cur_slots[i][2])
                                                if maxDrain ~= nil then
                                                    local hp_d = math.random(1, math.floor(math.random(0, maxDrain)))
                                                
                                                    if hp_d > 0 then
                                                        doTargetCombatHealth(aid, cid, COMBAT_LIFEDRAIN, -hp_d, -hp_d, CONST_ME_MAGIC_RED)
                                                        attacker:addHealth(hp_d)

solved
 
Lua:
local maxDrain = tonumber(cur_slots[i][2])
                                                if maxDrain ~= nil then
                                                    local hp_d = math.random(1, math.floor(math.random(0, maxDrain)))
                                             
                                                    if hp_d > 0 then
                                                        doTargetCombatHealth(aid, cid, COMBAT_LIFEDRAIN, -hp_d, -hp_d, CONST_ME_MAGIC_RED)
                                                        attacker:addHealth(hp_d)

solved
No, not solved. You didn't get error because math.random(0, maxDrain) returned number higher than 0 however this is still possible to return 0 and you will get same error again.
 
No, not solved. You didn't get error because math.random(0, maxDrain) returned number higher than 0 however this is still possible to return 0 and you will get same error again.
24h without error and works correctly.
is a function that takes% off of damage and grants it to the hp player, may be zero and have the value specified above.
 
Back
Top