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

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
211
hi, i'm making the scripts of broken ring of ending
Code:
function text1(player)
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
    if not ringItem then
        return true
    end
    if not player then
        return true
    end
    if player then
        if ringItem then
            player:getPosition():sendMagicEffect(12)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'msg1.')
            addEvent(text2, 10 * 1000, player)
        end
    end
end
function text2(player)
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
    if not ringItem then
        return true
    end
    if not player then
        return true
    end
    if player then
        if ringItem then
            player:getPosition():sendMagicEffect(38)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'msg2')
            addEvent(text3, 10 * 1000, player)
        end
    end
end
function text3(player)
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
    if not ringItem then
        return true
    end
    if not player then
        return true
    end
    if player then
        if ringItem then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'msg3')
            addEvent(text4, 10 * 1000, player)
        end
    end
end
function text4(player)
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
    if not ringItem then
        return true
    end
    if not player then
        return true
    end
    if player then
        if ringItem then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'msg4.')
            addEvent(text5, 10 * 1000, player)
        end
    end
end
function text5(player)
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
    if not ringItem then
        return true
    end
    if not player then
        return true
    end
    if player then
        if ringItem then
            local chance = math.random(2)
            if chance == 1 then
                player:getPosition():sendMagicEffect(18)
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'msg5')
                addEvent(text6, 10 * 1000, player)
            else
                doTargetCombatHealth(0, player, COMBAT_DEATHDAMAGE, -300000, -300000, CONST_ME_MORTAREA)
            end
        end
    end
end

function text6(player)
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
    if not ringItem then
        return true
    end
    if not player then
        return true
    end
    if player then
        if ringItem then
            ringItem:transform(22516)
            player:getPosition():sendMagicEffect(38)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'msg6')
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
    if not ringItem then
        return false
    end
    if player then
        addEvent(text1, 10 * 1000, player)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'msgOnUse')
        player:getPosition():sendMagicEffect(1)
    end
    return true
end
I need to check in all events if the player is "online" and the ring is in the correct slot to do the functions, also, if I logout and back, sometimes got crash, and the "effects" stay sending ? wtf ... I'll explain better, I use the ring, then logout, and then back again, the effects stay send in the last position before I logout
any question, please feel free to ask :D
thank you
 
The point of writing a function is so its reusable, you don't create 6 functions where 4 of them are identical.
 
is not, all functions have differents messages and effects
I just not get the msgs yet, but is different
All your doing is copy and pasting the same function using a different msg or effect, there is a thing called recursion.
How are you going to tell me they are not the same.. unlike you i know how to program.
If the moderators want to remove my post.. i could care even less about this community.. these people need to know how to code and your not helping them 1 bit by spoon feeding them the answers.

Learn the god dam language already, your never going to be able to write shit for your server if you never bother to learn lua.. that is the truth of the matter.
 
All your doing is copy and pasting the same function using a different msg or effect, there is a thing called recursion.
How are you going to tell me they are not the same.. unlike you i know how to program.
If the moderators want to remove my post.. i could care even less about this community.. these people need to know how to code and your not helping them 1 bit by spoon feeding them the answers.

Learn the god dam language already, your never going to be able to write shit for your server if you never bother to learn lua.. that is the truth of the matter.

Wow.. Are you okay? Programming isn't something you pick up instantly. It takes time to learn.
 
All your doing is copy and pasting the same function using a different msg or effect, there is a thing called recursion.
How are you going to tell me they are not the same.. unlike you i know how to program.
If the moderators want to remove my post.. i could care even less about this community.. these people need to know how to code and your not helping them 1 bit by spoon feeding them the answers.

Learn the god dam language already, your never going to be able to write shit for your server if you never bother to learn lua.. that is the truth of the matter.
I know recursion, but in what I want to do, not is neeed.
I don't want to "improve" my code, I want to make it work without any crash
if you don't will help, why are commenting here?
 
Last edited:
Here is an example of how we can expand addEvent and our function to make the script more organized... I tried to add some comments so it can be easier to understand. For me it is easiest to learn by example, so I hope this can help you as well.

As always, if another member notices something that can be improved please let me know.

Code:
local config = {
    [1] = {msg = 'msg1', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = false},
    [2] = {msg = 'msg2', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = false},
    [3] = {msg = 'msg3', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = false},
    [4] = {msg = 'msg4', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = false},
    [5] = {msg = 'msg5', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = true, transformRing = false}, -- sendDamage is true here because on part 5 we want to do random chance of damage or event 6
    [6] = {msg = 'msg6', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = true} -- transformRing is true here because if it makes it to step 6 then we will transform the ring
}

