• 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 tfs 1.4.2 when item equipped heal percent

F

Fairytail

Guest
^^' may someone help me with a movement script that heals % when item equipped?
 
Lua:
local percent = 5

function onEquip(player, item, slot, isCheck)
    if isCheck then
    return true
    end
    player:addHealth(player:getMaxHealth() * percent / 100)
return true
end
 
onEquip triggers on login aswell
oh thank you
Post automatically merged:

how many ticks?
managed to solve it, thank you
Post automatically merged:

how many ticks?
oh im using the following, it works but after the char dies it stops healing even if dequped/requiped
Lua:
local percent = 5

local runningEvents = {}
local function gainHpAndMana(cid)
    local player = Player(cid)
    if not player then
        return
    end


    player:addMana(player:getMaxMana() * percent / 100)
    player:addHealth(player:getMaxHealth() * percent / 100)
    runningEvents[1] = addEvent(gainHpAndMana, 1000, player:getId())
    return true
end
function onEquip(player, item, slot)
    local event = runningEvents[1]
    if not event then
        event = addEvent(gainHpAndMana, 1000, player:getId())
    end
    return true
end
function onDeEquip(player, item, slot)
    local event = runningEvents[1]
    stopEvent(runningEvents[1])
    if event then
        event = nil
    end
    return true
end
 
Last edited by a moderator:
Not sure what you're trying to make here, but if you want an equipment to just works like a limitless ring of healing, you can do this just by adding some attributes into the items.xml, btw:

Lua:
<attribute key="healthGain" value="6" />
<attribute key="healthTicks" value="6000" />
 
Not sure what you're trying to make here, but if you want an equipment to just works like a limitless ring of healing, you can do this just by adding some attributes into the items.xml, btw:

Lua:
<attribute key="healthGain" value="6" />
<attribute key="healthTicks" value="6000" />
yes but i want it in percentage instead
Post automatically merged:

oh thank you
Post automatically merged:


managed to solve it, thank you
Post automatically merged:


oh im using the following, it works but after the char dies it stops healing even if dequped/requiped
Lua:
local percent = 5

local runningEvents = {}
local function gainHpAndMana(cid)
    local player = Player(cid)
    if not player then
        return
    end


    player:addMana(player:getMaxMana() * percent / 100)
    player:addHealth(player:getMaxHealth() * percent / 100)
    runningEvents[1] = addEvent(gainHpAndMana, 1000, player:getId())
    return true
end
function onEquip(player, item, slot)
    local event = runningEvents[1]
    if not event then
        event = addEvent(gainHpAndMana, 1000, player:getId())
    end
    return true
end
function onDeEquip(player, item, slot)
    local event = runningEvents[1]
    stopEvent(runningEvents[1])
    if event then
        event = nil
    end
    return true
end
this script also continues heal after deequip
 
Last edited by a moderator:
@Fairytail Instead of this performance killer solution you could simply execute condition:

Lua:
local condition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
condition:setTicks(seconds * 1000) -- seconds or -1
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, healthGain)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, healthTicks)
condition:setParameter(CONDITION_PARAM_MANAGAIN, manaGain)
condition:setParameter(CONDITION_PARAM_MANATICKS, manaTicks)

player:addCondition(condition)

Yours solution does not work as it allows only one event to be executed (so it only works for one player anywas).
You'd need to store event ID's per player to make that work and handle case when player dies (clean of this guard map)

Alternatively you could rework item attributes to allow to specify some additional attribute like usePercentage (healthPercentage / manaPercentage) (CPP changes required).
 
@Fairytail Instead of this performance killer solution you could simply execute condition:

Lua:
local condition = Condition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
condition:setTicks(seconds * 1000) -- seconds or -1
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, healthGain)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, healthTicks)
condition:setParameter(CONDITION_PARAM_MANAGAIN, manaGain)
condition:setParameter(CONDITION_PARAM_MANATICKS, manaTicks)

player:addCondition(condition)

Yours solution does not work as it allows only one event to be executed (so it only works for one player anywas).
You'd need to store event ID's per player to make that work and handle case when player dies (clean of this guard map)

Ideally you could rework item attributes to allow to specify some additional attribute like "usePercentage" for "healthGain" (CPP changes required).
thank you
 
The condition I posted as exmaple is default food condition so maybe no to mix things up choose some other one (try to replace CONDITIONID_DEFAULT with respective slot condition e.g. CONDITIONID_RING) , anyway I'm sure you'll manage to make that work without side effect ;)

Remember to remove condition in DeEquip
Lua:
player:removeCondition(CONDITION_REGENERATION, CONDITIONID_RING)
 
Last edited:
Back
Top