• 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 Potions Heal Over Time

Sunset

Member
Joined
Jun 3, 2009
Messages
26
Reaction score
8
Location
Uruguay
Hey there!

I found this script while looking for this but I'd love to have one modification to it: I don't want it to stack.

Atm spamming potions stacks the effect of each of them making it very difficult to balance.

Is it possible to make them non stackable with themselves but stackable with other stuff like normal healing or recovery spells?

Also, is it possible to have them for mana too?

Thanks in advance. Here's the script:

Lua:
local config = {
    amount = 20, -- HPs by second
    time = 10 -- seconds
}

local function doRegeneration(cid, amount, seconds)
    if seconds <= 0 then
        return FALSE
    end
    doCreatureAddHealth(cid, amount)
    doSendAnimatedText(getThingPos(cid), "+" .. amount, COLOR_LIGHTBLUE)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    return addEvent(doRegeneration, 1000, cid, amount, seconds - 1)
end
     
function onUse(cid, item, fromPosition, itemEx, toPosition)
    doRemoveItem(item.uid, 1)
    doRegeneration(cid, config.amount, config.time)
    return TRUE
end

Edit:
The post has this:
Lua:
local config = {
    amount = 20, -- HPs by second
    time = 5, -- seconds
    exhaust = {
        storage = 1000,
        time = 10, -- Exhaust time seconds~
    }
}

local function doRegeneration(cid, amount, seconds)
    if seconds <= 0 then
        return false
    end
    doCreatureAddHealth(cid, amount)
    doSendAnimatedText(getThingPos(cid), "+" .. amount, COLOR_LIGHTBLUE)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    return addEvent(doRegeneration, 1000, cid, amount, seconds - 1)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if exhaustion.check(cid, config.exhaust.storage) then      
        return doPlayerSendCancel(cid, "You're exhausted.")
    end  
    doRemoveItem(item.uid, 1)
    doRegeneration(cid, config.amount, config.time)
    exhaustion.set(cid, config.exhaust.storage, config.exhaust.time)
    return true
end

But it doesn't work...

TFS 1.4.2 BTW
 
Last edited:
try this code:

Lua:
local config = {
    amount = 20, -- HPs by second
    time = 5, -- seconds
    exhaust = {
        storage = 1000,
        time = 10, -- Exhaust time seconds~
    }
}


local function doRegeneration(player, amount, seconds)
    if seconds <= 0 then
        return false
    end
    
    player:addHealth(amount)
    local pos = player:getPosition()
    pos:sendAnimatedText("+" .. amount, COLOR_LIGHTBLUE)
    pos:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    
    addEvent(doRegeneration, 1000, player, amount, seconds - 1)
end


function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cid = player:getId()
    
    if player:getStorageValue(config.exhaust.storage) > os.time() then
        player:sendCancelMessage("You're exhausted.")
        return true
    end
    
    item:remove(1)
    doRegeneration(player, config.amount, config.time)
    player:setStorageValue(config.exhaust.storage, os.time() + config.exhaust.time)
    
    return true
end
Post automatically merged:

Hey there!

I found this script while looking for this but I'd love to have one modification to it: I don't want it to stack.

Atm spamming potions stacks the effect of each of them making it very difficult to balance.

Is it possible to make them non stackable with themselves but stackable with other stuff like normal healing or recovery spells?

Also, is it possible to have them for mana too?

Thanks in advance. Here's the script:

Lua:
local config = {
    amount = 20, -- HPs by second
    time = 10 -- seconds
}

local function doRegeneration(cid, amount, seconds)
    if seconds <= 0 then
        return FALSE
    end
    doCreatureAddHealth(cid, amount)
    doSendAnimatedText(getThingPos(cid), "+" .. amount, COLOR_LIGHTBLUE)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    return addEvent(doRegeneration, 1000, cid, amount, seconds - 1)
end
    
function onUse(cid, item, fromPosition, itemEx, toPosition)
    doRemoveItem(item.uid, 1)
    doRegeneration(cid, config.amount, config.time)
    return TRUE
end

Edit:
The post has this:
Lua:
local config = {
    amount = 20, -- HPs by second
    time = 5, -- seconds
    exhaust = {
        storage = 1000,
        time = 10, -- Exhaust time seconds~
    }
}

local function doRegeneration(cid, amount, seconds)
    if seconds <= 0 then
        return false
    end
    doCreatureAddHealth(cid, amount)
    doSendAnimatedText(getThingPos(cid), "+" .. amount, COLOR_LIGHTBLUE)
    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
    return addEvent(doRegeneration, 1000, cid, amount, seconds - 1)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if exhaustion.check(cid, config.exhaust.storage) then     
        return doPlayerSendCancel(cid, "You're exhausted.")
    end 
    doRemoveItem(item.uid, 1)
    doRegeneration(cid, config.amount, config.time)
    exhaustion.set(cid, config.exhaust.storage, config.exhaust.time)
    return true
end

But it doesn't work...

TFS 1.4.2 BTW
 

Revscripts​

Lua:
local config = {
    amount = 20, 
    cooldown = {
        storage = 2000, 
        time = 10, 
    },
    regenerationInterval = 5000, 
}

local function doRegeneration(player)
    player:addHealth(config.amount)
   
    local color = config.amount
    local formattedText = string.format("+%d", color)
    local playerPosition = player:getPosition()
    playerPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    doSendAnimatedText(formattedText, playerPosition, 12) -- Changed to number 12 (desired color)
end

local function startRegeneration(player)
    if player:getStorageValue(config.cooldown.storage) > os.time() then
        player:sendCancelMessage("You're still on cooldown.")
        return
    end

    doRegeneration(player)
    player:setStorageValue(config.cooldown.storage, os.time() + config.cooldown.time)

    addEvent(function()
        doRegeneration(player)
    end, config.regenerationInterval)
end

local regenerationAction = Action()

function regenerationAction.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    startRegeneration(player)
    item:remove(1)
    return true
end

regenerationAction:id(39553) 
regenerationAction:register()
 
Last edited:
Back
Top