function sendTextToPlayer(player, message, damage, transform, magicEffect)
    local player = Player(player)
    if not player then
        return true
    end
  
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
  
    if not ringItem then
        return true
    end
  
     -- here for Event 5 we will do a random chance test
    if damage then
        if math.random(2) == 1 then
            -- I disabled this for testing purposes and added the comment 'BOOM!' as a replacement, be sure to uncomment it on your server
            -- doTargetCombatHealth(0, player, COMBAT_DEATHDAMAGE, -300000, -300000, CONST_ME_MORTAREA)
            player:say('BOOM!', TALKTYPE_MONSTER_SAY)
            return true
        end
        -- if we make it to this part that means the player is still alive and the random chance was equal to 2
        -- notice in this addEvent we are calling 'config[6]' which is already set in our config table
        addEvent(sendTextToPlayer, 10 * 1000, player:getId(), config[6].msg, config[6].sendDamage, config[6].transformRing, config[6].magicEffect)
    end
  
    -- here for Event 6 we will transform the ring
    if transform then
        ringItem:transform(22516)
    end
  
    player:getPosition():sendMagicEffect(magicEffect)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
    if not ringItem then
        return false
    end
    if player then
        for i= 1,5 do -- Note: I did 1 through 5 and not #config, this is because for event 6 we need to check if the player failed or succeeded
            addEvent(sendTextToPlayer, i * 10 * 1000, player:getId(), config[i].msg, config[i].sendDamage, config[i].transformRing, config[i].magicEffect)
        end
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'msgOnUse')
        player:getPosition():sendMagicEffect(CONST_ME_DRAWBLOOD)
    end
    return true
end
 
Last edited:
Wow.. Are you okay? Programming isn't something you pick up instantly. It takes time to learn.
The guy has been on these forums since 2010, you would think by now he would learn the language already but instead he doesn't, he listens to knuckle head people on here telling him he doesn't need to.

@imkingran
Learning by example is great up to a certain point but you need to learn the core language to do anything meaningful, you can't copy and paste for the rest of your life and it is a terrible habit to form.
 
Here is an example of how we can expand addEvent and our function to make the script more organized... I tried to add some comments so it can be easier to understand. For me it is easiest to learn by example, so I hope this can help you as well.

As always, if another member notices something that can be improved please let me know.

Code:
local config = {
    [1] = {msg = 'msg1', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = false},
    [2] = {msg = 'msg2', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = false},
    [3] = {msg = 'msg3', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = false},
    [4] = {msg = 'msg4', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = false},
    [5] = {msg = 'msg5', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = true, transformRing = false}, -- sendDamage is true here because on part 5 we want to do random chance of damage or event 6
    [6] = {msg = 'msg6', magicEffect = CONST_ME_DRAWBLOOD, sendDamage = false, transformRing = true} -- transformRing is true here because if it makes it to step 6 then we will transform the ring
}

function sendTextToPlayer(player, message, damage, transform, magicEffect)
    local player = Player(player)
    if not player then
        return true
    end
  
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
  
    if not ringItem then
        return true
    end
  
     -- here for Event 5 we will do a random chance test
    if damage then
        if math.random(2) == 1 then
            -- I disabled this for testing purposes and added the comment 'BOOM!' as a replacement, be sure to uncomment it on your server
            -- doTargetCombatHealth(0, player, COMBAT_DEATHDAMAGE, -300000, -300000, CONST_ME_MORTAREA)
            player:say('BOOM!', TALKTYPE_MONSTER_SAY)
            return true
        end
        -- if we make it to this part that means the player is still alive and the random chance was equal to 2
        -- notice in this addEvent we are calling 'config[6]' which is already set in our config table
        addEvent(sendTextToPlayer, 10 * 1000, player, config[6].msg, config[6].sendDamage, config[6].transformRing, config[6].magicEffect)
    end
  
    -- here for Event 6 we will transform the ring
    if transform then
        ringItem:transform(22516)
    end
  
    player:getPosition():sendMagicEffect(magicEffect)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local ringItem = player:getSlotItem(CONST_SLOT_RING)
    if not ringItem then
        return false
    end
    if player then
        for i= 1,5 do -- Note: I did 1 through 5 and not #config, this is because for event 6 we need to check if the player failed or succeeded
            addEvent(sendTextToPlayer, i * 10 * 1000, player:getId(), config[i].msg, config[i].sendDamage, config[i].transformRing, config[i].magicEffect)
        end
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'msgOnUse')
        player:getPosition():sendMagicEffect(CONST_ME_DRAWBLOOD)
    end
    return true
