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

Tfs 1.2 On level up gives full hp/mana

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
870
Solutions
2
Reaction score
49
Hello,
so i cant figure it out how to give full hp and mana when you level up because now if you have items that gives health/mana, level up will gives only full base hp so sample
you have 250hp and items gives 5k so with level up it will restore 250hp, so have to make it restore that full 5250hp and mana
 
player:addHealth(player:getMaxHealth())
player:addMana(player:getMaxMana())
 
player:addHealth(player:getMaxHealth())
player:addMana(player:getMaxMana())
As far as i know default tfs 1.2 level up health restore is made in source so its not smart to create like this when there is functions running behind my back
Lua:
local config = {
    heal = true,
    save = true,
    effect = false
}

function onAdvance(player, skill, oldLevel, newLevel)
    if skill ~= SKILL_LEVEL or newLevel <= oldLevel then
        return true
    end

    if config.effect then
        player:getPosition():sendMagicEffect(math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
        player:say('LEVEL UP!', TALKTYPE_MONSTER_SAY)
    end

    if config.heal then
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
    end

    if config.save then
        player:save()
    end
    return true
end
So i need full tutorial how to remove it from source and then add in lua or how to do it in source instead of lua.
 
As far as i know default tfs 1.2 level up health restore is made in source so its not smart to create like this when there is functions running behind my back
Lua:
local config = {
    heal = true,
    save = true,
    effect = false
}

function onAdvance(player, skill, oldLevel, newLevel)
    if skill ~= SKILL_LEVEL or newLevel <= oldLevel then
        return true
    end

    if config.effect then
        player:getPosition():sendMagicEffect(math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
        player:say('LEVEL UP!', TALKTYPE_MONSTER_SAY)
    end

    if config.heal then
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
    end

    if config.save then
        player:save()
    end
    return true
end
So i need full tutorial how to remove it from source and then add in lua or how to do it in source instead of lua.
i think its not made in source, its only made in lua, try to remove this script and see if player will gain hp/mana after up level
 
i think its not made in source, its only made in lua, try to remove this script and see if player will gain hp/mana after up level
does anyone know what version cipsoft added this feature to their game?
As far as i can see in different threads people are talking about thats where level up mana health restore is made, but im not sure if its true or not because even without any onAdvance addHealth functions it still restore base health so if you think about it, it means its made in source

void Player::addExperience(Creature* source, uint64_t exp, bool sendText/* = false*/)
 
Comment out these lines, just a few lines up from where Sun referenced.
C++:
        health = healthMax;
        mana = manaMax;
Okay i did that. Thanks it works i have a last question
Lua:
local config = {
    heal = true,
    save = true,
    effect = false
}
Does save = true will cause any extra lag for server? Because it will save players every time they level up. But maybe im just over thinking.
 
Okay i did that. Thanks it works i have a last question
Lua:
local config = {
    heal = true,
    save = true,
    effect = false
}
Does save = true will cause any extra lag for server? Because it will save players every time they level up. But maybe im just over thinking.
Depends on the experience rate of the server and how often players will be leveling. Like some servers you'll go from level 8-30 in one kill and that will cause a lot of unnecessary saves. You could add an exhaustion to make sure they don't save too often. Here are these functions if you don't already have them:

Lua:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player.hasExhaustion(self, value)
    return self:getExhaustion(value) > 0
end
 
Depends on the experience rate of the server and how often players will be leveling. Like some servers you'll go from level 8-30 in one kill and that will cause a lot of unnecessary saves. You could add an exhaustion to make sure they don't save too often. Here are these functions if you don't already have them:

Lua:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player.hasExhaustion(self, value)
    return self:getExhaustion(value) > 0
end
Nah it goes from 1-2, but ofc there is missions that might gives exp so it might level up from 8-15 and similar range. I dont have it if it goes in player.lua
And how to use? Because as i understand it based on storage so that saving system have to be made in storage to
 
Nah it goes from 1-2, but ofc there is missions that might gives exp so it might level up from 8-15 and similar range. I dont have it if it goes in player.lua
And how to use? Because as i understand it based on storage so that saving system have to be made in storage to
Yeah it goes in lib/core/player.lua

You can either use it in the script like this:
Lua:
    if config.save and not player:hasExhaustion(8000) then
        player:save()
        player:setExhaustion(8000, 10 * 60) -- Uses seconds so this is 10 minutes
    end

Or using the same concept the function uses we can do it locally within script file like this:
Lua:
local config = {
    heal = true,
    save = true,
    effect = false,
    save_exhaust_time = 10 -- in minutes
}

save_exhaust = save_exhaust or {}

function onAdvance(player, skill, oldLevel, newLevel)
    if skill ~= SKILL_LEVEL or newLevel <= oldLevel then
        return true
    end

    if config.effect then
        player:getPosition():sendMagicEffect(math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
        player:say('LEVEL UP!', TALKTYPE_MONSTER_SAY)
    end

    if config.heal then
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
    end

    if config.save then
        local time = os.date()
        if not save_exhaust[player.uid] or save_exhaust[player.uid] <= time then
            player:save()
            save_exhaust[player.uid] = time + (save_exhaust_time * 60)
        end
    end
    return true
end
 
Yeah it goes in lib/core/player.lua

You can either use it in the script like this:
Lua:
    if config.save and not player:hasExhaustion(8000) then
        player:save()
        player:setExhaustion(8000, 10 * 60) -- Uses seconds so this is 10 minutes
    end

Or using the same concept the function uses we can do it locally within script file like this:
Lua:
local config = {
    heal = true,
    save = true,
    effect = false,
    save_exhaust_time = 10 -- in minutes
}

save_exhaust = save_exhaust or {}

function onAdvance(player, skill, oldLevel, newLevel)
    if skill ~= SKILL_LEVEL or newLevel <= oldLevel then
        return true
    end

    if config.effect then
        player:getPosition():sendMagicEffect(math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
        player:say('LEVEL UP!', TALKTYPE_MONSTER_SAY)
    end

    if config.heal then
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
    end

    if config.save then
        local time = os.date()
        if not save_exhaust[player.uid] or save_exhaust[player.uid] <= time then
            player:save()
            save_exhaust[player.uid] = time + (save_exhaust_time * 60)
        end
    end
    return true
end
Ok so added
Lua:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player.hasExhaustion(self, value)
    return self:getExhaustion(value) > 0
end
in player.lua
and posted that new code
save_exhaust_time = 10 -- in minutes
Thanks dude.
 
Back
Top