• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

C++ Classic Ammo Slot/Healing Mana show numbers

Solution
my bad

LUA:
local config = {
    [{1, 5}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{2, 6}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{3, 7}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{4, 8}] = { healAmount = {90, 250}, effect = 1, color = 210 }
}

function onCastSpell(player, variant, isHotkey)
    for v, c in pairs(config) do
        if table.contains(v, player:getVocation():getId()) then
            local pos = player:getPosition()
            local mana_add = math.random(c.healAmount[1], c.healAmount[2])
            player:addMana(mana_add)
            pos:sendMagicEffect(c.effect)
            Game.sendAnimatedText(mana_add, pos, c.color)
        end
    end...
Try this:

LUA:
local config = {
    [{1, 5}] = { healAmount = {90, 250}, effect = 1, color = 210 }
    [{2, 6}] = { healAmount = {90, 250}, effect = 1, color = 210 }
    [{3, 7}] = { healAmount = {90, 250}, effect = 1, color = 210 }
    [{4, 8}] = { healAmount = {90, 250}, effect = 1, color = 210 }
}

function onCastSpell(player, variant)
    for v, c in pairs(config) do
        if table.contains(v, player:getVocation():getId()) then
            local pos = player:getPosition()
            player:addMana(math.random(v.healAmount[1], v.healAmount[2]))
            pos:sendMagicEffect(v.effect)
            Game.sendAnimatedText(v.healAmount, pos, v.color)
        end
    end
    combat:execute(player, variant)
end
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/Custom/Manarune.lua:onCastSpell
data/spells/scripts/Custom/Manarune.lua:12: attempt to index field 'healAmount' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/Custom/Manarune.lua:12: in function <data/spells/scripts/Custom/Manarune.lua:8>
 
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/Custom/Manarune.lua:onCastSpell
data/spells/scripts/Custom/Manarune.lua:12: attempt to index field 'healAmount' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/Custom/Manarune.lua:12: in function <data/spells/scripts/Custom/Manarune.lua:8>
do the math random as separate variable e.g local myvariable = math.random(v.healthAmount[1],...
then in sendeffect do just do player:addHealth(myvariable)
..effect(variable...
Post automatically merged:

LUA:
local config = {
    [{1, 5}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{2, 6}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{3, 7}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{4, 8}] = { healAmount = {90, 250}, effect = 1, color = 210 },
}

function onCastSpell(player, variant)
    for v, c in pairs(config) do
        if table.contains(v, player:getVocation():getId()) then
            local pos = player:getPosition()
            
            -- Generate one random value for both healAmount and animated text
            local healAmount = math.random(c.healAmount[1], c.healAmount[2])
            
            player:addMana(healAmount)
            pos:sendMagicEffect(c.effect)
            Game.sendAnimatedText(tostring(healAmount), pos, c.color)
        end
    end
    combat:execute(player, variant)
end
 
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/Custom/Manarune.lua:onCastSpell
data/spells/scripts/Custom/Manarune.lua:12: attempt to index field 'healAmount' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/Custom/Manarune.lua:12: in function <data/spells/scripts/Custom/Manarune.lua:8>

my bad

LUA:
local config = {
    [{1, 5}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{2, 6}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{3, 7}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{4, 8}] = { healAmount = {90, 250}, effect = 1, color = 210 }
}

function onCastSpell(player, variant, isHotkey)
    for v, c in pairs(config) do
        if table.contains(v, player:getVocation():getId()) then
            local pos = player:getPosition()
            local mana_add = math.random(c.healAmount[1], c.healAmount[2])
            player:addMana(mana_add)
            pos:sendMagicEffect(c.effect)
            Game.sendAnimatedText(mana_add, pos, c.color)
        end
    end
    combat:execute(player, variant)
end

If I were you I would do this as action script
 
Last edited:
my bad

LUA:
local config = {
    [{1, 5}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{2, 6}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{3, 7}] = { healAmount = {90, 250}, effect = 1, color = 210 },
    [{4, 8}] = { healAmount = {90, 250}, effect = 1, color = 210 }
}

function onCastSpell(player, variant, isHotkey)
    for v, c in pairs(config) do
        if table.contains(v, player:getVocation():getId()) then
            local pos = player:getPosition()
            local mana_add = math.random(c.healAmount[1], c.healAmount[2])
            player:addMana(mana_add)
            pos:sendMagicEffect(c.effect)
            Game.sendAnimatedText(mana_add, pos, c.color)
        end
    end
    combat:execute(player, variant)
end
I found the solution it was exactly as I said (ManaChange) Function didnt have sendeffects in the game.cpp

I followed this gentleman solution and worked perfectly!
@Ramon Bernardo

The solution for coming people

Find in game cpp this code
C++:
int32_t realManaChange = targetPlayer->getMana();
targetPlayer->changeMana(manaChange);
realManaChange = targetPlayer->getMana() - realManaChange;

Add below it add this line

C++:
if (realManaChange > 0 && !targetPlayer->isInGhostMode()) {
    addAnimatedText(fmt::format("+{:d}", realManaChange), targetPlayer->getPosition(), TEXTCOLOR_DARKPURPLE);
}

dsadsadsa.webp


And thanks for everyone help for sacrficing their time for me @Gesior.pl @Marko999x @czouski @Mateus Robeerto
 
Solution
I found the solution it was exactly as I said (ManaChange) Function didnt have sendeffects in the game.cpp

I followed this gentleman solution and worked perfectly!
@Ramon Bernardo

The solution for coming people

Find in game cpp this code
C++:
int32_t realManaChange = targetPlayer->getMana();
targetPlayer->changeMana(manaChange);
realManaChange = targetPlayer->getMana() - realManaChange;

Add below it add this line

C++:
if (realManaChange > 0 && !targetPlayer->isInGhostMode()) {
    addAnimatedText(fmt::format("+{:d}", realManaChange), targetPlayer->getPosition(), TEXTCOLOR_DARKPURPLE);
}

View attachment 88271


And thanks for everyone help for sacrficing their time for me @Gesior.pl @Marko999x @czouski @Mateus Robeerto
great solution by doing this in c++ the thing will generally run more smooth and will not use lua so there will be no delay or unnecessary stream of extra data in the game with a lot of players you are saving a lot of memory here!
 
Back
Top