• 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 Ring of Ending

Unknown Soldier

Mapping a map
Joined
Oct 30, 2010
Messages
263
Solutions
11
Reaction score
621
Hi everyone,

I am struggling with bugged ring of ending script.

When you put the ring on, everything goes fine, you will get the ring, or you will die, 50/50.
But the problem starts, when you pull off the ring during the event of messages... There are two variants when the ring is taken off from the ring slot:
- the event continues, you can still die when you are unlucky (but you can keep the unstable ring of ending)
- when you are lucky, you will clone the ring - so you will have one succesful ring in ring slot (ID 22516) and one unstable ring of ending (ID 22543) which you had in the beginning.

So I am searching for solution which will stop the event when you put the ring off, and simultaneously will stop the function preventing from logging off duiring the event.

Alternative solution would be making the unstable ring of ending impossible to take off, when you put it on. It will disappear when you die, or transform to succesful ring when you are lucky.

I have tried to put stopEvent in function onDeEquip(cid, item, slot), but didn't work.

Thanks in advance.

movements.xml

Lua:
<movevent event="Equip" itemid="22543" slot="ring" function="onEquipItem" script="ringofending.lua"/>
<movevent event="DeEquip" itemid="22543" slot="ring" function="onDeEquipItem" script="ringofending.lua"/>

ringofending.lua

Lua:
local storage = 480658
local storage2 = 480663
local messages = {
    {m = "The ring feels quite heavy now. Nothing else happens.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring feels even heavier. You feel slightly stronger, however.", e = CONST_ME_MAGIC_GREEN},
    {m = "You feel better, more energetic than ever before. The ring seems to wrap itself tighter around your finger."},
    {m = "The ring now cuts your flesh. However, you feel fast as lightning and strong as a dragon, fires seem to burn within you."},
    {m = "You feel as if you could touch the stars and see beyond even the dimmest of them. The ring hurts you now.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring now seems to be as hot as fire while at the same time cold as ice. Put it off or it will seriously hurt you."},
    {m = "Pain is no word for what you feel anymore. If you do not put the ring off it MAY kill you. Chances are 50/50.", e = CONST_ME_FIREWORK_YELLOW},
    {m = "Your pain transports you in a different world, you are alone there. Filled with anguish. You may live or it MAY KILL YOU."},
    {m = "You became pain itself. You are mere seconds away from death. If you do not PUT OFF THE RING. You MAY actually DIE.", e = CONST_ME_MORTAREA}
}
local function endRing(cid)
    if not isPlayer(cid) then
        return true
    end
    if getPlayerStorageValue(cid, storage) == 0 then
        return true
    end
    local chance = math.random(1, 2)
    if chance == 1 then
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "The ring closes. It feels cool now. With the ring restored, you have returned.")
        local itemUID = doCreateItemEx(22516, 1)
        local item = Item(itemUID)
        item:setAttribute(ITEM_ATTRIBUTE_TEXT,"This eternal ring was forged in the pain of " .. getCreatureName(cid) .. " and hardened by his/her endurance.")
        doPlayerAddItemEx(cid, itemUID, true)
        setPlayerStorageValue(cid, storage2, getPlayerStorageValue(cid, storage2) - 1)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "A bright explosion bursts from inside the ring. You die.")
        setPlayerStorageValue(cid, storage2, getPlayerStorageValue(cid, storage2) - 1)
    end
    return true
