• 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 HealthGain and ManaGain

Fischturd

Member
Joined
Jan 30, 2023
Messages
26
Reaction score
5
GitHub
Fischturd
Good morning, Good afternoon and Good evening!

I recently started using this upgrade system: CreatureEvent - [TFS 1.3 / 1.4] Upgrade System (https://otland.net/threads/tfs-1-3-1-4-upgrade-system.264672/)
It peaked my interest and it has been pretty fun playing around with everything, it works very well.

I am using TFS 1.4

I tried adding a new enchant called ManaGain and HealthGain and it "worked" it would show the ManaGain and HealthGain on a item, however it didn't actually do anything though.. -sad trumpet-

I was doing something along the lines of this
Lua:
[56] = {
    name = "Health Gain",
    combatType = US_TYPES.CONDITION,
    condition = CONDITION_PARAM_HEALTHGAIN,
    VALUES_PER_LEVEL = 1,
    format = function(value)
      return "Health Gain +" .. value
    end,
    itemType = US_ITEM_TYPES.HELMET + US_ITEM_TYPES.ARMOR + US_ITEM_TYPES.LEGS + US_ITEM_TYPES.BOOTS + US_ITEM_TYPES.SHIELD
  },
  [57] = {
    name = "Mana Gain",
    combatType = US_TYPES.CONDITION,
    condition = CONDITION_PARAM_MANAGAIN,
    VALUES_PER_LEVEL = 1,
    format = function(value)
      return "Mana Gain +" .. value
    end,
    itemType = US_ITEM_TYPES.HELMET + US_ITEM_TYPES.ARMOR + US_ITEM_TYPES.LEGS + US_ITEM_TYPES.BOOTS + US_ITEM_TYPES.SHIELD
  }

It prints on the items mana and health gain.. but like I said did not contribute to the vocations.xml ManaGain and HealthGain values

I guess has anybody had experience and successful implementation of creating this condition into the upgrade system?

Any guidance is appreciated!

Thank you for reading,
Fischturd
 
Last edited:
hp/mana gain is hardcoded and is always taken from vocation config

C++:
    while (experience >= nextLevelExp) {
        ++level;
        healthMax += vocation->getHPGain();
        health += vocation->getHPGain();
        manaMax += vocation->getManaGain();
        mana += vocation->getManaGain();
        capacity += vocation->getCapGain();

        currLevelExp = nextLevelExp;
        nextLevelExp = Player::getExpForLevel(level + 1);
        if (currLevelExp >= nextLevelExp) {
            // player has reached max level
            break;
        }
    }

Without source edit you won't be able to modify HPGain/MPGain.
But you could instead handle these attributes in onAdvance event and modify there max HP/MP.
Lua:
player:setMaxHealth(maxHealth)
player:setMaxMana(maxMana)

XML:
<event type="advance" name="UpgradeSystemAdvance" script="upgrade_system_cs.lua" />

upgrade_system_cs.lua
Lua:
function onAdvance(player, skill, oldLevel, newLevel)
  return us_onAdvance(player, skill, oldLevel, newLevel)
end

upgrade_system_core.lua
Lua:
function us_onAdvance(player, skill, oldLevel, newLevel)
  if (skill ~= SKILL_LEVEL) then
    return true
  end

  for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
    local item = player:getSlotItem(slot)
    if item then
      local values = item:getBonusAttributes()
      if values then
        for _, value in pairs(values) do
          local attr = US_ENCHANTMENTS[value[1]] or {}
          if attr.name == 'Health Gain' then
            player:setMaxHealth(player:getMaxHealth() + value[2])
          end

          if attr.name == 'Mana Gain' then
            player:setMaxMana(player:getMaxMana() + value[2])
          end
        end
      end
    end
  end
  
  return true
end
Formula: I don't know how much mp/hp it needs to add, whether it's a percent or static bonus

Lua:
function us_onLogin(player)
  player:registerEvent("UpgradeSystemAdvance")

Anyway once you add some new attribute to this system you need to handle such attributes.
From what I see some of these attributes are distinguishable by name and have their handlers written in lua.
Some are executed in combat (onManaChange/onHealthChange/onKill) thanks to their config combatType & triggerType.

Are you even sure you want to do it that way, by changing hp/mana gain amount for players (while leveling)?
Sounds like something that players would abuse by transferring such items to noob chars to build character with more HP/MP.
 
hp/mana gain is hardcoded and is always taken from vocation config

C++:
    while (experience >= nextLevelExp) {
        ++level;
        healthMax += vocation->getHPGain();
        health += vocation->getHPGain();
        manaMax += vocation->getManaGain();
        mana += vocation->getManaGain();
        capacity += vocation->getCapGain();

        currLevelExp = nextLevelExp;
        nextLevelExp = Player::getExpForLevel(level + 1);
        if (currLevelExp >= nextLevelExp) {
            // player has reached max level
            break;
        }
    }

Without source edit you won't be able to modify HPGain/MPGain.
But you could instead handle these attributes in onAdvance event and modify there max HP/MP.
Lua:
player:setMaxHealth(maxHealth)
player:setMaxMana(maxMana)

XML:
<event type="advance" name="UpgradeSystemAdvance" script="upgrade_system_cs.lua" />

upgrade_system_cs.lua
Lua:
function onAdvance(player, skill, oldLevel, newLevel)
  return us_onAdvance(player, skill, oldLevel, newLevel)
end

upgrade_system_core.lua
Lua:
function us_onAdvance(player, skill, oldLevel, newLevel)
  if (skill ~= SKILL_LEVEL) then
    return true
  end

  for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
    local item = player:getSlotItem(slot)
    if item then
      local values = item:getBonusAttributes()
      if values then
        for _, value in pairs(values) do
          local attr = US_ENCHANTMENTS[value[1]] or {}
          if attr.name == 'Health Gain' then
            player:setMaxHealth(player:getMaxHealth() + value[2])
          end

          if attr.name == 'Mana Gain' then
            player:setMaxMana(player:getMaxMana() + value[2])
          end
        end
      end
    end
  end
 
  return true
end
Formula: I don't know how much mp/hp it needs to add, whether it's a percent or static bonus

Lua:
function us_onLogin(player)
  player:registerEvent("UpgradeSystemAdvance")

Anyway once you add some new attribute to this system you need to handle such attributes.
From what I see some of these attributes are distinguishable by name and have their handlers written in lua.
Some are executed in combat (onManaChange/onHealthChange/onKill) thanks to their config combatType & triggerType.

Are you even sure you want to do it that way, by changing hp/mana gain amount for players (while leveling)?
Sounds like something that players would abuse by transferring such items to noob chars to build character with more HP/MP.
Edit: i withdraw
 
hp/mana gain is hardcoded and is always taken from vocation config

C++:
    while (experience >= nextLevelExp) {
        ++level;
        healthMax += vocation->getHPGain();
        health += vocation->getHPGain();
        manaMax += vocation->getManaGain();
        mana += vocation->getManaGain();
        capacity += vocation->getCapGain();

        currLevelExp = nextLevelExp;
        nextLevelExp = Player::getExpForLevel(level + 1);
        if (currLevelExp >= nextLevelExp) {
            // player has reached max level
            break;
        }
    }

Without source edit you won't be able to modify HPGain/MPGain.
But you could instead handle these attributes in onAdvance event and modify there max HP/MP.
Lua:
player:setMaxHealth(maxHealth)
player:setMaxMana(maxMana)

XML:
<event type="advance" name="UpgradeSystemAdvance" script="upgrade_system_cs.lua" />

upgrade_system_cs.lua
Lua:
function onAdvance(player, skill, oldLevel, newLevel)
  return us_onAdvance(player, skill, oldLevel, newLevel)
end

upgrade_system_core.lua
Lua:
function us_onAdvance(player, skill, oldLevel, newLevel)
  if (skill ~= SKILL_LEVEL) then
    return true
  end

  for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
    local item = player:getSlotItem(slot)
    if item then
      local values = item:getBonusAttributes()
      if values then
        for _, value in pairs(values) do
          local attr = US_ENCHANTMENTS[value[1]] or {}
          if attr.name == 'Health Gain' then
            player:setMaxHealth(player:getMaxHealth() + value[2])
          end

          if attr.name == 'Mana Gain' then
            player:setMaxMana(player:getMaxMana() + value[2])
          end
        end
      end
    end
  end
 
  return true
end
Formula: I don't know how much mp/hp it needs to add, whether it's a percent or static bonus

Lua:
function us_onLogin(player)
  player:registerEvent("UpgradeSystemAdvance")

Anyway once you add some new attribute to this system you need to handle such attributes.
From what I see some of these attributes are distinguishable by name and have their handlers written in lua.
Some are executed in combat (onManaChange/onHealthChange/onKill) thanks to their config combatType & triggerType.

Are you even sure you want to do it that way, by changing hp/mana gain amount for players (while leveling)?
Sounds like something that players would abuse by transferring such items to noob chars to build character with more HP/MP.

Sorry just circling back to this, I see what you did there..
I forgot to mention this was not for max/hp/mp it was for the gainhpamount and gainmanaamount per tick.. so in vocations.xml you have
XML:
gainhpticks="4" gainhpamount="5" gainmanaticks="4" gainmanaamount="5"
This value will not change, it is hard-coded into the tick + hp or mana amount..

That is fine, I don't need the TICKS to change.. but I want to have you allowed to gainhpamount or gainmanaamount more with item rarity enchants

So example:
Leather Boots (Armor 1)
Health Recovery +5
Mana Recovery +5

That recovery will contribute/stack to the gainhpamount and gainmanaamount from the gainhptick/gainmanatick

So if we take the above XML code you you have base 5 hp/managain per tick.. with the leatherboots you would now have 10hp/mana per tick

Hope I explained good, sorry always type these so late... lol
 
Back
Top