F
Fairytail
Guest
^^' may someone help me with a movement script that heals % when item equipped?
thank youLUA:local percent = 5 function onEquip(player, item, slot, isCheck) if isCheck then return true end player:addHealth(player:getMaxHealth() * percent / 100) return true end
Test it, if it works mark it as the solution for the thread. You're welcomethank you![]()
how can i make it heals per sec?Test it, if it works mark it as the solution for the thread. You're welcomeglhf
how many ticks?how can i make it heals per sec?
once per sec for examplehow many ticks?
oh thank youonEquip triggers on login aswell
managed to solve it, thank youhow many ticks?
oh im using the following, it works but after the char dies it stops healing even if dequped/requipedhow many ticks?
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
<attribute key="healthGain" value="6" />
<attribute key="healthTicks" value="6000" />
yes but i want it in percentage insteadNot 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" />
this script also continues heal after deequipoh 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
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)
usePercentage
(healthPercentage
/ manaPercentage
) (CPP changes required).thank you@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).
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 DeEquip
player:removeCondition(CONDITION_REGENERATION, CONDITIONID_RING)