end
function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    else
        setPlayerStorageValue(cid, storage, 1)
        setPlayerStorageValue(cid, storage2, 1)     
    end
    local time = 0
    for m = 1, #messages do
        addEvent(doPlayerSendTextMessage, time, cid.uid, MESSAGE_EVENT_ADVANCE, messages[m].m)
        if messages[m].e then
            addEvent(doSendMagicEffect, time, getPlayerPosition(cid.uid), messages[m].e)
        end
        time = time + 10000
    end
    addEvent(endRing, #messages * 10000, cid.uid)
    return true
end
function onDeEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 0 then
        return true
    else
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end

creaturescripts/logout.lua

Lua:
function onLogout(cid)
    if (Player(cid):getStorageValue(480663) == 1) then
        doPlayerSendCancel(cid, "You can not log out during these effects.")
        return false
    end
    return true
end
 
Solution
Lua:
local storage = 480658
local storage2 = 480663
local messages = {
    {m = "The ring feels quite heavy now. Nothing else happens.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring feels even heavier. You feel slightly stronger, however.", e = CONST_ME_MAGIC_GREEN},
    {m = "You feel better, more energetic than ever before. The ring seems to wrap itself tighter around your finger."},
    {m = "The ring now cuts your flesh. However, you feel fast as lightning and strong as a dragon, fires seem to burn within you."},
    {m = "You feel as if you could touch the stars and see beyond even the dimmest of them. The ring hurts you now.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring now seems to be as hot as fire while at the same time cold...
In the first place I would like to repair the script.

I will try to edit "for" loop, because it goes on with all the messeges even if the ring is off.
When you put the ring off the slot before the "for" loop ends, you will not die or create succesful ring, simply it won't reach the function that creates the ring/kills a player, and the messages then will stop, but I want them to stop just IN THE MOMENT you take the ring off. It needs some kind of "break" maybe? Anyone? :)
 
Try this:
Lua:
local storage = 480658
local storage2 = 480663
local messages = {
    {m = "The ring feels quite heavy now. Nothing else happens.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring feels even heavier. You feel slightly stronger, however.", e = CONST_ME_MAGIC_GREEN},
    {m = "You feel better, more energetic than ever before. The ring seems to wrap itself tighter around your finger."},
    {m = "The ring now cuts your flesh. However, you feel fast as lightning and strong as a dragon, fires seem to burn within you."},
    {m = "You feel as if you could touch the stars and see beyond even the dimmest of them. The ring hurts you now.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring now seems to be as hot as fire while at the same time cold as ice. Put it off or it will seriously hurt you."},
    {m = "Pain is no word for what you feel anymore. If you do not put the ring off it MAY kill you. Chances are 50/50.", e = CONST_ME_FIREWORK_YELLOW},
    {m = "Your pain transports you in a different world, you are alone there. Filled with anguish. You may live or it MAY KILL YOU."},
    {m = "You became pain itself. You are mere seconds away from death. If you do not PUT OFF THE RING. You MAY actually DIE.", e = CONST_ME_MORTAREA}
}
local function endRing(cid)
    if not isPlayer(cid) then
        return true
    end
    if getPlayerStorageValue(cid, storage) == 0 then
        return true
    end
    local chance = math.random(1, 2)
    if chance == 1 then
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "The ring closes. It feels cool now. With the ring restored, you have returned.")
        local itemUID = doCreateItemEx(22516, 1)
        local item = Item(itemUID)
        item:setAttribute(ITEM_ATTRIBUTE_TEXT,"This eternal ring was forged in the pain of " .. getCreatureName(cid) .. " and hardened by his/her endurance.")
        doPlayerAddItemEx(cid, itemUID, true)
        setPlayerStorageValue(cid, storage2, getPlayerStorageValue(cid, storage2) - 1)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "A bright explosion bursts from inside the ring. You die.")
        setPlayerStorageValue(cid, storage2, getPlayerStorageValue(cid, storage2) - 1)
    end
    return true
end
events = {}
function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    else
        setPlayerStorageValue(cid, storage, 1)
        setPlayerStorageValue(cid, storage2, 1)  
    end
    events[cid.uid] = {}
    local time = 0
    for m = 1, #messages do
        events[cid.uid][m] = addEvent(doPlayerSendTextMessage, time, cid.uid, MESSAGE_EVENT_ADVANCE, messages[m].m)
        if messages[m].e then
            events[cid.uid][m+#messages]addEvent(doSendMagicEffect, time, getPlayerPosition(cid.uid), messages[m].e)
        end
        time = time + 10000
    end
    events[cid.uid][0] = addEvent(endRing, #messages * 10000, cid.uid)
    return true
end
function onDeEquip(cid, item, slot)
    for i = 0, #events[cid.uid] do
        stopEvent(events[cid.uid][i])
    end
    if getPlayerStorageValue(cid, storage) == 0 then
        return true
    else
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end
 
Hi,

works almost perfectly :) I must admit I wouldn't do this alone, so thank you! Just added a line that resets storage, so that you can logout from the game after putting the ring off. So all I mentioned above is solved.

There is still one more, less important bug in this script. Magic effects always appears in the position, where you put on the ring at first. When you move they are not using current player location so this looks strange.

Current version:

Lua:
local storage = 480658
local storage2 = 480663
local messages = {
    {m = "The ring feels quite heavy now. Nothing else happens.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring feels even heavier. You feel slightly stronger, however.", e = CONST_ME_MAGIC_GREEN},
    {m = "You feel better, more energetic than ever before. The ring seems to wrap itself tighter around your finger."},
    {m = "The ring now cuts your flesh. However, you feel fast as lightning and strong as a dragon, fires seem to burn within you."},
    {m = "You feel as if you could touch the stars and see beyond even the dimmest of them. The ring hurts you now.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring now seems to be as hot as fire while at the same time cold as ice. Put it off or it will seriously hurt you."},
    {m = "Pain is no word for what you feel anymore. If you do not put the ring off it MAY kill you. Chances are 50/50.", e = CONST_ME_FIREWORK_YELLOW},
    {m = "Your pain transports you in a different world, you are alone there. Filled with anguish. You may live or it MAY KILL YOU."},
    {m = "You became pain itself. You are mere seconds away from death. If you do not PUT OFF THE RING. You MAY actually DIE.", e = CONST_ME_MORTAREA}
}
local function endRing(cid)
    if not isPlayer(cid) then
        return true
    end
    if getPlayerStorageValue(cid, storage) == 0 then
        return true
    end
    local chance = math.random(1, 2)
    if chance == 1 then
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "The ring closes. It feels cool now. With the ring restored, you have returned.")
        local itemUID = doCreateItemEx(22516, 1)
        local item = Item(itemUID)
        item:setAttribute(ITEM_ATTRIBUTE_TEXT,"This eternal ring was forged in the pain of " .. getCreatureName(cid) .. " and hardened by his/her endurance.")
        doPlayerAddItemEx(cid, itemUID, true)
        setPlayerStorageValue(cid, storage2, getPlayerStorageValue(cid, storage2) - 1)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "A bright explosion bursts from inside the ring. You die.")
        setPlayerStorageValue(cid, storage2, getPlayerStorageValue(cid, storage2) - 1)
    end
    return true
