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

Heal Flatnumber onAdvance level

freaked1

Active Member
Joined
Jan 30, 2008
Messages
486
Solutions
5
Reaction score
29
Location
Sweden
Hello, I wonder if someone can help me with an onAdvance to heal flat numbers on level instead of character "max health". This as I have a custom server with items that can be modified ingame, for example +hp/mana%.

to clarify: onAdvance that gives a specified number of health on advance instead of getCreatureMaxHealth.

TFS 1.1
Thanks in advance :)
 
Hello, I wonder if someone can help me with an onAdvance to heal flat numbers on level instead of character "max health". This as I have a custom server with items that can be modified ingame, for example +hp/mana%.

to clarify: onAdvance that gives a specified number of health on advance instead of getCreatureMaxHealth.

TFS 1.1
Thanks in advance :)
Code:
local heal = {
    health = 100,
    mana = 100
}

function onAdvance(player, skill, oldLevel, newLevel)
    if skill == SKILL_LEVEL then
        player:addHealth(heal.health)
        player:addMana(heal.mana)
    end
    return true
end
 
also you can use it by percent something like this:
Code:
local heal = {
    health = 10, -- 10%
    mana = 10 -- 10%
}

function onAdvance(player, skill, oldLevel, newLevel)
    local health = player:getMaxHealth() / 100 * heal.health -- I don't remember the correct function, please tell me if I'm wrong
    local mana = player:getMaxMana() / 100 * heal.mana -- I don't remember the correct function, please tell me if I'm wrong
    if skill == SKILL_LEVEL then
        player:addHealth(health)
        player:addMana(mana)
    end
    return true
end
 
Thanks guys! It is working great now :) Just had to change some things to player to cid and Player(cid).

Can I skip the "local player = Player(cid)"
and just go for "Player(cid):addHealth(heal.health)"
or if that local is needed, can I just put it above the function to make it look cleaner? :)

creaturescripts/scripts/advance.lua

Code:
local heal = {
    health = 99999,
    mana = 99999
}

function onAdvance(cid, skill, oldLevel, newLevel)
local player = Player(cid)
    if skill == SKILL_LEVEL then
        player:addHealth(heal.health)
        player:addMana(heal.mana)
    end
    return true
end

creaturescripts/creaturescripts.xml

Code:
<event type="advance" name="advance" script="advance.lua"/>

TFS 1.1 compatible if anyone needs.
Thanks once again! :)
 
Can I skip the "local player = Player(cid)"
and just go for "Player(cid):addHealth(heal.health)"
or if that local is needed, can I just put it above the function to make it look cleaner? :)
Yes you can but then you are creating a player each time you use Player(cid):addHealth Player(cid):addMana.
It would be equivalent to doing something like this.
Code:
local player1 = Player(cid)
local player2 = Player(cid)

player1:addHealth
player2:addMana
Although by using Player(cid) directly on the metamethod isn't creating any new variables you would still being calling the constructor twice instead of just 1 time by passing the return value to Player(cid) to player. This makes for a very poor programming habit.
 
Back
Top