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

Add Player 3% Mana per sec needed

Hashirama479

World of Ninja
Joined
Dec 19, 2016
Messages
536
Solutions
6
Reaction score
74
Yo I need a script which gives players 3% mana per sec and it should work forever also its shouldnt be like using a item = getting mana it should always heal doenst matter if you log off or what ever haha xD ( sorry if the script alredy exists but cant find it.... )
 
Editied. Works on every tfs, otx and few yurots
It's creaturescript, so remember to register in login.lua too.
Code:
-- Creaturescripts.xml: <event type="think" name="Healing" script="healing.lua"/>
-- login.lua: registerCreatureEvent(cid, "Healing")
-- for more ask andu @ otland.net

local config = {
    useTfsVersion1 = "no", -- use "yes" for tfs 1.0+ and otx 2.0+. For old tfs, and other engines use "no".
    inCombat = {
        healthPercent = 0.0,    -- % of max health
        manaPercent = 0.0    -- % of max mana
    },
    outOfCombat = {
        healthPercent = 15.0,    -- % of max health
        manaPercent = 7.5    -- % of max mana
    },
    energyGain = 10        -- melee/tank etc (in my server players what have exactly 100 mana are melee/tanks)
}

if config.useTfsVersion1 == "yes" then
    function hasCondition(cid, condition)
        local c = Creature(cid)
        return c ~= nil and c:getCondition(condition, CONDITIONID_DEFAULT) or false
    end
end

function onThink(cid, interval)
    if isPlayer(cid) == true then
        local hp, mp = 0, 0
        if hasCondition(cid, CONDITION_INFIGHT) == true then
            hp = config.inCombat.healthPercent
            mp = config.inCombat.manaPercent
        else
            hp = config.outOfCombat.healthPercent
            mp = config.outOfCombat.manaPercent
        end

        local hpheal, mpheal = getCreatureMaxHealth(cid)*(hp/100), getPlayerMaxMana(cid) * (mp / 100)

        if hpheal >= 1 and getCreatureHealth(cid) < getCreatureMaxHealth(cid) then
            doCreatureAddHealth(cid, hpheal)
        end
        if getPlayerMana(cid) < getPlayerMaxMana(cid) then
            if getPlayerMaxMana(cid) > 100 then
                if mpheal >= 1 then
                    doPlayerAddMana(cid, mpheal)
                end
            else
                doPlayerAddMana(cid, config.energyGain)    -- energy
            end
        end
    end
    return true
end
 
Last edited:
Ah I have two problems with the script

1. It shows the mana amount which has been added is it possible to remove? So it does not show as explain 1248 anymore

2. It even adds mana when you have alredy ur max mana xD
 
I would do a few changes:
If you have max mana or max health, don't do anything.
If you have more than 100% - configured%Regen, HP/MP, give yourself only max - current HP/MP.

Should be less stressful performance wise.
 
About the performance; Is better to use an onThink script like this one, or just create a regeneration condition and update the hp/mana ticks/amount as needed?
 
I would do a few changes:
If you have max mana or max health, don't do anything.
If you have more than 100% - configured%Regen, HP/MP, give yourself only max - current HP/MP.

Should be less stressful performance wise.
That's true. Changed.

About the performance; Is better to use an onThink script like this one, or just create a regeneration condition and update the hp/mana ticks/amount as needed?
Conditions doesn't have good support in sources. They loads before function so you can't use variables like cid. Unless you decide to make alot of conditions to match different players' max mana. This option will be memory absorbing.

@Hashirama479 I updated it to better match your needs. post
 
@Hashirama479 I updated it to better match your needs. post

Does not work here error from console -

f227fe20fb100de0954f20860d30590c.png

https://gyazo.com/f227fe20fb100de0954f20860d30590c

EDIT: and yes I did put no here
Code:
    useTfsVersion1 = "no" -- use "yes" for tfs 1.0+ and otx 2.0+. For old tfs, and other engines use "no".
xD
 
Last edited:
Creaturescript, remember to register in login.lua too.
Code:
-- Creaturescripts.xml: <event type="think" name="Healing" script="healing.lua"/>
-- login.lua: registerCreatureEvent(cid, "Healing")
-- for more ask andu @ otland.net

