• 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 Regen out of battle

Blasphemy

Well-Known Member
Joined
Jan 5, 2012
Messages
387
Reaction score
67
Hello every one, I need to make a script that enhances the mana/health regen when you are out of combat, such as this:


but I'm using TFS 1.2, anyone can help me?

thanks
 
test

I have doubt with addEvent funtion in 1.5
revscript

Lua:
local function Player.regenPercentageHealthOverTime(self, percentage, delay)


print("-------")
    if not self:isPlayer() then
        print("regen stopped. Player no longer exists.")
        return true
    end
    print(self:getName())
    if self:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        print("Regen is active.")
        local currentHealth = self:getHealth()
        local maxHealth = self:getMaxHealth()
        if currentHealth < maxHealth then
            local percentHealth = (maxHealth / 100) * percentage
            if currentHealth + percentHealth > maxHealth then
                percentHealth = maxHealth - currentHealth
            end

            self:addHealth(healthChange)
          
            print("Player recovered " .. percentHealth .. " health.")
        else
            print("Player is at max health. No healing provided.")
        end
    else
        print("Regen is in-active due to combat.")
    end
    addEvent(regenPercentageHealthOverTime, delay, percentage, delay)

end


local creatureEvent = CreatureEvent("creatureEventName")

function creatureEvent.onLogin(player)
    player.regenPercentageHealthOverTime(5, 5000)
    return true
end

creatureEvent:register()
 
test

I have doubt with addEvent funtion in 1.5
revscript

Lua:
local function Player.regenPercentageHealthOverTime(self, percentage, delay)


print("-------")
    if not self:isPlayer() then
        print("regen stopped. Player no longer exists.")
        return true
    end
    print(self:getName())
    if self:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        print("Regen is active.")
        local currentHealth = self:getHealth()
        local maxHealth = self:getMaxHealth()
        if currentHealth < maxHealth then
            local percentHealth = (maxHealth / 100) * percentage
            if currentHealth + percentHealth > maxHealth then
                percentHealth = maxHealth - currentHealth
            end

            self:addHealth(healthChange)
         
            print("Player recovered " .. percentHealth .. " health.")
        else
            print("Player is at max health. No healing provided.")
        end
    else
        print("Regen is in-active due to combat.")
    end
    addEvent(regenPercentageHealthOverTime, delay, percentage, delay)

end


local creatureEvent = CreatureEvent("creatureEventName")

function creatureEvent.onLogin(player)
    player.regenPercentageHealthOverTime(5, 5000)
    return true
end

