• 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 Passive Leeching

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,470
Solutions
27
Reaction score
844
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi! I use TFS 1.5 by nekiro, and I wonder if someone can help me with this idea. I have a passive critical system on my server where players get a % of critical chance every 10 levels. This critical chance is not handled by sources, .lua is the way this works for my 8.6 server and this is the creaturescript that check the player hits.

Lua:
--[[
    Dodge & Critical fixado por Movie (Movie#4361)
    Disponibilizado para o TibiaKing e não autorizo outras reproduções
    Mantenha os créditos <3
--]]

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if (not attacker or not creature) then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if primaryType == COMBAT_HEALING then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    if (attacker:isPlayer() and (attacker:getCriticalLevel() * 3) >= math.random (0, 1000)) then
        primaryDamage = primaryDamage + math.ceil(primaryDamage * CRITICAL.PERCENT)
        creature:getPosition():sendMagicEffect(CONST_ME_WATERCREATURE)
    end

    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Lua:
--[[
    Dodge & Critical fixado por Movie (Movie#4361)
    Disponibilizado para o TibiaKing e não autorizo outras reproduções
    Mantenha os créditos <3
--]]

STORAGEVALUE_DODGE = 48900
STORAGEVALUE_CRITICAL = 48901

DODGE = {
    LEVEL_MAX = 100, -- máximo de level que o dodge será
    PERCENT = 0.2 -- porcentagem que irá defender o ataque
}

CRITICAL = {
    LEVEL_MAX = 100, -- máximo de level que o critical será
    PERCENT = 0.4 -- porcentagem que irá aumentar o ataque
}

function Player.getDodgeLevel(self)
    return self:getStorageValue(STORAGEVALUE_DODGE)
end

function Player.setDodgeLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_DODGE, value)
end

function Player.getCriticalLevel(self)
    return self:getStorageValue(STORAGEVALUE_CRITICAL)
end

function Player.setCriticalLevel(self, value)
    return self:setStorageValue(STORAGEVALUE_CRITICAL, value)
end

What I need is to convert the formula of this script to a "leeching" formula. Where player gets a % of health based on their hit damage. and only use .lua to achieve this. Is it possible? I will read your answers and see where all this goes. Thanks in advance!

Regards :)
 
Solution
Its basically the same concept
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType ~= COMBAT_HEALING then
        if (attacker and attacker:isPlayer() and (attacker:getLifeLeechLevel() * 3) >= math.random (0, 1000)) then
            if attacker:getHealth() < attacker:getMaxHealth() then
                local value = ((LIFE_LEECH.PERCENT * primaryDamage) / 100) * attacker:getLifeLeechLevel()
                attacker:addHealth(value)
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
Just add leech funcs/vars on lib
Its basically the same concept
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType ~= COMBAT_HEALING then
        if (attacker and attacker:isPlayer() and (attacker:getLifeLeechLevel() * 3) >= math.random (0, 1000)) then
            if attacker:getHealth() < attacker:getMaxHealth() then
                local value = ((LIFE_LEECH.PERCENT * primaryDamage) / 100) * attacker:getLifeLeechLevel()
                attacker:addHealth(value)
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
Just add leech funcs/vars on lib
 
Solution
Back
Top