• 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 TFS1.3 Life/Mana Leech makes the USER lose mana/hp against players

FeLiPe-Eduardo

New Member
Joined
Jun 3, 2015
Messages
38
Solutions
1
Reaction score
3
Hello at my server i have one rarity system based at this : [TFS 1.X] Rarity Rolls & Custom Attributes Library (https://otland.net/threads/tfs-1-x-rarity-rolls-custom-attributes-library.268888/)

Was made by @Leo32 but it was edited by a guy in the Discord who was helping me.

TFS1.3 OTServBR

And the script works perfectly, only mana/life leech is defective and only in pvp. against monsters works perfectly.




Code:
Lua:
-- Apply mana leech
                if manaleech ~= 0 then
                    local manatoadd = math.floor((manaleech / 100) * (primaryDamage + secondaryDamage))
                    local attackerpos = attacker:getPosition()
                    addEvent(manaLeechConcat, 5, attacker.uid, manatoadd)
                end
              
                -- Apply life leech
                if lifeleech ~= 0 then
                    local lifetoadd = math.floor((lifeleech / 100) * (primaryDamage + secondaryDamage))
                    local attackerpos = attacker:getPosition()
                    addEvent(lifeLeechConcat, 5, attacker.uid, lifetoadd)
                end

Lua:
-- Apply mana leech
                if manaleech ~= 0 and primaryType ~= COMBAT_HEALING and secondaryType ~= COMBAT_HEALING then
                    local manatoadd = math.floor((manaleech / 100) * (primaryDamage + secondaryDamage))
                    manaLeechConcat(attacker.uid, manatoadd)
                end
              
                -- Apply life leech
                if lifeleech ~= 0 and primaryType ~= COMBAT_HEALING and secondaryType ~= COMBAT_HEALING then
                    local lifetoadd = math.floor((lifeleech / 100) * (primaryDamage + secondaryDamage))
                    lifeLeechConcat(attacker.uid, lifetoadd)
                end

Both are in the same file, could this be a conflict?

If you need more files let me know.

FLP
 

Attachments

Last edited:
The parameter

"Attacker"

Is not shown where it is getting passed from, so there is no knowing if you are using a player or creature type variable.

Also,

Manaleechconcat, and lifeleechconcat are functions not shown here, which most likely hold the key to the reason it doesn't work, and if that's not it, then the key is in that attacker variable, where it's being called and passed to and from...
 
The parameter

"Attacker"

Is not shown where it is getting passed from, so there is no knowing if you are using a player or creature type variable.

Also,

Manaleechconcat, and lifeleechconcat are functions not shown here, which most likely hold the key to the reason it doesn't work, and if that's not it, then the key is in that attacker variable, where it's being called and passed to and from...

I will think of something to change this attacker parameter. I don't have much knowledge about this, I will have to do a little more research.

Lua:
-- Mana leech (individual amounts)
function manaLeechConcat(attackerid, manatoadd)
    -- Create player table if it doesn't exist
    if not manaleechBatched[attackerid] then
        manaleechBatched[attackerid] = {}
    end
    -- Run processManaleechBatch after 5ms
    if not manaleechBatched[attackerid].ReadyToCommit then
        addEvent(processManaleechBatch, 5, attackerid)
        manaleechBatched[attackerid].ReadyToCommit = true
    end
    -- Sum manaleech amounts together (10% for additional targets)
    manaleechBatched[attackerid].Mana = (manaleechBatched[attackerid].Mana or manatoadd) + ((10 / 100) * math.floor(manatoadd))
end


Lua:
-- Life leech (individual amounts)
function lifeLeechConcat(attackerid, lifetoadd)
    -- Create player table if it doesn't exist
    if not lifeleechBatched[attackerid] then
        lifeleechBatched[attackerid] = {}
    end
    -- Run processlifeleechBatch after 5ms
    if not lifeleechBatched[attackerid].ReadyToCommit then
        addEvent(processLifeleechBatch, 5, attackerid)
        lifeleechBatched[attackerid].ReadyToCommit = true
    end
    -- Sum lifeleech amounts together (10% for additional targets)
    lifeleechBatched[attackerid].Life = (lifeleechBatched[attackerid].Life or lifetoadd) + ((10 / 100) * math.floor(lifetoadd))
end

Do you need any more information ?

FLP
 
I didnt say you needed to change the attacker parameter, I just can't tell if it's a creature variable or player variable that is being passed.

This code seems rather complex, and honestly I have no idea why someone felt it necessary to create a table, why that is there, I'm clueless.

Unfortunately, yes, more information is definitely needed to find the root of the problem.

"Processlifeleechbatch"
"Processmanaleechbatch"

Those are two more functions I don't understand how they work.

If you could show me those two functions, and the very beginning of the first script you showed me, the one where attacker is first defined, that would be very helpful in trying to isolate the problem, however it's not a for sure thing I will be able to see and fix the problem, I haven't done any kind of work with 1.3, best I can do is try to make sense of the code and maybe offer a small rewrite that could possibly fix it.
 
I didnt say you needed to change the attacker parameter, I just can't tell if it's a creature variable or player variable that is being passed.

This code seems rather complex, and honestly I have no idea why someone felt it necessary to create a table, why that is there, I'm clueless.

Unfortunately, yes, more information is definitely needed to find the root of the problem.

"Processlifeleechbatch"
"Processmanaleechbatch"

Those are two more functions I don't understand how they work.

If you could show me those two functions, and the very beginning of the first script you showed me, the one where attacker is first defined, that would be very helpful in trying to isolate the problem, however it's not a for sure thing I will be able to see and fix the problem, I haven't done any kind of work with 1.3, best I can do is try to make sense of the code and maybe offer a small rewrite that could possibly fix it.


In the first topic I sent the files for the script, but I will send the files completely in pastebin, ok?

if you need anything from the source let me know. thank you very much for your interest in helping. 🥰

Lua:
-- Life leech (batched, makes AOE spells give single bulk amount)
function processLifeleechBatch(attackerid)
    -- Check if player is still in-game
    if Creature(attackerid) then
        local player = Creature(attackerid)
        local attackerpos = player:getPosition()
        local actualLifeAdd = math.floor(lifeleechBatched[attackerid].Life)
        -- Consume batched manaleech
        player:addHealth(lifeleechBatched[attackerid].Life)
        --player:sendTextMessage(MESSAGE_HEALED, "You leech ".. actualLifeAdd .. " life.")
    end
    -- Reset player table
    lifeleechBatched[attackerid] = nil
end


Lua:
-- Mana leech (batched, makes AOE spells give single bulk amount)
function processManaleechBatch(attackerid)
    -- Check if player is still in-game
    if Creature(attackerid) then
        local player = Creature(attackerid)
        local attackerpos = player:getPosition()
        local actualmanadd = math.floor(manaleechBatched[attackerid].Mana)
        -- Consume batched manaleech
        player:addMana(manaleechBatched[attackerid].Mana)
        --player:sendTextMessage(MESSAGE_HEALED, "You leech ".. actualmanadd .. " mana.")
    end
    -- Reset player table
    manaleechBatched[attackerid] = nil
end

Entire code :



FLP
 
Ok so, looking it over, I honestly see no reason as to why it would work with monsters and not players.

I suspect that the funtion "manaLeechConcat" or "manaLeechBatch" (as well as the lifeleech versions) are only being passed a monsters id. Which means its where the functions are placed, not an actual problem with the funtion.

It appears you are using this in a weapons system, so I assume that in the weapons folder you have some scripts for the attributes? Ones that activate on the event

OnUseWeapon()

Is that correct? Either way, Im %100 certain that the functions or any of the code you have showed me so far is not at fault, as it appears to have all the bases covered and even makes a "Creature" object from the attacker.uid. Which would and should work with both monsters and players as they both derive from Creature.

Yes, it has to be where the functions are being called from, please check your weapons folder for a script in there pertaining to this system.
 
actually, the more that i think about it
the likely issue is the DAMAGETYPE being wrong because of whatever he has done to the script.

put
Lua:
print(damage .. damagetype .. secondaryDamage .. secondaryType .. origin)
on the end of the mana/healthchange parts of the script and see if youre missing a DamageType or have a weird number there when leeching pvp:

if you want further help, you will need to post this part of your full customized script:

EDIT:
On further testing I believe it's actually..
The native mana leech triggering onManaChange

Test this theory by replacing this code:

Lua:
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if primaryType ~= 64 then -- Ignore mana potions
        primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
     
        -- Apply magic shield bonus, even if neutral source
        if creature:isPlayer() then
            local manashield = 0
            for i = 1,#checkweaponslots do
                if creature:getSlotItem(checkweaponslots[i]) ~= nil then
                    local slotitem = creature:getSlotItem(checkweaponslots[i])
                    local slotitemdesc = slotitem:getDescription()
                    if slotitemdesc:find "%[Mana Shield" then
                        manashield = manashield + tonumber(string.match(slotitemdesc, '%[Mana Shield: %+(%d+)%%%]'))
                    end
                end
            end
            if manashield ~= 0 then
                local shieldPercent = (100 - manashield)
                primaryDamage = (shieldPercent / 100) * primaryDamage
                secondaryDamage = (shieldPercent / 100) * secondaryDamage
            end
        end
     
    end
 
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

with just this:
Lua:
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    print(primaryDamage .. primaryType.. secondaryDamage .. secondaryType .. origin)

    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

post me the console output too
 
Last edited:
Ok so, looking it over, I honestly see no reason as to why it would work with monsters and not players.

local SorryDelayReply = ("Thanks for the help, sorry for the delay in replying. I'm still working on the project(my ot server), but these last few days I was busy with my personal work.") :p

On further testing I believe it's actually..
The native mana leech triggering onManaChange
Print(SorryDelayReply) :p

this code are correct and looks like the same that i already use.
if you want further help, you will need to post this part of your full customized script:
In this topic I have already put the complete code, I will send the part you requested, if anything else is missing, let me know.

Lua:
-- Apply condition
function rollCondition(player, item, slot)
    local attributes = {
         [1] = {"%[" .. stats[25].attribute.name .. ": ", CONDITION_PARAM_SKILL_SWORD}, -- "[Sword Skill: "
         [2] = {"%[" .. stats[26].attribute.name .. ": ", CONDITION_PARAM_SKILL_AXE},
         [3] = {"%[" .. stats[27].attribute.name .. ": ", CONDITION_PARAM_SKILL_CLUB},
         [4] = {"%[" .. stats[28].attribute.name .. ": ", CONDITION_PARAM_SKILL_MELEE},
         [5] = {"%[" .. stats[29].attribute.name .. ": ", CONDITION_PARAM_SKILL_DISTANCE},
         [6] = {"%[" .. stats[30].attribute.name .. ": ", CONDITION_PARAM_SKILL_SHIELD},
         [7] = {"%[" .. stats[31].attribute.name .. ": ", CONDITION_PARAM_STAT_MAGICPOINTS},
         [8] = {"%[" .. stats[32].attribute.name .. ": ", CONDITION_PARAM_STAT_MAXHITPOINTS},
         [9] = {"%[" .. stats[33].attribute.name .. ": ", CONDITION_PARAM_STAT_MAXMANAPOINTS},
        [10] = {"%[" .. stats[34].attribute.name .. ": ", CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, percent = true, absolute = true},
        [11] = {"%[" .. stats[35].attribute.name .. ": ", CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, percent = true, absolute = true},
        --[12] = {"%[" .. stats[11].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_CRITICALHITAMOUNT, percent = true, absolute = true},
        --[13] = {"%[" .. stats[10].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE, percent = true},
        --[14] = {"%[" .. stats[36].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_LIFELEECHCHANCE, percent = true},
        --[15] = {"%[" .. stats[37].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_LIFELEECHAMOUNT, percent = true, absolute = true},
        --[16] = {"%[" .. stats[38].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_MANALEECHCHANCE, percent = true},
        --[17] = {"%[" .. stats[39].attribute.name .. ": ", CONDITION_PARAM_SPECIALSKILL_MANALEECHAMOUNT, percent = true, absolute = true},
    }
    local itemDesc = item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
    for k = 1,#attributes do
        local skillBonus = 0 -- reset
        local attributeSearchValue = "%+(%d+)%]" -- "+10]"
        if attributes[k].percent ~= nil then
            attributeSearchValue = "%+(%d+)%%%]" -- "+10%]"
            if attributes[k].absolute ~= nil then
                skillBonus = 100 -- These conditions require absolutes (108%, 145% etc.)
            end
        end
        local attributeString = attributes[k][1] .. attributeSearchValue -- "%[Attack: %+(%d+)%]"
        if string.match(itemDesc, attributeString) ~= nil then -- "[Attack: +10]"
            local offset = (10 * k) + slot -- ((CONST_SLOT_LAST) * k) + slot
            local skillBonus = skillBonus + tonumber(string.match(itemDesc, attributeString)) -- Raw (%d+) value
            
            if player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, offset) == nil then
                local condition = Condition(CONDITION_ATTRIBUTES)
                condition:setParameter(CONDITION_PARAM_SUBID, offset)
                condition:setParameter(CONDITION_PARAM_TICKS, -1)
                condition:setParameter(attributes[k][2], skillBonus)
                player:addCondition(condition)
            else
                player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, offset)
            end
        end
    end
