• 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+ I have weird Health/Mana bug with transforms

henkas

Well-Known Member
Joined
Jul 8, 2015
Messages
993
Solutions
5
Reaction score
55
Hi
so i dont exactly know how this bug works, but i noticed couple thinks so lets say my vocation has four transformations every transformation increase health and mana bar so the problem is when i die my health somehow increase randomly and mana drops to zero, and second think i'm not sure about this one. Its really hard to explain so i'll try my best lets say you have 200Hp with default and then you take some items that adds +100hp so now we have 300hp and then i type transform and transform add +200 so now i have 500hp, right? So now when i'm transformed lets say i want to take my item off so now it should be -100 and i should have 400 but the problem that i have 500 so its like if i add items that gives me hp i can bug my health. So i suppose i should show my transform system
Code:
function onSay(player, words, param)
    local kurwa_gdzie_jest_efekt = Position(player:getPosition().x + 1, player:getPosition().y, player:getPosition().z)
    local pid = player:getId()

    local TRANS = transform[player:getVocation():getId()]
   
    if not TRANS then
        player:sendCancelMessage("TRANSFORM ERROR 11. Vocation = " .. player:getVocation():getId() .. "") -- VOCATION NOT IN GLOBAL TABLE
        return false
    end
   
    if TRANS.newVoc == 0 then
        player:sendCancelMessage("You cannot transform.")
        return false
    end
   
    if player:getLevel() < TRANS.level then
        player:sendCancelMessage("You must reach level "..TRANS.level.." to transform.")
        return false
    end
    if player:getSoul() < TRANS.rage then
        player:sendCancelMessage("You need "..TRANS.rage.." to transform.")
        return false
    end

    local outfit = player:getOutfit()
    outfit.lookType = TRANS.looktype

    if TRANS.constant then
        player:setOutfit(outfit)
    else
        player:setOutfit(outfit, true)
    end

    player:addSoul(-TRANS.rage)
    player:setMaxHealth(player:getMaxHealth() + TRANS.addHealth)
    player:setMaxMana(player:getMaxMana() + TRANS.addMana)
    kurwa_gdzie_jest_efekt:sendMagicEffect(TRANS.effect)
    player:setVocation(TRANS.newVoc)
    player:save()
    return false
end
This is revert
Code:
local function removeExhaust(pid)
    exhaust_transform[pid] = nil
end

function onSay(player, words, param, channel)
    local pid = player:getId()
   
    if exhaust_transform[pid] ~= nil then
        return false
    end
   
    local TRANS = transform[player:getVocation():getId()]
   
    if not TRANS then
        player:sendCancelMessage("TRANSFORM ERROR 11. Vocation = " .. player:getVocation():getId() .. "") -- VOCATION NOT IN GLOBAL TABLE
        return false
    end
   
    if TRANS.fromVoc == 0 then
        player:sendCancelMessage("You cannot revert.")
        return false
    end

    for i = 1, TRANS.transform do
        player:setVocation(TRANS.fromVoc)
        TRANS = transform[player:getVocation():getId()]
        local outfit = player:getOutfit()
        outfit.lookType = TRANS.from_looktype
        if TRANS.constant then
            player:setOutfit(outfit)
        else
            player:setOutfit(outfit, false)
        end
        player:setMaxHealth(player:getMaxHealth() - TRANS.addHealth)
        player:setMaxMana(player:getMaxMana() - TRANS.addMana)
    end
    player:save()
   
    exhaust_transform[pid] = 1   
    addEvent(removeExhaust, 5 * 1000, pid)
    return false
end

bump

bump

bump

upupupup

bump

bump

bump
 
