• 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...
work, thanks one question how to check if player food > 0 ?
add this in data/lib/core/player.lua
Lua:
function Player.getFood(self)
    local condition = self:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition then
        return condition:getTicks()
    end
    return 0
end
to check if player food is > 0:
Lua:
if player:getFood() > 0 then
    -- do something
end
 
add this in data/lib/core/player.lua
Lua:
function Player.getFood(self)
    local condition = self:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
    if condition then
        return condition:getTicks()
    end
    return 0
end
to check if player food is > 0:
Lua:
if player:getFood() > 0 then
    -- do something
end
thanks!! one more question how to add there also magiclevel?

like formule = (1 * level) + (3 * maglevel)
 
thanks!! one more question how to add there also magiclevel?

like formule = (1 * level) + (3 * maglevel)
for regeneration?
i thought you wanted it to be a flat rate
do you want it to be the config value + formula or just the formula?
 
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, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        for range, formulas in pairs(config) do
            local level = player:getLevel()
            -- level matches between range found from config
            if level >= range[1] and level < range[2] then
                local formula = formulas[player:getVocationId()]
                if formula then
                    local value = player:getLevel() * formula.lvl
                    if formula.mlvl then
                        value = value + (player:getMagicLevel() * formula.mlvl)
                    end
                    if formula.distance then
                        value = value + (player:getSkillLevel(SKILL_DISTANCE) * formula.distance)
                    end
                    if formula.sword then
                        value = value + (player:getSkillLevel(SKILL_SWORD) * formula.sword)
                    end
                    if formula.axe then
                        value = value + (player:getSkillLevel(SKILL_AXE) * formula.axe)
                    end
                    if formula.club then
                        value = value + (player:getSkillLevel(SKILL_CLUB) * formula.club)
                    end
                end 
                break
            end
        end
    end
    return true
end
 
Solution
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, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        for range, formulas in pairs(config) do
            local level = player:getLevel()
            -- level matches between range found from config
            if level >= range[1] and level < range[2] then
                local formula = formulas[player:getVocationId()]
                if formula then
                    local value = player:getLevel() * formula.lvl
                    if formula.mlvl then
                        value = value + (player:getMagicLevel() * formula.mlvl)
                    end
                    if formula.distance then
                        value = value + (player:getSkillLevel(SKILL_DISTANCE) * formula.distance)
                    end
                    if formula.sword then
                        value = value + (player:getSkillLevel(SKILL_SWORD) * formula.sword)
                    end
                    if formula.axe then
                        value = value + (player:getSkillLevel(SKILL_AXE) * formula.axe)
                    end
                    if formula.club then
                        value = value + (player:getSkillLevel(SKILL_CLUB) * formula.club)
                    end
                end
                break
            end
        end
    end
    return true
end
thanks very much :)
 
you added it in globalevents.xml?
using tfs 1.2 or 1.3?
Oh silly me, I only recopied the script, not the xml for globalevents.xml. Thanks! its working :D.

Do you know where can I find a logic script guide by the way? Someone showed me this one: otland/forgottenserver
But it doesn't have everything. It's not fully updated I think.
 
Oh silly me, I only recopied the script, not the xml for globalevents.xml. Thanks! its working :D.

Do you know where can I find a logic script guide by the way? Someone showed me this one: otland/forgottenserver
But it doesn't have everything. It's not fully updated I think.
logic isn't tfs-based, it's lua-based
if you're actually interested in learning how to script you should learn lua as a whole language instead of just limiting yourself to tfs
Lua 5.1 Reference Manual - contents
Programming in Lua (first edition)
this particular section of PIL will show you how "classes" work in lua and why newer tfs uses : and . symbols for functions
Programming in Lua : 16
 
Thanks. I understand the logic a lot more now and some lua regular.

I still would like to know the full TFS part though because I don't see "game." instruction anywhere and that seems to be what to use for a lot of code. and the player:addHealth otland/forgottenserver doesn't have all the commands apparently.. -.- where's :addHealth there? I had to learn it from you lol. I want the full list. Should I request a full list on a separate request thread?
 
Thanks. I understand the logic a lot more now and some lua regular.