creatureEvent:register()
nope :( i think because there's not "self" function on tfs 1.2
Post automatically merged:

I modified to look like TFS 1.2 one, but still not working
Code:
function regenPercentageHealthOverTime(creature, percentage, delay)


print("-------")
    if not creature:isPlayer() then
        print("regen stopped. Player no longer exists.")
        return true
    end
    print(creature:getName())
    if creature:getCondition(CONDITION_INFIGHT) then
        print("Regen is active.")
        local currentHealth = creature:getHealth()
        local maxHealth = creature:getMaxHealth()
        if currentHealth < maxHealth then
            local percentHealth = (maxHealth / 100) * percentage
            if currentHealth + percentHealth > maxHealth then
                percentHealth = maxHealth - currentHealth
            end

            creature:addHealth(healthChange)
          
            print("Player recovered " .. percentHealth .. " health.")
        else
            print("Player is at max health. No healing provided.")
        end
    else
        print("Regen is in-active due to combat.")
    end
    addEvent(regenPercentageHealthOverTime, delay, percentage, delay)

end


local creatureEvent = CreatureEvent("creatureEventName")

function creatureEvent.onLogin(player)
    regenPercentageHealthOverTime(5, 5000)
    return true
end

creatureEvent:register()
 
Last edited:
Try this:
Lua:
local config = {
    option = 1, -- Try using option 1, if it fails, try using option 2
    time = 5000, -- The character's life will be regenerated every 5 seconds
    percentage = 5, -- The character's health will be healed by 5 percent
    printTest = true,
}

function regenPercentageHealthOverTime(target)
    if isPlayer(target) then
        local player = Player(target)
        if player:isPlayer() then
            if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
                if config.printTest then
                    print("Regen is active.")
                end
                local currentHealth = player:getHealth()
                local maxHealth = player:getMaxHealth()
                if currentHealth < maxHealth then
                    local percentHealth = (maxHealth / 100) * config.percentage
                    if currentHealth + percentHealth > maxHealth then
                        percentHealth = maxHealth - currentHealth
                    end
                    player:addHealth(healthChange)
                    if config.printTest then
                        print("Player recovered " .. percentHealth .. " health.")
                    end
                else
                    if config.printTest then
                        print("Player is at max health. No healing provided.")
                    end
                end
            else
                if config.printTest then
                    print("Regen is in-active due to combat.")
                end
            end
            addEvent(regenPercentageHealthOverTime, config.time, player:getId())
        end
    end
end

local creatureEvent = CreatureEvent("creatureEventName")

function creatureEvent.onLogin(player)
    if config.option == 1 then
        regenPercentageHealthOverTime(player:getId())
    elseif config.option == 2 then
        regenPercentageHealthOverTime(player)
    else
        print("Choose between option 1 or option 2.")
    end
    return true
end

creatureEvent:register()
 
Try this:
Lua:
local config = {
    option = 1, -- Try using option 1, if it fails, try using option 2
    time = 5000, -- The character's life will be regenerated every 5 seconds
    percentage = 5, -- The character's health will be healed by 5 percent
    printTest = true,
}

function regenPercentageHealthOverTime(target)
    if isPlayer(target) then
        local player = Player(target)
        if player:isPlayer() then
            if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
                if config.printTest then
                    print("Regen is active.")
                end
                local currentHealth = player:getHealth()
                local maxHealth = player:getMaxHealth()
                if currentHealth < maxHealth then
                    local percentHealth = (maxHealth / 100) * config.percentage
                    if currentHealth + percentHealth > maxHealth then
                        percentHealth = maxHealth - currentHealth
                    end
                    player:addHealth(healthChange)
                    if config.printTest then
                        print("Player recovered " .. percentHealth .. " health.")
                    end
                else
                    if config.printTest then
                        print("Player is at max health. No healing provided.")
                    end
                end
            else
                if config.printTest then
                    print("Regen is in-active due to combat.")
                end
            end
            addEvent(regenPercentageHealthOverTime, config.time, player:getId())
        end
    end
end

local creatureEvent = CreatureEvent("creatureEventName")

function creatureEvent.onLogin(player)
    if config.option == 1 then
        regenPercentageHealthOverTime(player:getId())
    elseif config.option == 2 then
        regenPercentageHealthOverTime(player)
    else
        print("Choose between option 1 or option 2.")
    end
    return true
end

creatureEvent:register()
I appreciate it, but I already solved it by myself :D!
on sources, file conditions.cpp


Code:
bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interval)
{
    internalHealthTicks += interval;
    internalManaTicks += interval;

    if (creature->getZone() != ZONE_PROTECTION) {

        Condition* condition = creature->getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT); {
        if (condition) {
                if (internalHealthTicks >= healthTicks) {
                    internalHealthTicks = 0;
                    creature->changeHealth(healthGain);
                }

                if (internalManaTicks >= manaTicks) {
                    internalManaTicks = 0;
                    creature->changeMana(manaGain);
                }
            } else {

                if (internalHealthTicks >= healthTicks) {
                    internalHealthTicks = 0;
                    creature->changeHealth(healthGain * 3);
                }
                if (internalManaTicks >= manaTicks) {
                    internalManaTicks = 0;
                    creature->changeMana(manaGain * 3);
                }
            }
        }
    }

    return ConditionGeneric::executeCondition(creature, interval);
}
 
I appreciate it, but I already solved it by myself :D!
on sources, file conditions.cpp


Code:
bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interval)
{
    internalHealthTicks += interval;
    internalManaTicks += interval;

    if (creature->getZone() != ZONE_PROTECTION) {

        Condition* condition = creature->getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT); {
        if (condition) {
                if (internalHealthTicks >= healthTicks) {
                    internalHealthTicks = 0;
                    creature->changeHealth(healthGain);
                }

                if (internalManaTicks >= manaTicks) {
                    internalManaTicks = 0;
                    creature->changeMana(manaGain);
                }
            } else {

                if (internalHealthTicks >= healthTicks) {
                    internalHealthTicks = 0;
                    creature->changeHealth(healthGain * 3);
                }
                if (internalManaTicks >= manaTicks) {
                    internalManaTicks = 0;
                    creature->changeMana(manaGain * 3);
                }
            }
        }
    }

    return ConditionGeneric::executeCondition(creature, interval);
}
I know u solved but i think i found a problem,
Lua:
local creatureEvent = CreatureEvent("creatureEventName")
function creatureEvent.onLogin(player)
    if config.option == 1 then
        regenPercentageHealthOverTime(player:getId())
    elseif config.option == 2 then
        regenPercentageHealthOverTime(player)
    else
        print("Choose between option 1 or option 2.")
    end
    return true
end

creatureEvent:register()

this code aint working for tfs 1.2 because revscripts missing "creaturescripts" hook for revscripts. Hope that information will help in future to someone.
 
Back
Top