• 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 Calculating required mana to next magic level

ond

Veteran OT User
Joined
Mar 24, 2008
Messages
2,775
Solutions
25
Reaction score
483
Location
Sweden
As the title implies, I need some help making a lua function that will return the mana needed for the next magic level.

Server: OTHire (Based on OTServ, Legacy)

Edit:

This solution works:
Lua:
function onSay(cid, param, words)

    local data = {
        [1] = 1.1,
        [2] = 1.1,
        [3] = 1.4,
        [4] = 3.0,
    }
   
    local voc = data[getPlayerVocation(cid)]
    if not voc or not voc + 4 then
        return false
    end

    local magicLevel = getPlayerMagLevel(cid)
    local mana = math.ceil(((1600 * math.pow(voc, magicLevel)) - getPlayerManaSpent(cid)) / getConfigValue('rate_mag'))
   
    doPlayerSendTextMessage(cid, 17, "Mana required for magic level " .. magicLevel + 1 .. ": " .. mana)
    return false
end
 
Last edited:
Code:
uint64_t Vocation::getReqMana(uint32_t magLevel)
{
auto it = cacheMana.find(magLevel);
if (it != cacheMana.end()) {
return it->second;
}
uint64_t reqMana = static_cast<uint64_t>(400 * std::pow<double>(manaMultiplier, static_cast<int32_t>(magLevel) - 1));
uint32_t modResult = reqMana % 20;
if (modResult < 10) {
reqMana -= modResult;
} else {
reqMana -= modResult + 20;
}
cacheMana[magLevel] = reqMana;
return reqMana;
}

You should reference this function for the formula
 
I can't finish it for you...

I have this script for TFS 1.1 by zbizu if want:

https://otland.net/threads/tfs-1-1-exp-mana-updated-to-1-1.228822/

Yeah, I saw. Still can't puzzle it together.

Code:
uint64_t Vocation::getReqMana(uint32_t magLevel)
{
auto it = cacheMana.find(magLevel);
if (it != cacheMana.end()) {
return it->second;
}
uint64_t reqMana = static_cast<uint64_t>(400 * std::pow<double>(manaMultiplier, static_cast<int32_t>(magLevel) - 1));
uint32_t modResult = reqMana % 20;
if (modResult < 10) {
reqMana -= modResult;
} else {
reqMana -= modResult + 20;
}
cacheMana[magLevel] = reqMana;
return reqMana;
}

You should reference this function for the formula

I am, but differently coded in OTHire.
 
Back
Top