I still would like to know the full TFS part though because I don't see "game." instruction anywhere and that seems to be what to use for a lot of code. and the player:addHealth otland/forgottenserver doesn't have all the commands apparently.. -.- where's :addHealth there? I had to learn it from you lol. I want the full list. Should I request a full list on a separate request thread?
otland/forgottenserver
Player inherits from Creature, so all Creature methods are usable on a Player instance
same goes for Monster, Monster inherits Creature methods because it's also a creature, NPCs do too
this conversation isn't related to this thread though so if you have more questions go to the otland discord here: Discord - Free voice and text chat for gamers
 
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, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        for range, formulas in pairs(config) do
            local level = player:getLevel()
            -- level matches between range found from config
            if level >= range[1] and level < range[2] then
                local formula = formulas[player:getVocationId()]
                if formula then
                    local value = player:getLevel() * formula.lvl
                    if formula.mlvl then
                        value = value + (player:getMagicLevel() * formula.mlvl)
                    end
                    if formula.distance then
                        value = value + (player:getSkillLevel(SKILL_DISTANCE) * formula.distance)
                    end
                    if formula.sword then
                        value = value + (player:getSkillLevel(SKILL_SWORD) * formula.sword)
                    end
                    if formula.axe then
                        value = value + (player:getSkillLevel(SKILL_AXE) * formula.axe)
                    end
                    if formula.club then
                        value = value + (player:getSkillLevel(SKILL_CLUB) * formula.club)
                    end
                end
                break
            end
        end
    end
    return true
end

I Test it today and got Error:
Screen_Shot_08-22-18_at_11.03_AM.png


script:
Lua:
local config = {
    -- [{min_level, max_level}] = regen per second
    [{1, 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, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        for range, formulas in pairs(config) do
            local level = player:getLevel()
            -- level matches between range found from config
            if level >= range[1] and level < range[2] then
                local formula = formulas[player:getVocationId()]
                if formula then
                    local value = player:getLevel() * formula.lvl
                    if formula.mlvl then
                        value = value + (player:getMagicLevel() * formula.mlvl)
                    end
                    if formula.distance then
                        value = value + (player:getSkillLevel(SKILL_DISTANCE) * formula.distance)
                    end
                    if formula.sword then
                        value = value + (player:getSkillLevel(SKILL_SWORD) * formula.sword)
                    end
                    if formula.axe then
                        value = value + (player:getSkillLevel(SKILL_AXE) * formula.axe)
                    end
                    if formula.club then
                        value = value + (player:getSkillLevel(SKILL_CLUB) * formula.club)
                    end
                end
                break
            end
        end
    end
    return true
end

i need also min max and use math.random its possible? i modifite it there


Lua:
local config = {
    -- [{min_level, max_level}] = regen per second
    [{1, 250}] = {
        -- [vocation id] = {formula}
        [1] = {min = 5, max = 10, lvlmul = 1, mlvlmul = 17},
        [2] = {min = 5, max = 10, lvlmul = 1, mlvlmul = 17},
        [3] = {min = 3, max = 7, lvlmul = 1, mlvlmul = 5},
        [4] = {min = 1, max = 5, lvlmul = 1, mlvlmul = 1}
    },
    -- 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, lastExecution)
    for _, player in pairs(Game.getPlayers()) do
        for range, formulas in pairs(config) do
            local level = player:getLevel()
            -- level matches between range found from config
            if level >= range[1] and level < range[2] then
                local formula = formulas[player:getVocationId()]
                if formula then
                    local value = player:getLevel() * formula.lvl
                    if formula.mlvl then
                        value = value + (player:getMagicLevel() * formula.mlvl)
                    end
                    if formula.distance then
                        value = value + (player:getSkillLevel(SKILL_DISTANCE) * formula.distance)
                    end
                    if formula.sword then
                        value = value + (player:getSkillLevel(SKILL_SWORD) * formula.sword)
                    end
                    if formula.axe then
                        value = value + (player:getSkillLevel(SKILL_AXE) * formula.axe)
                    end
                    if formula.club then
                        value = value + (player:getSkillLevel(SKILL_CLUB) * formula.club)
                    end
                end
                break
            end
        end
    end
    return true
end

finish formule:
Lua:
add_min = voc.min +(voc.lvmul*player:level)+(voc.mlvlmul* player:maglevel)
add_max = voc.max +(voc.lvmul*player:level)+(voc.mlvlmul*player:maglevel)
add = math.random(add_min,add_max)
 
change player:getVocationId() to player:getVocation():getId()
its possible but you're indexing the wrong thing
it's not voc.lvmul it's formula.lvmul after local formula
 
Back
Top