Last edited by a moderator:
Solution
Code:
1>..\src\luascript.cpp(2053): error C2039: 'luaPlayerGetBaseMaxHealth': is not a member of 'LuaScriptInterface'
1>  c:\users\animal\desktop\dragon ball nuo nulio\server\src\luascript.h(199): note: see declaration of 'LuaScriptInterface'
1>..\src\luascript.cpp(2053): error C2065: 'luaPlayerGetBaseMaxHealth': undeclared identifier
1>..\src\luascript.cpp(2054): error C2039: 'luaPlayerGetBaseMaxMana': is not a member of 'LuaScriptInterface'
1>  c:\users\animal\desktop\dragon ball nuo nulio\server\src\luascript.h(199): note: see declaration of 'LuaScriptInterface'
1>..\src\luascript.cpp(2054): error C2065: 'luaPlayerGetBaseMaxMana': undeclared identifier
1>..\src\luascript.cpp(7461): error C2039: 'luaPlayerGetBaseMaxHealth': is not a...
I'm not really sure how it works when you equip an item that gives you extra hp, so I will suggest this:

When adding hp and mana on the transform script you should instead of taking players maxhealth, take the players level * vocation hp gain.

So lets say the vocation KNIGHT gets 10 hp every level he gets, when you transform someone to knight you want to set his health to (BONUS + (level * knight_health_gain_per_level)), which can be achieved by this:

change
Lua:
player:setMaxHealth(player:getMaxHealth() - TRANS.addHealth)

to

Lua:
player:setMaxHealth((player:getVocation():getHealthGain() * player:getLevel()) + TRANS.addHealth)

(I assume when you equip an item that gives you extra hp it changes players maxhealth, because I never saw anything related to players:getBaseHealth() or something like that, but you could make it if its useful to you.)

This way you will use the real base health of the player, mind you if the player is already wearing an item that gives him health when transforming, he will have to re-equip it to gain the health bonus from the item if you don't manage that on the code.

Also, the revert method you are using, make sure the values on TRANS.addHealth are correct, you want that values to be positive since you are doing a subtraction. -> player:getMaxHealth() - TRANS.addHealth

if TRANS.addHealth is a negative number he will add health instead of remove :)

Also, if you have rookgard on the server, I'm pretty sure until you hit level 8 you get only 5 health per level, so if you reaaaally want this to be that accurate, you could take that in count, something like this:

(BONUS + ((level - 8) * knight_health_gain_per_level) + 185)

I think 185 is the health you have when you reach level 8 in rookgard, but also I can be more nerd than that, because the player can leave rookgard on level 10 so that would different... anyways, you get the point.

When you die, this is a part of the code in Player::death method.
C++:
manaMax = std::max<int32_t>(0, manaMax - vocation->getManaGain());

This is executed one time for each level the characters has lost on the death, so that could be why its getting you to 0 mana when you die, probably a wrong number you set to the managain on the vocation, or to the character mana itself.

I hope that helps.
 
Last edited:
I'm not really sure how it works when you equip an item that gives you extra hp, so I will suggest this:

When adding hp and mana on the transform script you should instead of taking players maxhealth, take the players level * vocation hp gain.

So lets say the vocation KNIGHT gets 10 hp every level he gets, when you transform someone to knight you want to set his health to (BONUS + (level * knight_health_gain_per_level)), which can be achieved by this:

change
Lua:
player:setMaxHealth(player:getMaxHealth() - TRANS.addHealth)

to

Lua:
player:setMaxHealth((player:getVocation():getHealthGain() * player:getLevel()) + TRANS.addHealth)

(I assume when you equip an item that gives you extra hp it changes players maxhealth, because I never saw anything related to players:getBaseHealth() or something like that, but you could make it if its useful to you.)

This way you will use the real base health of the player, mind you if the player is already wearing an item that gives him health when transforming, he will have to re-equip it to gain the health bonus from the item if you don't manage that on the code.

Also, the revert method you are using, make sure the values on TRANS.addHealth are correct, you want that values to be positive since you are doing a subtraction. -> player:getMaxHealth() - TRANS.addHealth

if TRANS.addHealth is a negative number he will add health instead of remove :)

Also, if you have rookgard on the server, I'm pretty sure until you hit level 8 you get only 5 health per level, so if you reaaaally want this to be that accurate, you could take that in count, something like this:

(BONUS + ((level - 8) * knight_health_gain_per_level) + 185)

I think 185 is the health you have when you reach level 8 in rookgard, but also I can be more nerd than that, because the player can leave rookgard on level 10 so that would different... anyways, you get the point.

When you die, this is a part of the code in Player::death method.
C++:
manaMax = std::max<int32_t>(0, manaMax - vocation->getManaGain());

