Hello!
Yesterday I was doing a script that was needed to round off numbers to whole numbers. I tried to use math.Round or math.round, they both did'nt work with our tfs version today. So i decided to make the math.round function working.
math.Round rounds off the number to a whole number. For example: 0.3 becomes 0 and 0.6 becomes 1.
Put this at: .../data/lib/050-function.lua
So here is an example how to use it:
So it heals whole numbers always.
This is why you need to use this function. You don't want to see 625,3 above you when you heal. Tibia does'nt even use decimals as heal or damage. So it is unnecessary to heal or damage 0.3-
Thanks and enjoy!
Yesterday I was doing a script that was needed to round off numbers to whole numbers. I tried to use math.Round or math.round, they both did'nt work with our tfs version today. So i decided to make the math.round function working.
math.Round rounds off the number to a whole number. For example: 0.3 becomes 0 and 0.6 becomes 1.
Put this at: .../data/lib/050-function.lua
Lua:
function math.Round(number)
if number >= 0 then
return math.floor(number+.5)
else
return math.ceil(number-.5)
end
end
So here is an example how to use it:
Lua:
function onUse(cid, item, frompos, item2, topos)
local heal = getCreatureHealth(cid) / 100 * 10
doCreatureAddHealth(cid, math.Round(heal)) -- If you example had 6253 HP, you would get 625,3 HP. But if you round it, you get 625 HP.
doSendAnimatedText(getCreaturePosition(cid), "".. math.Round(heal) .."", COLOR_GREEN) -- This is why you need to use this function. You don't want to see 625,3 above you when you heal. Tibia does'nt even use decimals as heal or damage. So it is not necessary to heal or damage 0.3-
doSendMagicEffect(getCreaturePosition(cid), 12)
doRemoveItem(item.uid, 1)
return true
end
So it heals whole numbers always.
This is why you need to use this function. You don't want to see 625,3 above you when you heal. Tibia does'nt even use decimals as heal or damage. So it is unnecessary to heal or damage 0.3-
Thanks and enjoy!
Last edited: