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

CreatureEvent [TFS 1.x] Auto adjust hp/mana/cap per level like CIP

E

Evil Puncker

Guest
script by jerryb1988 on github, posting it here in case anyone wants to use it:

just add the following code to your login.lua here

Lua:
-- Fix HP/Mana/Cap to match CIP, assume player left rook at level 8
    if player:getVocation():getId() == 0 then
        
        calchp = 5 * (player:getLevel() + 29)
        calcmana = 5 * (player:getLevel() + 10)
        calccap = 10 * (player:getLevel() + 39)
        
    elseif player:getVocation():getId() == 1 or player:getVocation():getId() == 5 then
        
        calchp = 5 * (player:getLevel() + 29)
        calcmana = 5 * ((6 * player:getLevel()) - (5 * 8) + 10)
        calccap = 10 * (player:getLevel() + 39)
        
    elseif player:getVocation():getId() == 2 or player:getVocation():getId() == 6 then
        
        calchp = 5 * (player:getLevel() + 29)
        calcmana = 5 * ((6 * player:getLevel()) - (5 * 8) + 10)
        calccap = 10 * (player:getLevel() + 39)
        
    elseif player:getVocation():getId() == 3 or player:getVocation():getId() == 7 then
        
        calchp = 5 * ((2 * player:getLevel()) - 8 + 29)
        calcmana = 5 * ((3 * player:getLevel())- (2 * 8) + 10)
        calccap = 10 * ((2 * player:getLevel()) - 8 + 39)
        
    elseif player:getVocation():getId() == 4 or player:getVocation():getId() == 8 then
        
        calchp = 5 *((3 * player:getLevel()) - (2 * 8) + 29)
        calcmana = 5 *(player:getLevel() + 10)
        calccap = 5 *((5 * player:getLevel()) - (5 * 8) + 94)
        
    end   

    if player:getMaxHealth() ~= calchp then
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Server detected your max health was wrongly set at " .. player:getMaxHealth() .. " and we adjusted it to " .. calchp .. " automatically.")
        player:setMaxHealth(calchp)
        player:addHealth(calchp)
    
    end
    
    if player:getMaxMana() ~= calcmana then
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Server detected your max mana was wrongly set at " .. player:getMaxMana() .. " and we adjusted it to " .. calcmana .. " automatically.")
        player:setMaxMana(calcmana)
        player:addMana(calcmana)
    
    end
    
    if player:getCapacity() ~= (calccap * 100) then
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Server detected your max capacity was wrongly set at " .. (player:getCapacity() / 100) .. " and we adjusted it to " .. calccap .. " automatically.")
        player:setCapacity(calccap * 100)
    
    end   
    
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "For level " .. player:getLevel() .. ", your max HP should be: " .. calchp .. " max mana should be: " .. calcmana .. " max cap should be: " .. calccap .. ".")


his words:
These formulas were taken from the tibia wiki. They assume that for any character with a vocation, that they left rookgaard at level 8 (so there will be no handicap). Their may be a better way to do this via hardcoding, but this was a quick and easy solution to characters having incorrect values when being bumped levels from the start. The cap is multiplied by 100 to accommodate for the double since items can weigh #.## I realize this will trigger unnecessarily for every login and could potentially create a performance hit on a large server, so this could also be something that could become a talk action like !fixme or something of the sorts. Feel free to incorporate however you deem it fits.

all credit to him;
 
Why not simplify it like
Lua:
local vocation = player:getVocation()
local level = player:getLevel()
local supposedhealth = 185 + (vocation:getHealthGain() * (level-8))
local supposedmana = 90 + (vocation:getManaGain() * (level-8))
local supposedcap = 47000 + (vocation:getCapacityGain() * (level-8))
if supposedhealth ~= player:getMaxHealth() then
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Server detected your max health was wrongly set at " .. player:getMaxHealth() .. " and we adjusted it to " .. supposedhealth .. " automatically.")
player:setMaxHealth(supposedhealth)
player:setHealth(supposedhealth)
end
if supposedhealth ~= player:getMaxMana() then
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Server detected your max mana was wrongly set at " .. player:getMaxMana() .. " and we adjusted it to " .. supposedmana .. " automatically.")
player:setMaxMana(supposedmana)
player:setMana(supposedmana)
end
if supposedcap ~= player:getCapacity() then
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Server detected your max capacity was wrongly set at " .. (player:getCapacity() / 100) .. " and we adjusted it to " .. supposedcap/100 .. " automatically.")
player:setCapacity(supposedcap)
end
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "For level " .. player:getLevel() .. ", your max HP should be: " .. supposedhealth .. " max mana should be: " .. supposedmana .. " max cap should be: " .. supposedcap .. ".")

It will also work if you have more promotions or new vocations with other health gain
 
Why not simplify it like
Lua:
local vocation = player:getVocation()
local level = player:getLevel()
local supposedhealth = 185 + (vocation:getHealthGain() * (level-8))
local supposedmana = 90 + (vocation:getManaGain() * (level-8))
local supposedcap = 47000 + (vocation:getCapacityGain() * (level-8))
if supposedhealth ~= player:getMaxHealth() then
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Server detected your max health was wrongly set at " .. player:getMaxHealth() .. " and we adjusted it to " .. supposedhealth .. " automatically.")
player:setMaxHealth(supposedhealth)
player:setHealth(supposedhealth)
end
if supposedhealth ~= player:getMaxMana() then
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Server detected your max mana was wrongly set at " .. player:getMaxMana() .. " and we adjusted it to " .. supposedmana .. " automatically.")
player:setMaxMana(supposedmana)
player:setMana(supposedmana)
end
if supposedcap ~= player:getCapacity() then
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Server detected your max capacity was wrongly set at " .. (player:getCapacity() / 100) .. " and we adjusted it to " .. supposedcap/100 .. " automatically.")
player:setCapacity(supposedcap)
end
player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "For level " .. player:getLevel() .. ", your max HP should be: " .. supposedhealth .. " max mana should be: " .. supposedmana .. " max cap should be: " .. supposedcap .. ".")

It will also work if you have more promotions or new vocations with other health gain

the solution by hirezu have this error on tfs 1.3 revscript sys..
error_setmana.png

anyways, the main script provided by @Evil Puncker is working.. at least show no errors for me ^^ thanks for the shared script!
 
Any chance to release for 0.X? @Hyresu @Evil Puncker I could do the replace of all functions, replacing player:getVocation for getPlayerVocation(cid) and so on, but don't really know if is the best way to optimize it for 0.X. This script is really usefull, thanks in advance!
 
Any chance to release for 0.X? @Hyresu @Evil Puncker I could do the replace of all functions, replacing player:getVocation for getPlayerVocation(cid) and so on, but don't really know if is the best way to optimize it for 0.X. This script is really usefull, thanks in advance!
don't worry there wont be any problem, just replace them and it will still work just fine
 
Back
Top