• 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!

Lua math issues XD

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,529
Solutions
1
Reaction score
85
Location
Portugal
hey, can some1 help me with this math?

I changed some lines on player events in TFS 1.2

everything Works fine except that I can't manage to get it showing correct "current" health

example:

HP: 1kk / 10kk <-- this is fine

but if player has less than 1kk hp but his max health is over 1kk the current health will display like

HP: 0kk / 10kk

I'm trying to make it do like for example if you have 800k/10kk

HP: 8kk / 10kk

HP: 800k / 10kk

HP: 80k/10kk

HP: 8k/10kk

HP: 800/10kk

HP: 8/10kk


Code:
    if thing:isCreature() then
        local str1k = "%s\nHP: %dk / %dk"
        local str1kk = "%s\nHP: %dkk / %dkk"
        if thing:getMaxMana() > 0 and thing:getMaxMana() < 1000000 then
            str = string.format("%s & MP: %dk / %dk", str1k, (thing:getMana()/1000), (thing:getMaxMana()/1000))
            print("1")
        else
            str = string.format("%s & MP: %dkk / %dkk", str1kk, (thing:getMana()/1000000), (thing:getMaxMana()/1000000))
            print("2")
        end
        if thing:getMaxHealth() > 0 and thing:getMaxHealth() < 1000000 then
            description = string.format(str1k, description, (thing:getHealth()/1000), (thing:getMaxHealth()/1000)) .. "."
            print("3")
        else
            description = string.format(str1kk, description, (thing:getHealth()/1000000), (thing:getMaxHealth()/1000000)) .. "."
            print("4")
        end
    end
 
Last edited:
Solution
Code:
if thing:isCreature() then
        local low = "%s\nHP: %d / %d"
        local low1 = "%s\nHP: %d / %dk"
        local low2 = "%s\nHP: %d / %dm"
     
        local str1k = "%s\nHP: %dk / %dk"
        local str1kk = "%s\nHP: %dk / %dm"
        local str2kk = "%s\nHP: %dm / %dm"
        if thing:getMaxMana() > 0 and thing:getMaxMana() < 1000000 then
            str = string.format("%s & MP: %dk / %dk", str1k, (thing:getMana()/1000), (thing:getMaxMana()/1000))
        else
            str = string.format("%s & MP: %dkk / %dm", str1kk, (thing:getMana()/1000000), (thing:getMaxMana()/1000000))
        end
     
        if thing:getMaxHealth() > 0 and thing:getMaxHealth() < 1000000 and thing:getHealth() > 1000 then
            description...
Code:
if thing:isCreature() then
        local low = "%s\nHP: %d / %d"
        local low1 = "%s\nHP: %d / %dk"
        local low2 = "%s\nHP: %d / %dm"
     
        local str1k = "%s\nHP: %dk / %dk"
        local str1kk = "%s\nHP: %dk / %dm"
        local str2kk = "%s\nHP: %dm / %dm"
        if thing:getMaxMana() > 0 and thing:getMaxMana() < 1000000 then
            str = string.format("%s & MP: %dk / %dk", str1k, (thing:getMana()/1000), (thing:getMaxMana()/1000))
        else
            str = string.format("%s & MP: %dkk / %dm", str1kk, (thing:getMana()/1000000), (thing:getMaxMana()/1000000))
        end
     
        if thing:getMaxHealth() > 0 and thing:getMaxHealth() < 1000000 and thing:getHealth() > 1000 then
            description = string.format(str1k, description, (thing:getHealth()/1000), (thing:getMaxHealth()/1000)) .. "."
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() > 1000000 and thing:getHealth() < 1000000 and thing:getHealth() > 1000 then
            description = string.format(str1kk, description, (thing:getHealth()/1000), (thing:getMaxHealth()/1000000)) .. "."
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() > 1000000 and thing:getHealth() > 1000000 then
            description = string.format(str2kk, description, (thing:getHealth()/1000000), (thing:getMaxHealth()/1000000)) .. "."
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() > 1000000 and thing:getHealth() < 1000 then
            description = string.format(low2, description, (thing:getHealth()), (thing:getMaxHealth()/1000000)) .. "."
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() > 1000 and thing:getMaxHealth() < 1000000 and thing:getHealth() < 1000 then
            description = string.format(low1, description, (thing:getHealth()), (thing:getMaxHealth()/1000)) .. "."
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() < 1000 and thing:getHealth() < 1000 then
            description = string.format(low, description, (thing:getHealth()), (thing:getMaxHealth())) .. "."
        end
    end

Sorry things got a little messy... Anyway it works, I tested it. Sorry that it took so long :p Enjoy! :)

wIMG3tU.png
VLrnFkK.png
mKPpqLW.png
h4vUI8T.png
 
Last edited:
Solution
thanks for your time :p

it's not working, it shows 0k, 10k, 100k, 1000k, 10000k instead of 1m, 10m, etc

I added prints to it's easier to test, it keeps printing 2 when my health is bigger than 1m and prints 1 if health is less than 1m

Code:
if thing:isCreature() then
        local low = "%s\nHP: %d / %d"
        local low1 = "%s\nHP: %d / %dk"
        local low2 = "%s\nHP: %d / %dm"
      
        local str1k = "%s\nHP: %dk / %dk"
        local str1kk = "%s\nHP: %dk / %dm"
        local str2kk = "%s\nHP: %dm / %dm"
        if thing:getMaxMana() > 0 and thing:getMaxMana() < 1000000 then
            str = string.format("%s & MP: %dk / %dk", str1k, (thing:getMana()/1000), (thing:getMaxMana()/1000))
        else
            str = string.format("%s & MP: %dkk / %dm", str1kk, (thing:getMana()/1000000), (thing:getMaxMana()/1000000))
        end
           -- player:setMaxHealth(999999999)
        if thing:getMaxHealth() > 0 and thing:getMaxHealth() < 1000000 then
            description = string.format(str1k, description, (thing:getHealth()/1000), (thing:getMaxHealth()/1000)) .. "."
            print("1")
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() > 1000000 and thing:getHealth() < 1000000 then
            description = string.format(str1k, description, (thing:getHealth()/1000), (thing:getMaxHealth()/1000000)) .. "."
            print("2")
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() > 1000000 and thing:getHealth() > 1000000 then
            description = string.format(str2kk, description, (thing:getHealth()/1000000), (thing:getMaxHealth()/1000000)) .. "."
            print("3")
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() > 1000000 and thing:getHealth() < 1000 then
            description = string.format(low2, description, (thing:getHealth()), (thing:getMaxHealth()/1000000)) .. "."
            print("4")
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() > 1000 and thing:getHealth() < 1000 then
            description = string.format(low2, description, (thing:getHealth()), (thing:getMaxHealth()/1000)) .. "."
            print("5")
        elseif thing:getMaxHealth() > 0 and thing:getMaxHealth() < 1000 and thing:getHealth() < 1000 then
            description = string.format(low, description, (thing:getHealth()), (thing:getMaxHealth())) .. "."
            print("6")
        end
    end
 
Back
Top