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

Solved Ring of Ending Argument #3 is unsafe

Majster12

Member
Joined
Feb 20, 2009
Messages
134
Solutions
1
Reaction score
16
Code:
function onEquip(cid, item, slot)
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)
    local chance = math.random(1, 2)
    if chance == 1 then
        doPlayerAddItem(cid, 22516, 1)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
    end
    doRemoveItem(getPlayerSlotItem(cid, CONST_SLOT_RING).uid, 1)
    return true
end
 
--

local time = 0
for m = 1, #messages do
    addEvent(doPlayerSendTextMessage, time, cid, MESSAGE_EVENT_ADVANCE, messages[m].m)
    if messages[m].e then
        addEvent(doSendMagicEffect, time, getPlayerPosition(cid), messages[m].e)
    end
    time = time + 5000
end
addEvent(endRing, #messages * 5000, cid)
    return true
end

dnZUtnC.png



The text should be displayed once.
azRJIqy.png
 
Solution
Ty guys but i think this is a better solution.

Code:
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...
I'm assuming you are using 1.x

Use the creatureid instead of userdata in addEvent. In TFS 1.1 the main functions use userdata instead of creatureid as parameter.

Any reason why your functions are inside the main function?
I moved them outside.

Code:
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)
    local chance = math.random(1, 2)
    if chance == 1 then
        doPlayerAddItem(cid, 22516, 1)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
    end
    doRemoveItem(getPlayerSlotItem(cid, CONST_SLOT_RING).uid, 1)
    return true
end