end
events = {}
function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    else
        setPlayerStorageValue(cid, storage, 1)
        setPlayerStorageValue(cid, storage2, 1)
    end
    events[cid.uid] = {}
    local time = 0
    for m = 1, #messages do
        events[cid.uid][m] = addEvent(doPlayerSendTextMessage, time, cid.uid, MESSAGE_EVENT_ADVANCE, messages[m].m)
        if messages[m].e then
        events[cid.uid][m+#messages] = addEvent(doSendMagicEffect, time, getPlayerPosition(cid.uid), messages[m].e)
        end
        time = time + 10000
    end
    events[cid.uid][0] = addEvent(endRing, #messages * 10000, cid.uid)
    return true
end
function onDeEquip(cid, item, slot)
    for i = 0, #events[cid.uid] do
        stopEvent(events[cid.uid][i])
        setPlayerStorageValue(cid, storage2, -1)
    end
    if getPlayerStorageValue(cid, storage) == 0 then
        return true
    else
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end
 
Lua:
local storage = 480658
local storage2 = 480663
local messages = {
    {m = "The ring feels quite heavy now. Nothing else happens.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring feels even heavier. You feel slightly stronger, however.", e = CONST_ME_MAGIC_GREEN},
    {m = "You feel better, more energetic than ever before. The ring seems to wrap itself tighter around your finger."},
    {m = "The ring now cuts your flesh. However, you feel fast as lightning and strong as a dragon, fires seem to burn within you."},
    {m = "You feel as if you could touch the stars and see beyond even the dimmest of them. The ring hurts you now.", e = CONST_ME_MAGIC_GREEN},
    {m = "The ring now seems to be as hot as fire while at the same time cold as ice. Put it off or it will seriously hurt you."},
    {m = "Pain is no word for what you feel anymore. If you do not put the ring off it MAY kill you. Chances are 50/50.", e = CONST_ME_FIREWORK_YELLOW},
    {m = "Your pain transports you in a different world, you are alone there. Filled with anguish. You may live or it MAY KILL YOU."},
    {m = "You became pain itself. You are mere seconds away from death. If you do not PUT OFF THE RING. You MAY actually DIE.", e = CONST_ME_MORTAREA}
}
local function endRing(cid)
    if not isPlayer(cid) then
        return true
    end
    if getPlayerStorageValue(cid, storage) == 0 then
        return true
    end
    local chance = math.random(1, 2)
    if chance == 1 then
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "The ring closes. It feels cool now. With the ring restored, you have returned.")
        local itemUID = doCreateItemEx(22516, 1)
        local item = Item(itemUID)
        item:setAttribute(ITEM_ATTRIBUTE_TEXT,"This eternal ring was forged in the pain of " .. getCreatureName(cid) .. " and hardened by his/her endurance.")
        doPlayerAddItemEx(cid, itemUID, true)
        setPlayerStorageValue(cid, storage2, getPlayerStorageValue(cid, storage2) - 1)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "A bright explosion bursts from inside the ring. You die.")
        setPlayerStorageValue(cid, storage2, getPlayerStorageValue(cid, storage2) - 1)
    end
    return true
end
events = {}
function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    else
        setPlayerStorageValue(cid, storage, 1)
        setPlayerStorageValue(cid, storage2, 1)
    end
    events[cid.uid] = {}
    local time = 0
    for m = 1, #messages do
        events[cid.uid][m] = addEvent(doPlayerSendTextMessage, time, cid.uid, MESSAGE_EVENT_ADVANCE, messages[m].m)
        if messages[m].e then
        events[cid.uid][m+#messages] = addEvent(sendEff, time, cid.uid, messages[m].e)
        end
        time = time + 10000
    end
    events[cid.uid][0] = addEvent(endRing, #messages * 10000, cid.uid)
    return true
end
function onDeEquip(cid, item, slot)
    for i = 0, #events[cid.uid] do
        stopEvent(events[cid.uid][i])
        setPlayerStorageValue(cid, storage2, -1)
    end
    if getPlayerStorageValue(cid, storage) == 0 then
        return true
    else
        setPlayerStorageValue(cid, storage, 0)
    end
    return true
end
function sendEff(player, eff)
    local player = Player(player)
    if player then
        doSendMagicEffect(getPlayerPosition(player), eff)
    end
end
 
Last edited:
Solution
Back
Top