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

Regeneration per sec/per two sec

legadoss

New Member
Joined
Jun 1, 2014
Messages
142
Reaction score
4
hello, how i can do this?

level 100 = 100hp/per sec
level 250 = 250hp/per sec
 
Solution
just for formula with vocation like knight have one formula and sorcerer have another one formula
try this
Lua:
local config = {
    -- [{min_level, max_level}] = regen per second
    [{100, 250}] = {
        -- [vocation id] = {formula}
        [1] = {lvl = 1, mlvl = 0.7},
        [2] = {lvl = 1, mlvl = 0.5},
        [3] = {lvl = 1, distance = 0.7},
        [4] = {lvl = 1, sword = 0.3, axe = 0.3, club = 0.3}
    },
    -- last max_level must be math.huge
    [{250, math.huge}] = {
        -- [vocation id] = {formula}
        [1] = {lvl = 1, mlvl = 0.7},
        [2] = {lvl = 1, mlvl = 0.5},
        [3] = {lvl = 1, distance = 0.7},
        [4] = {lvl = 1, sword = 0.3, axe = 0.3, club = 0.3}
    },
}

function onThink(interval...
Not sure which one you wanted.
Put either of these into whatever script you are wanting to use the 'regeneration' for.

from level A to B heal X amount.
Lua:
local level = getPlayerLevel(cid)
if level < 100 then
    return true
end

local heal_amount = 0
if level >= 100 and level <= 249 then
    heal_amount = 100
elseif level >= 250 then
    heal_amount = 250
end

local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
    return true
elseif current_health + heal_amount > max_health then
    heal_amount = max_health - current_health
end

doCreatureAddHealth(cid, heal_amount)
heal LEVEL amount
Lua:
local heal_amount = getPlayerLevel(cid)

local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
    return true
elseif current_health + heal_amount > max_health then
    heal_amount = max_health - current_health
end

doCreatureAddHealth(cid, heal_amount)
 
Not sure which one you wanted.
Put either of these into whatever script you are wanting to use the 'regeneration' for.

from level A to B heal X amount.
Lua:
local level = getPlayerLevel(cid)
if level < 100 then
    return true
end

local heal_amount = 0
if level >= 100 and level <= 249 then
    heal_amount = 100
elseif level >= 250 then
    heal_amount = 250
end

local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
    return true
elseif current_health + heal_amount > max_health then
    heal_amount = max_health - current_health
end

doCreatureAddHealth(cid, heal_amount)
heal LEVEL amount
Lua:
local heal_amount = getPlayerLevel(cid)

local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
    return true
elseif current_health + heal_amount > max_health then
    heal_amount = max_health - current_health
end

doCreatureAddHealth(cid, heal_amount)


Globalevent ?
And interval = 1 sec only when player food > 0

Thanks i try it later and reply again
 
@Xikini I get the same error as the threadstarter.
"Attempt to compare boolean with number".
This is the script I added to HealthRegeneration.lua


Lua:
local level = getPlayerLevel(cid)
if level < 100 then
    return true
end
local heal_amount = 0
if level >= 100 and level <= 249 then
    heal_amount = 100
elseif level >= 250 then
    heal_amount = 250
end
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
    return true
elseif current_health + heal_amount > max_health then
    heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)
---------






I added it into creaturescripts.xml
XML:
<event type="healthchange" name="HealthRegeneration" script="HealthRegeneration.lua" />
The lua file HealthRegeneration.Lua is in the creaturescripts/scripts folder.
 
Last edited:
Not sure which one you wanted.
Put either of these into whatever script you are wanting to use the 'regeneration' for.

from level A to B heal X amount.
Lua:
local level = getPlayerLevel(cid)
if level < 100 then
    return true
end

local heal_amount = 0
if level >= 100 and level <= 249 then
    heal_amount = 100
elseif level >= 250 then
    heal_amount = 250
end

local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
    return true
elseif current_health + heal_amount > max_health then
    heal_amount = max_health - current_health
end

doCreatureAddHealth(cid, heal_amount)
heal LEVEL amount
Lua:
local heal_amount = getPlayerLevel(cid)

local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
    return true
elseif current_health + heal_amount > max_health then
    heal_amount = max_health - current_health
end

doCreatureAddHealth(cid, heal_amount)
Show full script, and picture of console?