end


Entire code :

on the end of the mana/healthchange parts of the script and see if youre missing a DamageType or have a weird number there when leeching pvp:
Lua:
local rollHealth = CreatureEvent("rollHealth")
function rollHealth.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if primaryType ~= 128 then -- Ignore health potions
        primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
    end
    
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
rollHealth:register()

I'll be blunt, I'm not a programmer. I can create simple codes using other codes. But this code I can not understand anything, sorry. I can try some tests if you explain something to me or tell me what I have to research.

FLP
 
actually, the more that i think about it
the likely issue is the DAMAGETYPE being wrong because of whatever he has done to the script.

put
Lua:
print(damage .. damagetype .. secondaryDamage .. secondaryType .. origin)
on the end of the mana/healthchange parts of the script and see if youre missing a DamageType or have a weird number there when leeching pvp:

if you want further help, you will need to post this part of your full customized script:

EDIT:
On further testing I believe it's actually..
The native mana leech triggering onManaChange

Test this theory by replacing this code:

Lua:
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if primaryType ~= 64 then -- Ignore mana potions
        primaryDamage, primaryType, secondaryDamage, secondaryType, origin = statChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) -- This is for feeding both onHealthChange and onManaChange through the same damage/buff formula
    
        -- Apply magic shield bonus, even if neutral source
        if creature:isPlayer() then
            local manashield = 0
            for i = 1,#checkweaponslots do
                if creature:getSlotItem(checkweaponslots[i]) ~= nil then
                    local slotitem = creature:getSlotItem(checkweaponslots[i])
                    local slotitemdesc = slotitem:getDescription()
                    if slotitemdesc:find "%[Mana Shield" then
                        manashield = manashield + tonumber(string.match(slotitemdesc, '%[Mana Shield: %+(%d+)%%%]'))
                    end
                end
            end
            if manashield ~= 0 then
                local shieldPercent = (100 - manashield)
                primaryDamage = (shieldPercent / 100) * primaryDamage
                secondaryDamage = (shieldPercent / 100) * secondaryDamage
            end
        end
    
    end
 
    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

with just this:
Lua:
function onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    print(primaryDamage .. primaryType.. secondaryDamage .. secondaryType .. origin)

    return primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end

post me the console output too
ive got the same problem im trying to access the github link
 
ive got the same problem im trying to access the github link
now that i'm managing a project that is possibly becoming a official fansite, I've been removing OT related projects and repositories from my github.
sorry bud.
 
Back
Top