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

[request] LUA Script: Heal % of damage dealt

D

Deleted 224045

Guest
Hi, guys!
I'm making a weapon that heals 25% of the damage dealt to the target.

Here's the script:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_SKILL , 0, 0, 1.0, 0)

-- Holds the last health of the target
lastTargetHealth = 0

-- Gets the targets health
function getTargetHealth(cid)
    local target = getCreatureTarget(cid)
    local health = getCreatureHealth(target)
    return health
end


function onUseWeapon(cid, var)
    local currentTargetHealth = getTargetHealth(cid)
    local damage = lastTargetHealth - currentTargetHealth
  
    lastTargetHealth = currentTargetHealth
  
    -- To get around the first hit because lastTargetHealth = 0
    if (damage > 0)
        local addhealth = damage * 0.25
        doCreatureAddHealth(cid, addhealth)
        doSendAnimatedText(getPlayerPosition(cid), "+"..addhealth.."", TEXTCOLOR_GREEN)
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    end
  
    return doCombat(cid, combat, var)
end

Can't figure out what I'm doing wrong guys. Could someone help me out?

Edit: I'm using OTHire 0.0.3 (tibia client 7.72)
 
Solution
Try this one:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_SKILL , 0, 0, 1.0, 0)

function onUseWeapon(cid, var)
    local target = getCreatureTarget(cid)
    local first = getCreatureHealth(target)
    if doCombat(cid, combat, var) then
        local second = getCreatureHealth(target)
        local damage = first - second
        if damage > 0 then
            local addhealth = damage * 0.25
            doCreatureAddHealth(cid, addhealth)
            doSendAnimatedText(getPlayerPosition(cid), "+"..addhealth.."", TEXTCOLOR_GREEN)
            doSendMagicEffect(getThingPos(cid)...
Try this one:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_SKILL , 0, 0, 1.0, 0)

function onUseWeapon(cid, var)
    local target = getCreatureTarget(cid)
    local first = getCreatureHealth(target)
    if doCombat(cid, combat, var) then
        local second = getCreatureHealth(target)
        local damage = first - second
        if damage > 0 then
            local addhealth = damage * 0.25
            doCreatureAddHealth(cid, addhealth)
            doSendAnimatedText(getPlayerPosition(cid), "+"..addhealth.."", TEXTCOLOR_GREEN)
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        end
        return true
    end
    return
end

Edit: Had to fix something
 
Last edited:
Solution
Try this one:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_SKILL , 0, 0, 1.0, 0)

function onUseWeapon(cid, var)
    local target = getCreatureTarget(cid)
    local first = getCreatureHealth(target)
    if doCombat(cid, combat, var) then
        local second = getCreatureHealth(target)
        local damage = first - second
        if damage > 0 then
            local addhealth = damage * 0.25
            doCreatureAddHealth(cid, addhealth)
            doSendAnimatedText(getPlayerPosition(cid), "+"..addhealth.."", TEXTCOLOR_GREEN)
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        end
        return true
    end
    return
end

Edit: Had to fix something
This does not work against players with magic shield, just a note :)
 
Last edited:
Back
Top