local config = {
    useTfsVersion1 = "yes" -- use "yes" for tfs 1.0+ and otx 2.0+. For old tfs, and other engines use "no".
    inCombat = {
        healthPercent = 0.0,    -- % of max health
        manaPercent = 0.0    -- % of max mana
    },
    outOfCombat = {
        healthPercent = 15.0,    -- % of max health
        manaPercent = 7.5    -- % of max mana
    },
    energyGain = 10        -- melee/tank etc (in my server players what have exactly 100 mana are melee/tanks)
}

function onThink(cid, interval)
    if isPlayer(cid) == true then
        local hp, mp, tfsv = 0, 0, false
        if useTfsVersion1 == "yes" then
            tfsv = cid:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT)
        else
            tfsv = hasCondition(cid, CONDITION_INFIGHT)
        end
        if tfsv == true then
            hp = config.inCombat.healthPercent
            mp = config.inCombat.manaPercent
        else
            hp = config.outOfCombat.healthPercent
            mp = config.outOfCombat.manaPercent
        end

        local hpheal, mpheal = getCreatureMaxHealth(cid)*(hp/100), getPlayerMaxMana(cid) * (mp / 100)

        if hpheal >= 1 and getCreatureHealth(cid) < getCreatureMaxHealth(cid) then
            doCreatureAddHealth(cid, hpheal)
        end
        if getPlayerMana(cid) < getPlayerMaxMana(cid) then
            if getPlayerMaxMana(cid) > 100 then
                if mpheal >= 1 then
                    doPlayerAddMana(cid, mpheal)
                end
            else
                doPlayerAddMana(cid, config.energyGain)    -- energy
            end
        end
    end
    return true
end

That variable tfsv is confusing. You should probably name it like "infight" or something.

Also I'd rather do like:
Code:
local valuesTable = infight and config.inCombat or config.outOfCombat
local hp = valuesTable.healthPercent
local mp = valuesTable.manaPercent

And the energyGain code should probably have been omitted considering this is something that exists only in your server.
 
Does not work here error from console -

f227fe20fb100de0954f20860d30590c.png

https://gyazo.com/f227fe20fb100de0954f20860d30590c

EDIT: and yes I did put no here
Code:
    useTfsVersion1 = "no" -- use "yes" for tfs 1.0+ and otx 2.0+. For old tfs, and other engines use "no".
xD
Code:
local mpGainPercent = 3

function onThink(interval)
    local players = getPlayersOnline()
    if (#players == 0) then
        return true
    end
    for i = 1, #players do
        local cid = getPlayerByNameWildcard(players[i])
        local maxMana = getCreatureMaxMana(cid)
        if getCreatureMana(cid) ~= maxMana then
            doPlayerAddMana(cid, maxMana * (mpGainPercent/100))
        end
    end
    return true
end

Code:
<globalevent name="mana regen" interval="1000" event="script" value="xxxxxxxx.lua"/>
 
@Xeraphus why

Your script is executing over 2000 functions per second on 500 players online server. With over 7 milions functions per hour. And forces server to do heavy job: in every second make and drop a table with 500 keys and 10k subkeys.

ezgif.com-2c1cf1f771.gif
 
Last edited:
@Xeraphus why

Your script is executing over 2000 functions per second on 500 players online server. With over 7 milions functions per hour.

ezgif.com-2c1cf1f771.gif
You want to jump from start to finish with no rise in performance? Ok here you go:

Code:
function onThink(interval)
end


It might be more less effective to use globalscripts onThink over creaturescripts onThink in this case, but not devastatingly. But aside from that, your code also "does something to all online players via lua" and "every tick get all online players" is also done, but by C++. Perhaps he uses an additional table compared to you etc but as I said this isn't devastating. Might not be great though but not as you say.
 
@Xeraphus why

Your script is executing over 2000 functions per second on 500 players online server. With over 7 milions functions per hour. And forces server to do heavy job: in every second make and drop a table with 500 keys and 10k subkeys.

ezgif.com-2c1cf1f771.gif
ok
my bad you're lightyears more advanced than me
 
Back
Top