I use this
Lua:
local level = getPlayerLevel(cid)
if level < 100 then
    return true
end
local heal_amount = 0
if level >= 100 and level <= 249 then
    heal_amount = 100
elseif level >= 250 then
    heal_amount = 250
end
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
    return true
elseif current_health + heal_amount > max_health then
    heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)

At GlobalEvent with interval 6000
 
@Xikini I get the same error as the threadstarter.
"Attempt to compare boolean with number".
This is the script I added to HealthRegeneration.lua



local level = getPlayerLevel(cid)
if level < 100 then
return true
end
local heal_amount = 0
if level >= 100 and level <= 249 then
heal_amount = 100
elseif level >= 250 then
heal_amount = 250
end
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
return true
elseif current_health + heal_amount > max_health then
heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)

---------






I added it into creaturescripts.xml
<event type="healthchange" name="HealthRegeneration" script="HealthRegeneration.lua" />

The lua file HealthRegeneration.Lua is in the creaturescripts/scripts folder.

I use this
Lua:
local level = getPlayerLevel(cid)
if level < 100 then
    return true
end
local heal_amount = 0
if level >= 100 and level <= 249 then
    heal_amount = 100
elseif level >= 250 then
    heal_amount = 250
end
local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
if current_health == max_health then
    return true
elseif current_health + heal_amount > max_health then
    heal_amount = max_health - current_health
end
doCreatureAddHealth(cid, heal_amount)

At GlobalEvent with interval 6000

Oh, that's because you both are supposed to add it to an existing script, not use the partial script as-is.
If you want it specifically for a global event, I suppose you can loop through all of the players online to grab the cid's of everyone based on an interval.

something like this. (0.4 interval is in seconds I think, so set 2000 to 2 instead)
XML:
<globalevent name="regen" interval="2000" event="script" value="regen.lua"/>
Lua:
function onThink(cid, interval, lastExecution)
    for _, cid in ipairs(getPlayersOnline()) do
   
        local level = getPlayerLevel(cid)
        if level < 100 then
            return true
        end
       
        local heal_amount = 0
        if level >= 100 and level <= 249 then
            heal_amount = 100
        elseif level >= 250 then
            heal_amount = 250
        end
       
        local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
        if current_health < max_health then
            if current_health + heal_amount > max_health then
                heal_amount = max_health - current_health
            end
            doCreatureAddHealth(cid, heal_amount)
        end
    end
    return true
end
 
Last edited:
Oh, that's because you both are supposed to add it to an existing script, not use the partial script as-is.
If you want it specifically for a global event, I suppose you can loop through all of the players online to grab the cid's of everyone based on an interval.

something like this. (0.4 interval is in seconds I think, so set 2000 to 2 instead)
XML:
<globalevent name="regen" interval="2000" event="script" value="regen.lua"/>
Lua:
function onThink(cid, interval, lastExecution)
    for _, cid in ipairs(getPlayersOnline()) do
 
        local level = getPlayerLevel(cid)
        if level < 100 then
            return true
        end
    
        local heal_amount = 0
        if level >= 100 and level <= 249 then
            heal_amount = 100
        elseif level >= 250 then
            heal_amount = 250
        end
    
        local current_health, max_health = getCreatureHealth(cid), getCreatureMaxHealth(cid)
        if current_health < max_health then
            if current_health + heal_amount > max_health then
                heal_amount = max_health - current_health
            end
            doCreatureAddHealth(cid, heal_amount)
        end
    end
    return true
end


I think its working now, with your finishing addition to the top of the script and adding it to globalevents instead of creaturescripts has left me with no error :)!

I have not tried it out ingame yet but I believe it work because I understand your lua code. Thank you!

EDIT: I tried using a char ingame with lvl 250 and there was no health regen at all. Your script looks like it should work, but it doesn't for my server =/ There's no errors but there is no regen.
 
Last edited:
I think its working now, with your finishing addition to the top of the script and adding it to globalevents instead of creaturescripts has left me with no error :)!

I have not tried it out ingame yet but I believe it work because I understand your lua code. Thank you!

EDIT: I tried using a char ingame with lvl 250 and there was no health regen at all. Your script looks like it should work, but it doesn't for my server =/ There's no errors but there is no regen.
Like I said in my previous post, if you are using tfs 0.4, it does interval in seconds.
2000 seconds = 33.3 minutes (ultra slow regen. :rolleyes:)
Change interval to something lower. (like 2)
 