This is executed one time for each level the characters has lost on the death, so that could be why its getting you to 0 mana when you die, probably a wrong number you set to the managain on the vocation, or to the character mana itself.

I hope that helps.
Hmmm its weird i did what u said but now when u transform, you gain hp and mana so thats fine, but then if u want to "revert - go back to previous form" hp stays like you are transformed so it should decrease my gained HP/MN when i revert to my previous form.
I think i dont have rookgard on my server. About death problem i think my mana is fine but i dont really know what u mean by that.
Code:
gainhp="5" gainmana="30"
 
HP gain from transfer is also change when you level up?

Code:
player:setMaxHealth(player:getMaxHealth() + (player:getLevel() * 30)) -- 30 is number of HP gain per transform level.
player:setMaxHealth(player:getMaxHealth() - (player:getLevel() * 30)) -- 30 is number of HP remove per transform level.
 
HP gain from transfer is also change when you level up?

Code:
player:setMaxHealth(player:getMaxHealth() + (player:getLevel() * 30)) -- 30 is number of HP gain per transform level.
player:setMaxHealth(player:getMaxHealth() - (player:getLevel() * 30)) -- 30 is number of HP remove per transform level.
No, stay the same. All transforms gain 5hp per level. Its only change how much health/mana add the exact form like example
Code:
transform = {
[1] =  {transform = 0, fromVoc = 0, newVoc = 5,  from_looktype = 2, looktype = 3, level = 50,  rage = 3, addHealth = 200, addMana = 150, effect = 79, aura = nil, constant = false}, first form, but gain the same hp per level
[5] =  {transform = 1, fromVoc = 1, newVoc = 36, from_looktype = 2, looktype = 5, level = 100, rage = 3, addHealth = 500, addMana = 500, effect = 79, aura = nil, constant = false}, second form, gain the same hp per level
 
show me your item function as well?
Example
Code:
    <item id="14341" article="a" name="Test Boots">
        <attribute key="description" value="defense and energy +15. HP/MP + 1500" />
        <attribute key="weight" value="2500" />
        <attribute key="armor" value="35" />
        <attribute key="skillfish" value="10"/>
        <attribute key="skillshield" value="10"/>
        <attribute key="maxhitpoints" value="1500"/>
        <attribute key="maxmanapoints" value="1500"/>
        <attribute key="slotType" value="feet" />
 
Example
Code:
    <item id="14341" article="a" name="Test Boots">
        <attribute key="description" value="defense and energy +15. HP/MP + 1500" />
        <attribute key="weight" value="2500" />
        <attribute key="armor" value="35" />
        <attribute key="skillfish" value="10"/>
        <attribute key="skillshield" value="10"/>
        <attribute key="maxhitpoints" value="1500"/>
        <attribute key="maxmanapoints" value="1500"/>
        <attribute key="slotType" value="feet" />

It feels like the item maxhealth is updating everytime you perform setMaxHealth function. This solution is only partial because it works only for one item :oops:

Lua:
function onSay(player, words, param)
    local kurwa_gdzie_jest_efekt = Position(player:getPosition().x + 1, player:getPosition().y, player:getPosition().z)
    local pid = player:getId()
    local TRANS = transform[player:getVocation():getId()]
  
    if not TRANS then
        player:sendCancelMessage("TRANSFORM ERROR 11. Vocation = " .. player:getVocation():getId() .. "") -- VOCATION NOT IN GLOBAL TABLE
        return false
    end
  
    if TRANS.newVoc == 0 then
        player:sendCancelMessage("You cannot transform.")
        return false
    end
  
    if player:getLevel() < TRANS.level then
        player:sendCancelMessage("You must reach level "..TRANS.level.." to transform.")
        return false
    end
    if player:getSoul() < TRANS.rage then
        player:sendCancelMessage("You need "..TRANS.rage.." to transform.")
        return false
    end
    local outfit = player:getOutfit()
    outfit.lookType = TRANS.looktype
    if TRANS.constant then
        player:setOutfit(outfit)
    else
        player:setOutfit(outfit, true)
    end

    local itemHpIncrease = 0
    local mySlot = player:getSlotItem(CONST_SLOT_FEET)
    if mySlot and mySlot:getId() == 14341 then -- ITEM ID
        itemHpIncrease = 1500 -- ITEM HP INCREASE
    end

    player:addSoul(-TRANS.rage)
    player:setMaxHealth(player:getMaxHealth() + TRANS.addHealth - itemHpIncrease)
    player:setMaxMana(player:getMaxMana() + TRANS.addMana)
    kurwa_gdzie_jest_efekt:sendMagicEffect(TRANS.effect)
    player:setVocation(TRANS.newVoc)
    player:save()
    return false
end
 
It feels like the item maxhealth is updating everytime you perform setMaxHealth function. This solution is only partial because it works only for one item :oops:

Lua:
function onSay(player, words, param)
    local kurwa_gdzie_jest_efekt = Position(player:getPosition().x + 1, player:getPosition().y, player:getPosition().z)
    local pid = player:getId()
    local TRANS = transform[player:getVocation():getId()]
 
    if not TRANS then
        player:sendCancelMessage("TRANSFORM ERROR 11. Vocation = " .. player:getVocation():getId() .. "") -- VOCATION NOT IN GLOBAL TABLE
        return false
    end
 
    if TRANS.newVoc == 0 then
        player:sendCancelMessage("You cannot transform.")
        return false
    end
 
    if player:getLevel() < TRANS.level then
        player:sendCancelMessage("You must reach level "..TRANS.level.." to transform.")
        return false
    end
    if player:getSoul() < TRANS.rage then
        player:sendCancelMessage("You need "..TRANS.rage.." to transform.")
        return false
    end
    local outfit = player:getOutfit()
    outfit.lookType = TRANS.looktype
    if TRANS.constant then
        player:setOutfit(outfit)
    else
        player:setOutfit(outfit, true)
    end

    local itemHpIncrease = 0
    local mySlot = player:getSlotItem(CONST_SLOT_FEET)
    if mySlot and mySlot:getId() == 14341 then -- ITEM ID
        itemHpIncrease = 1500 -- ITEM HP INCREASE
    end

    player:addSoul(-TRANS.rage)
    player:setMaxHealth(player:getMaxHealth() + TRANS.addHealth - itemHpIncrease)
    player:setMaxMana(player:getMaxMana() + TRANS.addMana)
    kurwa_gdzie_jest_efekt:sendMagicEffect(TRANS.effect)
    player:setVocation(TRANS.newVoc)
    player:save()
    return false
end
Thats bad because i have so much items that add hp/mn.
 
have you tried to add the item in movement.xml?
Code:
    <movevent event="Equip" itemid="2161" slot="necklace" function="onEquipItem" />
    <movevent event="DeEquip" itemid="2161" slot="necklace" function="onDeEquipItem" />
This is for amulets , try to add it for the item that you want to add and remove ( Equip - DeEquip )
 
have you tried to add the item in movement.xml?
Code:
    <movevent event="Equip" itemid="2161" slot="necklace" function="onEquipItem" />
    <movevent event="DeEquip" itemid="2161" slot="necklace" function="onDeEquipItem" />
This is for amulets , try to add it for the item that you want to add and remove ( Equip - DeEquip )
Yea my all items are in movement.xml
 
Maybe here is the problem ?
Code:
    player:save()
because you are saving the HP on 500 so it will stay 500 and it will keep the added 100 of the item and when the time of the transform remove it will remove only 200 so you got extra 100 HP i think this is your script and you know what i mean :p i think you should remove it and try it may work
 
mm, then does it revert only with command or it have exhaust?
i really can't understand this system its written function_Onsay and you said its item
Yea it revert only with command.
Maybe here is the problem ?
Code:
    player:save()
because you are saving the HP on 500 so it will stay 500 and it will keep the added 100 of the item and when the time of the transform remove it will remove only 200 so you got extra 100 HP i think this is your script and you know what i mean :p i think you should remove it and try it may work
Yea that makes sense. I'll try it out and let you know.
 
Yes i'm sure 200% It took me a lot of time to add all items in movements.xml
Example
Untitled.png
 
Back
Top