end
I've test, during the test
have only this 5 messages
Code:
11:47 msgOnUse
11:48 msg1
11:48 msg2
11:48 msg3
11:48 msg4
 
I agree @Codex NG that at some point real learning must come from your own efforts. In the future I won't re-write whole scripts. Instead I'll try my best to show an example of the concept using a random default script that serves no purpose other than for learning.

@silveralol

According to your script the first 4 messages were guaranteed. At message 5, there is a 50% chance that they player will receive damage (the words 'BOOM') or instead they will receive a message and if they received the message that means we then we can continue to part 6. In part 6 we transform the ring and send a last message.

Code:
11:59 msgOnUse
11:59 msg1
11:59 msg2
11:59 msg3
11:59 msg4
11:59 msg5 --> Here is the chance of either 1. Receive Damage and stop or 2. Send Msg and addEvent(6)
11:59 msg6
 
@silveralol

According to your script the first 4 messages were guaranteed. At message 5, there is a 50% chance that they player will receive damage (the words 'BOOM') or instead they will receive a message and if they received the message that means we then we can continue to part 6. In part 6 we transform the ring and send a last message.

Code:
11:59 msgOnUse
11:59 msg1
11:59 msg2
11:59 msg3
11:59 msg4
11:59 msg5 --> Here is the chance of either 1. Receive Damage and stop or 2. Send Msg and addEvent(6)
11:59 msg6
yes, I understand what you're saying, the only thing that don't go to msg5 or msg of "boom" ...
 
All your doing is copy and pasting the same function using a different msg or effect, there is a thing called recursion.
How are you going to tell me they are not the same.. unlike you i know how to program.
If the moderators want to remove my post.. i could care even less about this community.. these people need to know how to code and your not helping them 1 bit by spoon feeding them the answers.

Learn the god dam language already, your never going to be able to write shit for your server if you never bother to learn lua.. that is the truth of the matter.

What is wrong with you? Do you get off when you try to appear smarter than everyone else?

  • "there is a thing called recursion" - I don't think you know what that means, and I don't believe you know how to use it either, otherwise you would've used it in this function of yours (and no, recursion won't ever cause infinite loops if you know 'how to program' properly, and neither is recursion much more expensive than loops in Lua if you use the language correctly - learn Lua and maybe you will know what tail calls are and how to use them) https://otland.net/threads/traverse-_g.238205/ And lastly, you don't even need recursion to be able to traverse all the objects in a table - nesting loops is something a beginner would do. Maybe if you stop bashing people looking for help in a god damn support forum and look for help yourself (both psychological and programming related) you might be able to learn something.
  • "The point of writing a function is so its reusable" - Is that so? Tell me again how a function that uses an arbitrary upvalue is reusable. https://otland.net/threads/lua-switch-function.236989/
  • "All your doing is copy" - you're
  • "i could care even less about this community" - You could care even less? That means you care at all?
  • "and your not helping" - you're
  • "Learn the god dam" - are you sure you mean this dam?
  • "your never going" - yet again, you're
Seriously, take a minute (or maybe a week) to think about what you are doing, you're just a little script kiddie that thinks the little knowledge you have enables you to disrespect people. And seriously, at least write in proper grammar if you're so full of yourself.
 
What is wrong with you? Do you get off when you try to appear smarter than everyone else?

  • "there is a thing called recursion" - I don't think you know what that means, and I don't believe you know how to use it either, otherwise you would've used it in this function of yours (and no, recursion won't ever cause infinite loops if you know 'how to program' properly, and neither is recursion much more expensive than loops in Lua if you use the language correctly - learn Lua and maybe you will know what tail calls are and how to use them) https://otland.net/threads/traverse-_g.238205/ And lastly, you don't even need recursion to be able to traverse all the objects in a table - nesting loops is something a beginner would do. Maybe if you stop bashing people looking for help in a god damn support forum and look for help yourself (both psychological and programming related) you might be able to learn something.
  • "The point of writing a function is so its reusable" - Is that so? Tell me again how a function that uses an arbitrary upvalue is reusable. https://otland.net/threads/lua-switch-function.236989/
  • "All your doing is copy" - you're
  • "i could care even less about this community" - You could care even less? That means you care at all?
  • "and your not helping" - you're
  • "Learn the god dam" - are you sure you mean this dam?
  • "your never going" - yet again, you're
