• 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 Custom ring of healing problem with Delay

Davey Chip

New Member
Joined
Mar 10, 2009
Messages
13
Solutions
1
Reaction score
0
Hi,

So i'm trying to make a custom ring of healing, this is the bare bones of the script. My problem being, how do i add a delay to this, so it only heals every second or two, currently it just bursts with endless healing because i can't add a delay to the loop? I added the magic effect so i could see how often the script was being executed.

Lua:
function onEquip(player, item, slot)

    while item == player:getSlotItem(CONST_SLOT_RING) do

        addEvent(healhealth,500, playerid)
        addEvent(healmana,500, playerid)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
    
    return true
end

function healhealth(playerid)

    playerid:addHealth(math.random(50,150))
    return true
end

function healmana(playerid)

    playerid:addMana(math.random(50, 150))
    return true
end
 
In items.xml
Code:
<attribute key="healthGain" value="1" />
<attribute key="healthTicks" value="3000" />

I know that much, but what if i want it to heal more when a quest is complete etc. I don't want it to just be a static heal like a regular item. That's why i said it's just the bare bones.
 
I am not an expert, but I would do it like that
Code:
function()
      whatever ur script is
      addEvent(function, 1000)
end
 
And this if u want it to work different after completing the quest
Lua:
if getPlayerStorageValue(cid, QuestStorageValue) < 1 then
 
And this if u want it to work different after completing the quest
Lua:
if getPlayerStorageValue(cid, QuestStorageValue) < 1 then

yes i know that, but i need my base script to work before i can do anything else
Post automatically merged:

I am not an expert, but I would do it like that
Code:
function()
      whatever ur script is
      addEvent(function, 1000)
end
this honestly seems like a great idea, but i'm unsure if a nested script like that of a function infinitely recalling itself will cause a memory leak since the original function never terminates? Or maybe it does and i'm just confused at this point. since the script would call the event then end?
 
Last edited:
this honestly seems like a great idea, but i'm unsure if a nested script like that of a function infinitely recalling itself will cause a memory leak since the original function never terminates? Or maybe it does and i'm just confused at this point. since the script would call the event then end?
Honestly, I don't think it will, but I am not sure. Maybe somebody more experienced can say something about that.
 
Honestly, I don't think it will, but I am not sure. Maybe somebody more experienced can say something about that.
I guess time will tell.

This is my complete script currently if anyone is interested.

Lua:
function onEquip(player, item, slot)
   
    if player:getStorageValue(51000) < 1 then
        player:setStorageValue(51000, 1)
        addEvent(ringloop,1500, player:getId(), item:getId())
    end
    return true
end


function ringloop(cid, itid)
        local creature = Creature(cid)
        if itid == creature:getSlotItem(CONST_SLOT_RING):getId() then
            addEvent(healhealth,1500, cid)
            addEvent(healmana,1500, cid)
            addEvent(ringloop, 1500, cid, itid)
        else
            creature:setStorageValue(51000, 0)
        end
    return true

end

function healhealth(cid)
    local creature = Creature(cid)
    creature:addHealth(math.random(50,150))
    creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

function healmana(cid)

    local creature = Creature(cid)
    creature:addMana(math.random(50, 150))
    creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

if anyone wants to neaten/shorten it for me that would be great.
 
Last edited:
I guess time will tell.

This is my complete script currently if anyone is interested.

Lua:
function onEquip(player, item, slot)
 
    if player:getStorageValue(51000) < 1 then
        player:setStorageValue(51000, 1)
        addEvent(ringloop,1500, player:getId(), item:getId())
    end
    return true
end


function ringloop(cid, itid)
        local creature = Creature(cid)
        if itid == creature:getSlotItem(CONST_SLOT_RING):getId() then
            addEvent(healhealth,1500, cid)
            addEvent(healmana,1500, cid)
            addEvent(ringloop, 1500, cid, itid)
        else
            creature:setStorageValue(51000, 0)
        end
    return true

end

function healhealth(cid)
    local creature = Creature(cid)
    creature:addHealth(math.random(50,150))
    creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

function healmana(cid)

    local creature = Creature(cid)
    creature:addMana(math.random(50, 150))
    creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

if anyone wants to neaten/shorten it for me that would be great.
For what this every things?
Lua:
OnEquip(player, item, slot)
player:setStorageValue(51000, 1)
if player:getStorageValue(51000) == 1 then
-- do things
return true
end
end
OnDeEquip(player, item, slot)
player:setStorageValue(51000, 0)
return true
end
 
