• 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.3] Percent amount healing potion per tick.

Kuantikum

Member
Joined
Jul 3, 2015
Messages
219
Solutions
1
Reaction score
20
Hello guys :p:p:p,


I'm trying to make a script that heals a certain amount as a percentage of the character's total health, for example: 5% of the character's total health per tick.


That's what I've done so far:
Lua:
local storage = 24036
local shp = Condition(CONDITION_REGENERATION)
shp:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
shp:setParameter(CONDITION_PARAM_HEALTHGAIN, 100)
shp:setParameter(CONDITION_PARAM_HEALTHTICKS, 100)
shp:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local potions = {
[26031] = {condition = shp, effect = CONST_ME_MAGIC_RED, description = "Only knights of level 200 or above may drink this fluid."},   
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if type(target) == "userdata" and not target:isPlayer() then
        return false
    end   
      local potion = potions[item:getId()]
    if potion.level and player:getLevel() < potion.level or potion.vocations and not table.contains(potion.vocations, player:getVocation():getId()) then
        player:say(potion.description, TALKTYPE_MONSTER_SAY)
        return true
    end
    if potion.condition then
        player:addCondition(potion.condition)
        player:say(potion.text, TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(potion.effect)
        --player:setStorageValue(storage, 1)
    
        return true
    else   

        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end

  -- item:remove(1)
    return true
end

I thought of something like:
Lua:
local healthmax = target:getMaxHealth()
local hpPercent = 5
((healthmax /100)*hpPercent )

i get stucked :rolleyes:...


I would be very happy and grateful for your help, thanks! 🥰😘😍
 
This?

Code:
local healthmax = target:getMaxHealth()
local hpPercent = 5
local toHeal = healthmax * (hpPercent/100)
doTargetCombatHealth(0, target, COMBAT_HEALING, toHeal, toHeal)
 
This?

Code:
local healthmax = target:getMaxHealth()
local hpPercent = 5
local toHeal = healthmax * (hpPercent/100)
doTargetCombatHealth(0, target, COMBAT_HEALING, toHeal, toHeal)


Yes, something like that. healing 5% per second for 1 minute for example ... But how do I apply this to the script I already have?

Lua:
local storage = 24036
local shp = Condition(CONDITION_REGENERATION)
shp:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
shp:setParameter(CONDITION_PARAM_HEALTHGAIN, 100)
shp:setParameter(CONDITION_PARAM_HEALTHTICKS, 100)
shp:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local potions = {
[26031] = {condition = shp, effect = CONST_ME_MAGIC_RED, description = "Only knights of level 200 or above may drink this fluid."},   
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if type(target) == "userdata" and not target:isPlayer() then
        return false
    end   
      local potion = potions[item:getId()]
    if potion.level and player:getLevel() < potion.level or potion.vocations and not table.contains(potion.vocations, player:getVocation():getId()) then
        player:say(potion.description, TALKTYPE_MONSTER_SAY)
        return true
    end
    if potion.condition then
        player:addCondition(potion.condition)
        player:say(potion.text, TALKTYPE_MONSTER_SAY)
        player:getPosition():sendMagicEffect(potion.effect)
        --player:setStorageValue(storage, 1)
    
        return true
    else   

        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end

  -- item:remove(1)
    return true
end
 
For 1.x
Lua:
local function eventRegeneration(playerId, seconds)
    local player = Player(playerId)
    if seconds > 0 and player then
        local healvalue = ((player:getMaxHealth * 0.05))
        player:addHealth(healvalue)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        addEvent(eventRegeneration, 1000, playerId, seconds - 1)
    end
end

local coolDownStorageID = 666777
local coolDownSeconds = 10

function onCastSpell(player, variant)
    if player:getStorageValue(coolDownStorageID) <= os.time() then
        player:setStorageValue(coolDownStorageID, os.time() + (coolDownSeconds - 1))
        return eventRegeneration(player:getId(), coolDownSeconds)
    end
    return not player:sendCancelMessage("You are exhausted.")
end
 
Back
Top