I'm using TFS 1.2 not 0.4 actually. Is there a need for a totally different script? I tried with 2000 and with 2.
I'm not sure.
Usually the older scripts work on tfs 1.x with no problems.
Not sure what you'd need to change.
 
made it configurable so you can add more regens for different level ranges, comments in config should explain how you add new ones

save this as regen.lua in data/globalevents/scripts
Lua:
local config = {
    -- [{min_level, max_level}] = regen per second
    [{100, 250}] = 100,
    -- last max_level must be math.huge
    [{250, math.huge}] = 250
}

function onThink(interval, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        for range, regen in pairs(config) do
            local level = player:getLevel()
            -- level matches between range found from config
            if level >= range[1] and level < range[2] then
                player:addHealth(regen)
                break
            end
        end
    end
    return true
end

add this in globalevents.xml
XML:
<globalevent name="regen" interval="1000" script="regen.lua" />
 
Last edited:
made it configurable so you can add more regens for different level ranges, comments in config should explain how you add new ones

save this as regen.lua in data/globalevents/scripts
Lua:
local config = {
    -- [{min_level, max_level}] = regen per second
    [{100, 250}] = 100,
    -- last max_level must be math.huge
    [{250, math.huge}] = 250
}

function onThink(interval, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        for range, regen in pairs(config) do
            local level = player:getLevel()
            -- level matches between range found from config
            if level >= range[1] and level < range[2] then
                player:addHealth(regen)
                return
            end
        end
    end
end

add this in globalevents.xml
XML:
<globalevent name="regen" interval="1000" script="regen.lua" />
I think you can't use return, otherwise it will only heal the first person it finds.
maybe I'm wrong though ¯\_(ツ)_/¯
 
made it configurable so you can add more regens for different level ranges, comments in config should explain how you add new ones

save this as regen.lua in data/globalevents/scripts
Lua:
local config = {
    -- [{min_level, max_level}] = regen per second
    [{100, 250}] = 100,
    -- last max_level must be math.huge
    [{250, math.huge}] = 250
}

function onThink(interval, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        for range, regen in pairs(config) do
            local level = player:getLevel()
            -- level matches between range found from config
            if level >= range[1] and level < range[2] then
                player:addHealth(regen)
                break
            end
        end
    end
end

add this in globalevents.xml
XML:
<globalevent name="regen" interval="1000" script="regen.lua" />


o_O I can see the scripting logic in this one too, but.. just like the last script, its not working and with no errors. Any other options? lol I'm using tfs 1.2

What version of tfs did you script this for? Because maybe I'll switch my ot server if its a higher version. I need to be able to script stuff.
 
Last edited:
made it configurable so you can add more regens for different level ranges, comments in config should explain how you add new ones

save this as regen.lua in data/globalevents/scripts
Lua:
local config = {
    -- [{min_level, max_level}] = regen per second
    [{100, 250}] = 100,
    -- last max_level must be math.huge
    [{250, math.huge}] = 250
}

function onThink(interval, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        for range, regen in pairs(config) do
            local level = player:getLevel()
            -- level matches between range found from config
            if level >= range[1] and level < range[2] then
                player:addHealth(regen)
                break
            end
        end
    end
end

add this in globalevents.xml
XML:
<globalevent name="regen" interval="1000" script="regen.lua" />
error:

Code:
[Error - GlobalEvents::think] Failed to executre event: PerLevelRegenHp
 
o_O I can see the scripting logic in this one too, but.. just like the last script, its not working and with no errors. Any other options? lol I'm using tfs 1.2

What version of tfs did you script this for? Because maybe I'll switch my ot server if its a higher version. I need to be able to script stuff.
my bad, edited the script in my previous post and it works now (i tested it)
 
not works, no error but no regen i set interval as 1 but my knight sample lvl7 no get health + 100 each sec
because you didn't edit the level ranges in the config, if you want it to work on your level 7 character you need to make a new range or edit the first level range minimum to level 1 like this
Lua:
local config = {
    -- [{min_level, max_level}] = regen per second
    [{1, 250}] = 100,
    -- last max_level must be math.huge
    [{250, math.huge}] = 250
}
 
Back
Top