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

Healing proportional to missing HP

axores

New Member
Joined
Jul 17, 2013
Messages
3
Reaction score
0
I am trying to build a character spell that not only increase the skills (like Blood Rage), but would also start healing the player at less than 50% HP. And as low the HP is, more intense becomes the healing.

I got this after days of trying different strategies:

local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_TICKS, 60000)
condition:setParameter(CONDITION_PARAM_SKILL_MELEEPERCENT, 135)
condition:setParameter(CONDITION_PARAM_SKILL_SHIELDPERCENT, 50)
condition:setParameter(CONDITION_PARAM_DISABLE_DEFENSE, true)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:addCondition(condition)

isPlayer(cid)
local healthmax = getCreatureMaxHealth(cid)
healing = getCreatureHealth(cid) / getCreatureMaxHealth(cid) *100


local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_SUBID, 1)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, 1)
condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, healing)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 500)
combat:addCondition(condition)



function onCastSpell(creature, var)
return combat:execute(creature, var)
end





It is working when i set a fixed value for healing per tick, but when i try to use the formula based on the health %. Not working at all, no errors thou.
I have been researching for 3 days already, tried so many different ways, but nothing really fixed it.

I would really appreciate some help with this, some guidance maybe.

Thank you very much.
 
Maybe try this?
Code:
isPlayer(cid)

local healthmax = getCreatureMaxHealth(cid)
healing = math.floor((getCreatureHealth(cid) / healthmax) * 100)
print(healthmax)
print(healing)
It should print on console when you cast it, the value it retrieved about the max health of the player plus the healing that should be applied down below it.
If the value shows up correctly, then the formula is alright.
 
Back
Top