For what this every things?
Lua:
OnEquip(player, item, slot)
player:setStorageValue(51000, 1)
if player:getStorageValue(51000) == 1 then
-- do things
return true
end
end
OnDeEquip(player, item, slot)
player:setStorageValue(51000, 0)
return true
end

my current problem is really, if i unequip it and reequip it fast enough the effect just multiplies so i'm trying to figure a way to stop it.
At this point i'm thinking of just putting an exhaust on the ring.

Lua:
function onEquip(player, item, slot)
    addEvent(ringloop,3000, player:getId(), item:getId())
    return true
    
end


function ringloop(cid, itid)

        local creature = Creature(cid)
        if itid == creature:getSlotItem(CONST_SLOT_RING):getId() then
            addEvent(healhealth,1500, cid)
            addEvent(healmana,1500, cid)
            addEvent(ringloop, 1500, cid, itid)
        end
    return true
    
end

function healhealth(cid)

    local creature = Creature(cid)
    creature:addHealth(math.random(50,150))
    creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
    
end

function healmana(cid)

    local creature = Creature(cid)
    creature:addMana(math.random(50, 150))
    creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
    
end


function onDeEquip(player, item, slot)
    stopEvent(ringloop)
end

this is my latest attempt
 
my current problem is really, if i unequip it and reequip it fast enough the effect just multiplies so i'm trying to figure a way to stop it.
At this point i'm thinking of just putting an exhaust on the ring.

Lua:
function onEquip(player, item, slot)
    addEvent(ringloop,3000, player:getId(), item:getId())
    return true
 
end


function ringloop(cid, itid)

        local creature = Creature(cid)
        if itid == creature:getSlotItem(CONST_SLOT_RING):getId() then
            addEvent(healhealth,1500, cid)
            addEvent(healmana,1500, cid)
            addEvent(ringloop, 1500, cid, itid)
        end
    return true
end

function healhealth(cid)

    local creature = Creature(cid)
    creature:addHealth(math.random(50,150))
    creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
 
end

function healmana(cid)

    local creature = Creature(cid)
    creature:addMana(math.random(50, 150))
    creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
 
end


function onDeEquip(player, item, slot)
    stopEvent(ringloop)
end

this is my latest attempt
Lua:
local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_SUBID, 4)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, (math.random(50,150)))
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 100)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
setCombatCondition(combat, condition)

local condition2 = Condition(CONDITION_REGENERATION)
condition2:setParameter(CONDITION_PARAM_SUBID, 4)
condition2:setParameter(CONDITION_PARAM_TICKS, -1)
condition2:setParameter(CONDITION_PARAM_MANAGAIN, (math.random(50,150)))
condition2:setParameter(CONDITION_PARAM_MANATICKS, 100)
condition2:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
setCombatCondition(combat, condition2)

function onEquip(player, item, slot, variant)
    if getPlayerSlotItem(player, slot).itemid == item.itemid and player:getStorageValue(51000) == 1 then
        player:setStorageValue(51000, 0)
        player:sendMagicEffect(CONST_ME_MAGIC_BLUE)
        player:addCondition(condition)
        player:addCondition(condition2)
        end
     return true
end

function onDeEquip(player, item, slot, variant)
    player:removeCondition(CONDITION_REGENERATION)
    return true
end
 
Lua:
local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_SUBID, 4)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, (math.random(50,150)))
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 100)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
setCombatCondition(combat, condition)

local condition2 = Condition(CONDITION_REGENERATION)
condition2:setParameter(CONDITION_PARAM_SUBID, 4)
condition2:setParameter(CONDITION_PARAM_TICKS, -1)
condition2:setParameter(CONDITION_PARAM_MANAGAIN, (math.random(50,150)))
condition2:setParameter(CONDITION_PARAM_MANATICKS, 100)
condition2:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
setCombatCondition(combat, condition2)

function onEquip(player, item, slot, variant)
    if getPlayerSlotItem(player, slot).itemid == item.itemid and player:getStorageValue(51000) == 1 then
        player:setStorageValue(51000, 0)
        player:sendMagicEffect(CONST_ME_MAGIC_BLUE)
        player:addCondition(condition)
        player:addCondition(condition2)
        end
     return true
end

function onDeEquip(player, item, slot, variant)
    player:removeCondition(CONDITION_REGENERATION)
    return true
end

thanks, this looks great, but if i were to want to turn that math.random into a variable amount how would i go about setting that? because i notice the conditions are set before player information is grabbed. so i can't do an if player has completed quest, regen = regenx2 etc... or does it not matter since i can set a global variable in the onEquip function before calling the addCondition functions?
 
Back
Top