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

Solved Storage Issue (Max HP) [OTX3]

Crevasse

惡名昭彰
Joined
Jan 13, 2017
Messages
133
Solutions
15
Reaction score
85
Location
Washington, D.C.
~*~*SOLVED*~*~

I encountered an interesting problem when changing a player's max HP with equipment. I set Knight armor and Knight legs to increase the wearer's max HP by 20% (each) by adding the maxhitpointspercent attribute and then changing movements.xml. This works just fine, the issue comes when the player wearing the equipment relogs (or dies). Example:

My test character's base max HP is 100. I put on knight armor and knight legs, the max HP is now 140. I heal up with exura to get full HP. Then, I relog. When I log back in, the max HP is 140 (the bonus is still there) which is fine, but I'm not at full HP anymore, I'm at 120.

Something is wrong with storage somewhere and it isn't "saving" that the player has healed up to their new max HP. Wearing just one of the two (only K-legs or K-armor) doesn't have a problem. It's when I wear more than 1 item that modifies max HP that the problem arises.

Any help is greatly appreciated.
 
Last edited:
Solution
I need to reopen this, as there is a new issue i encountered. All characters on my account are fine, but when I use a different account the character instantly dies when it logs in. I guess I don't enough about storages to see what the problem is I thought it was working for all players
Lua:
    if player:getLastLoginSaved() > 0 then
        local hp = player:getStorageValue(5678)
        local chp = player:getHealth()
        if (hp ~= -1) then
            player:addHealth(hp - chp)
        end
        local mp = player:getStorageValue(5679)
        local cmp = player:getMana()
        if (mp ~= -1) then
            player:addMana(mp - cmp)
        end
    end
on logout do this

Code:
function onLogout(player)
    local playerId = player:getId()
    if nextUseStaminaTime[playerId] ~= nil then
        nextUseStaminaTime[playerId] = nil
    end
local hp = player:getHealth()
player:setStorageValue(5678, hp)
    return true
end

at the end of Login above the last return true
do this

Code:
local hp = player:getStorageValue(5678)
local chp = player:getHealth()
print(hp)
print(chp)
to see the values then we can do things

not tested

test it and post the values (printed in your console)
 
SOLVED thanks to @Il Knight by adding the following to the end of login.lua (right above the last return true):

Code:
if player:getLastLoginSaved() > 0 then
        local hp = player:getStorageValue(5678)
        local chp = player:getHealth()
        local mp = player:getStorageValue(5679)
        local cmp = player:getMana()
        player:addHealth(hp - chp)
        player:addMana(mp - cmp)
    end

And adding these lines to logout.lua (also right above the final return true):

Code:
local hp = player:getHealth()
player:setStorageValue(5678, hp)
local mp = player:getMana()
player:setStorageValue(5679, mp)

Thank you so much!
 
SOLVED thanks to @Il Knight by adding the following to the end of login.lua (right above the last return true):

Code:
if player:getLastLoginSaved() > 0 then
        local hp = player:getStorageValue(5678)
        local chp = player:getHealth()
        local mp = player:getStorageValue(5679)
        local cmp = player:getMana()
        player:addHealth(hp - chp)
        player:addMana(mp - cmp)
    end

And adding these lines to logout.lua (also right above the final return true):

Code:
local hp = player:getHealth()
player:setStorageValue(5678, hp)
local mp = player:getMana()
player:setStorageValue(5679, mp)

Thank you so much!
i thought the problem was that only 1 piece of eq was giving you max hp %, but you were having an issue not being max health when you relogged?
you dont even need variables for that
Lua:
function onLogin(player)
    player:addHealth(player:getMaxHealth())
    return true
end
 
Sorry man I had a hard time explaining the problem the way I worded it made it kind of confusing. But question though, if I just addHealth to maximum like in the way you just posted, won't that mean that anytime someone relogs they will just get max HP?
 
Sorry man I had a hard time explaining the problem the way I worded it made it kind of confusing. But question though, if I just addHealth to maximum like in the way you just posted, won't that mean that anytime someone relogs they will just get max HP?
yeah but thats what knight's code does too lol
except he used extra variables
 
yeah but thats what knight's code does too lol
except he used extra variables
Save the current hp when you log out on the storage 5678, then when the player log in, the hp is removed(the current hp) and the hp saved is added.
My code not heal to max hp.
 
Save the current hp when you log out on the storage 5678, then when the player log in, the hp is removed(the current hp) and the hp saved is added.
My code not heal to max hp.
still not exactly a real fix, sources probably don't update database with current health properly, oh well
 
Last edited:
I need to reopen this, as there is a new issue i encountered. All characters on my account are fine, but when I use a different account the character instantly dies when it logs in. I guess I don't enough about storages to see what the problem is I thought it was working for all players
 
I need to reopen this, as there is a new issue i encountered. All characters on my account are fine, but when I use a different account the character instantly dies when it logs in. I guess I don't enough about storages to see what the problem is I thought it was working for all players
Lua:
    if player:getLastLoginSaved() > 0 then
        local hp = player:getStorageValue(5678)
        local chp = player:getHealth()
        if (hp ~= -1) then
            player:addHealth(hp - chp)
        end
        local mp = player:getStorageValue(5679)
        local cmp = player:getMana()
        if (mp ~= -1) then
            player:addMana(mp - cmp)
        end
    end
 
Solution
Back
Top