function onEquip(cid, item, slot)
    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 + 5000
    end
    addEvent(endRing, #messages * 5000, cid.uid)
    return true
end

Not sure about the other issue.
May be a duplicate registering issue in your source or movements.xml
 
Last edited:
Ty for reply, but nothing changed.

Code:
    <!-- Ring of Ending -->
    <movevent event="Equip" itemid="22543" slot="ring" function="onEquipItem" script="roe.lua"/>
    <movevent event="DeEquip" itemid="22543" slot="ring" function="onDeEquipItem"/>

VI7NCvY.png


oR7C5oV.png
 
Ty for reply, but nothing changed.

Code:
    <!-- Ring of Ending -->
    <movevent event="Equip" itemid="22543" slot="ring" function="onEquipItem" script="roe.lua"/>
    <movevent event="DeEquip" itemid="22543" slot="ring" function="onDeEquipItem"/>

VI7NCvY.png


oR7C5oV.png
Missed an addevent. sorry about that.

change this
Code:
addEvent(endRing, #messages * 5000, cid)
to this
Code:
addEvent(endRing, #messages * 5000, cid.uid)

and the other thing... as before
Not sure about the other issue.
May be a duplicate registering issue in your source or movements.xml
 
Not sure about the other issue.
May be a duplicate registering issue in your source or movements.xml

Basically, your movement onEquip is being registered three times.

It's mostly likely an issue with your source. (probable)
It may be duplicate entries in your movements.xml (unlikely)

You could try something like this.. so it doesn't do it multiple times..
But it's really a hack and slash solution.
But also works out well.. so when you remove the ring before it kills the player, it won't kill the player. xD

added some stuff.. just change storage to an empty one.
and remove anything you don't like

Code:
local storage = 45001

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
        doPlayerAddItem(cid, 22516, 1)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
    end
    doRemoveItem(getPlayerSlotItem(cid, CONST_SLOT_RING).uid, 1)
    return true
end

function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    else
        setPlayerStorageValue(cid, storage, 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 + 5000
    end
    addEvent(endRing, #messages * 5000, 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
 
I changed
doRemoveItem(getPlayerSlotItem(cid, CONST_SLOT_RING).uid, 1)
to
doPlayerRemoveItem(cid, 22543, 1)

How to add this text? After successful try? "You read: This eternal ring was forged in the pain of <player> and hardened by his/her endurance."
 
Last edited:
I changed
doRemoveItem(getPlayerSlotItem(cid, CONST_SLOT_RING).uid, 1)
to
doPlayerRemoveItem(cid, 22543, 1)

How to add this text? After successful try? "You read: This eternal ring was forged in the pain of <player> and hardened by his/her endurance."
Where does this text go? On the ring?
To be honest I'm not familiar with everything your trying to do.

You should be able to add it on using this function. (if you use description, it will set a special description onto the very end of an item.)
Code:
doItemSetAttribute(uid, type, text)
For an example usage, you can check out a really old script of mine.
https://otland.net/threads/xikinis-free-scripting-service-0-3-7-0-3-6-0-4.234306/page-2#post-2262314
 
Done, thank you very much.

Where does this text go? On the ring?
To be honest I'm not familiar with everything your trying to do.

You should be able to add it on using this function. (if you use description, it will set a special description onto the very end of an item.)
Code:
doItemSetAttribute(uid, type, text)
For an example usage, you can check out a really old script of mine.
https://otland.net/threads/xikinis-free-scripting-service-0-3-7-0-3-6-0-4.234306/page-2#post-2262314
5Seqcpl.png


Code:
local storage = 450650

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)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "A bright explosion bursts from inside the ring. You die.")
    end
    return true
end

function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    else
        setPlayerStorageValue(cid, storage, 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

in items.xml
Code:
<attribute key="allowdistread" value="true" />
 
Done, thank you very much.


5Seqcpl.png


Code:
local storage = 450650

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)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "A bright explosion bursts from inside the ring. You die.")
    end
    return true
end

function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    else
        setPlayerStorageValue(cid, storage, 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

in items.xml
Code:
<attribute key="allowdistread" value="true" />
Just a quick caution,
If players log out, directly after placing the ring on their finger (and stay logged out),
you'll receive a whole bunch of error's in your console from the addEvents.

If you pass the arguments over to a function like you did with "endRing", and then verify isPlayer(cid) like I tried to hint at previously,
you'll confirm if that player is actually online to send the messages to, and will not receive the errors in console.

(There may be another/better way to verify if cid is online, but this is the way I do it at least.)

Cheers. :D
 
Just a quick caution,
If players log out, directly after placing the ring on their finger (and stay logged out),
you'll receive a whole bunch of error's in your console from the addEvents.

If you pass the arguments over to a function like you did with "endRing", and then verify isPlayer(cid) like I tried to hint at previously,
you'll confirm if that player is actually online to send the messages to, and will not receive the errors in console.

(There may be another/better way to verify if cid is online, but this is the way I do it at least.)

Cheers. :D
It's possible to add "no logout" to script?
 
Kind of?
Code:
local condition = createConditionObject(CONDITION_INFIGHT)
setConditionParam(condition, CONDITION_PARAM_TICKS, 2 * 60 * 1000)
Code:
doAddCondition(cid, condition)
 
Kind of?
Code:
local condition = createConditionObject(CONDITION_INFIGHT)
setConditionParam(condition, CONDITION_PARAM_TICKS, 2 * 60 * 1000)
Code:
doAddCondition(cid, condition)
Tried with something like that but no effects.
Code:
local storage = 450654
local storage2 = 450655
local player = getPlayerPosition(pid)

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(player, 5555, 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(player, 5555, storage2 - 1)
    end
    return true
end

function onEquip(cid, item, slot)
    doAddCondition(cid, condition)
    setPlayerStorageValue(cid, storage2, 1)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    else
        setPlayerStorageValue(cid, storage, 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

function onLogout(cid)
if (getCreatureStorage(cid, storage2) == 1) then
doPlayerSendCancel(cid, "You can not log out during these effects.")
return false
end
return true
end
 
what is the problem with it? didnt follow thread so pls explain
Want to add no logout function, when player wear unstable ring of ending(id=22543), because when player logs out while script is running i have a lot of errors in console.
Simple by adding new storage "storage2" and checks when player have this storage can't log out.
Storage also should decay when process end.

setPlayerStorageValue(player, 5555, storage2 - 1)


Clean script

Code:
local storage = 450650

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)
    else
        doCreatureAddHealth(cid, -getCreatureHealth(cid))
        doPlayerRemoveItem(cid, 22543, 1)
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "A bright explosion bursts from inside the ring. You die.")
    end
    return true
end

function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    else
        setPlayerStorageValue(cid, storage, 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
 
Last edited:
well endRing already checks if player is valid, so thats fine
the problem is
Code:
       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
you could use a function like
Code:
function delayStuff(t, cid)
if not isPlayer(cid) then
return true
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, t.m)
if t.e then
doSendMagicEffect(getPlayerPosition(cid), t.e)
return true
end

   for m = 1, #messages do
addEvent(delayStuff, t[m], cid.uid)
        time = time + 10000
    end
 
zzzz

Untested.
Code:
local storage = 450650

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
    setPlayerStorageValue(cid, storage, 0)
    local chance = math.random(2)
    doPlayerRemoveItem(cid, 22543, 1)
    if chance == 1 then
        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)
        return true
    end
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "A bright explosion bursts from inside the ring. You die.")
    doCreatureAddHealth(cid, -getCreatureHealth(cid))
    return true
end

local function delayed_messages(cid, i)
    if not isPlayer(cid) then
        return true
    end
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, messages[i].m)
    return true
end

local function delayed_effect(cid, position, i)
    if not isPlayer(cid) then
        return true
    end
    doSendMagicEffect(position, messages[i].e)
    return true
end


function onEquip(cid, item, slot)
    if getPlayerStorageValue(cid, storage) == 1 then
        return true
    end
    setPlayerStorageValue(cid, storage, 1)
    local time = 0
    for i = 1, #messages do
        addEvent(delayed_messages, time, cid.uid, i)
        if messages[i].e then
            addEvent(delayed_effect, time, cid.uid, getPlayerPosition(cid.uid), i)
        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
    end
    setPlayerStorageValue(cid, storage, 0)
    return true
end
 
Last edited:
Ty guys but i think this is a better solution.

Code:
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

and in creaturescripts

Code:
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
Back
Top