Seriously, take a minute (or maybe a week) to think about what you are doing, you're just a little script kiddie that thinks the little knowledge you have enables you to disrespect people. And seriously, at least write in proper grammar if you're so full of yourself.
I know more than I let on.. as for grammar who cares?
So that is all you have to throw at me a few threads I made.. oh noes let me hang up my keyboard lol
 
The guy has been on these forums since 2010, you would think by now he would learn the language already but instead he doesn't, he listens to knuckle head people on here telling him he doesn't need to.
omg i'm here since 2010... and then ? I came back to here less than 1 year, stop to tell that all need to learn the language, if you don't will help, stop this stupid things that you're doing here, anyone ask to you to came here to tell shit for all
 
I know more than I let on

Though you still can't inspect a table, maybe you will be so humble as to follow your own advice you so lividly give others and "learn the language". In this snippet you will find both recursive and non-recursive ways of inspecting every object of a table.

Code:
local ex = {
    hey = {
        nested_shit = {
            '1', '2', 3, function() end
        },

        print,
    },

    2, 7,

    'some random string',

    another_table = {
        newproxy(),
        'even some userdata',
        {{{{{{'if you\'re seeing this this shit works'}}}}}}
    }
}

local function levelPrint(level, ...)
    io.write(string.rep('\t', level))
    print(...)
end

local function formatPair(first, second)
    if type(first) == 'string' then
        first = '"' .. first .. '"'
    end
    return string.format('[%s] = %s', tostring(first), tostring(second))
end

function inspect(list)
    local stack = {list}
    local info = {}
    local level = 1
    print('{')

    while #stack ~= 0 do
        local current = stack[#stack]
        local index, value = next(current, info[current])
        if not index then
            table.remove(stack, #stack)
            info[current] = nil
            level = level - 1
            levelPrint(level, '},')
        else
            info[current] = index

            if type(value) == 'string' then
                levelPrint(level, formatPair(index, '"' .. value .. '",'))           
            elseif type(value) == 'table' then
                table.insert(stack, value)
                levelPrint(level, formatPair(index, '{'))
                level = level + 1
            else
                levelPrint(level, formatPair(index, value) .. ', ')    
            end
        end
    end
end

function recursive_inspect(list, level)
    level = level or 0
    if level == 0 then
        print('{')
    end
    for index, value in pairs(list) do
        if type(value) == 'string' then
            levelPrint(level + 1, formatPair(index, '"' .. value .. '",'))
        elseif type(value) == 'table' then
            levelPrint(level + 1, formatPair(index, '{'))
            recursive_inspect(value, level + 1)
        else
            levelPrint(level + 1, formatPair(index, value) .. ',')
        end
    end
    levelPrint(level, '},')
end

recursive_inspect(ex)

print('---')

inspect(ex)

Surprisingly I get no infinite loop using recursion... but maybe you're just not 'letting on' how you manage to do that while inspecting a table, right?
 
yes, I understand what you're saying, the only thing that don't go to msg5 or msg of "boom" ...

This is an example of what it looks like if you passed step 5:
bqziEqz.gif


This is an example if you don't pass step 5:
hAOG7Y6.gif
 
This is an example of what it looks like if you passed step 5:
bqziEqz.gif


This is an example if you don't pass step 5:
hAOG7Y6.gif
oh my god my bad, works perfectly !!!
also, I find something bad... if the player stay clicking at the ring will get a big spawn of the messages, I solved it with an exhaustion .. 300 seconds, just do this check...
Code:
if player:getStorageValue(Storage.RingOfEnding) > os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You are still exhausted from your last attempt at improve this ring.')
        return true
    end
before the last return true
Code:
player:setExhaustion(Storage.RingOfEnding, 300)
 
Last edited:
You should probably check the equipped ring's item id as well, unless you want players to have their crystal rings (or other rings) transformed into a ring of ending.
 
oh my god my bad, works perfectly !!!
also, I find something bad... if the player stay clicking at the ring will get a big spawn of the messages, I solved it with an exhaustion .. 300 seconds, just do this check...
Code:
if player:getStorageValue(Storage.RingOfEnding) > os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You are still exhausted from your last attempt at improve this ring.')
        return true
    end
before the last return true
Code:
player:setExhaustion(Storage.RingOfEnding, 300)

Keep editing it until you have it how you like it, all I did was take your first script and try to show you how it can be improved. It was not my intention to write a script for the Broken Ring of Ending/Ring of Ending but instead an attempt to teach someone a new trick. :)

So please compare your original and then my re-write and try to learn from it. If we faltered, surely someone will come along and teach us more ways to improve.
 
Back
Top