• 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 Advance reward problem

Baiakym

New Member
Joined
Aug 28, 2015
Messages
15
Reaction score
2
Hello, I have a problem with script advance reward. it functions normally but for the reward function, the character needs to level up the exact level ...

example: i am lvl 49, kill monster and up to level 50 = win reward

but if i am lvl 49, kill monster and up to level 51 = dont win reward

this is bad because as I said my server is different and in some cases like invasions, the players evolve 2-3 level at once, but he wanted them to win the reward of the previous level...

function onAdvance(cid, skill, oldLevel, newLevel)
local storage = 30700
local config = {
[30] = {item = 2160, count = 1},
[50] = {item = 2160, count = 2},
[80] = {item = 2160, count = 3},
[100] = {item = 2157, count = 4},
[150] = {item = 2157, count = 5},
[200] = {item = 2157, count = 100},
}

if(skill == 8)then
for level, info in pairs(config) do
if(newLevel == level and newLevel > getPlayerStorageValue(cid, storage))then
doPlayerAddItem(cid, info.item, info.count)
doPlayerSendTextMessage(cid, 27, "Parabéns você atingiu o level "..newLevel.." e ganhou "..info.count.." "..getItemNameById(info.item)..".")
setPlayerStorageValue(cid, storage, newLevel)
break
end
end
end
return true
end
 
try this:
Code:
function onAdvance(cid, skill, oldLevel, newLevel)
    local storage = 30700
    local levels = {30, 50, 80, 100, 150, 200}
    local config = {
        [30] = {item = 2160, count = 1},
        [50] = {item = 2160, count = 2},
        [80] = {item = 2160, count = 3},
        [100] = {item = 2157, count = 4},
        [150] = {item = 2157, count = 5},
        [200] = {item = 2157, count = 100},
    }

    if skill == 8 then
        for _,level in ipairs(levels) do
            if newLevel >= level and level > getPlayerStorageValue(cid, storage) then
                doPlayerAddItem(cid, config[level].item, config[level].count)
                doPlayerSendTextMessage(cid, 27, "Parabéns você atingiu o level "..newLevel.." e ganhou "..config[level].count.." "..getItemNameById(config[level].item)..".")
                setPlayerStorageValue(cid, storage, level)
            end
        end
    end
    return true
end
 
No need to use a for loop :)
Just use the newLevel to index the table
Code:
    local storage = 30700
    local levels = {
        [30] = {item = 2160, count = 1},
        [50] = {item = 2160, count = 2},
        [80] = {item = 2160, count = 3},
        [100] = {item = 2157, count = 4},
        [150] = {item = 2157, count = 5},
        [200] = {item = 2157, count = 100}
    }

    function onAdvance(cid, skill, oldLevel, newLevel)
        if skill == 8 then
            if levels[newLevel] ~= nil and newLevel > getPlayerStorageValue(cid, storage) then
                doPlayerAddItem(cid, levels[newLevel].item, levels[newLevel].count)
                doPlayerSendTextMessage(cid, 27, "Parabéns você atingiu o level "..newLevel.." e ganhou "..levels[newLevel].count.." "..getItemNameById(levels[newLevel].item)..".")
                setPlayerStorageValue(cid, storage, newLevel)
            end
        end
        return true
    end
 
No need to use a for loop :)
Just use the newLevel to index the table
Code:
    local storage = 30700
    local levels = {
        [30] = {item = 2160, count = 1},
        [50] = {item = 2160, count = 2},
        [80] = {item = 2160, count = 3},
        [100] = {item = 2157, count = 4},
        [150] = {item = 2157, count = 5},
        [200] = {item = 2157, count = 100}
    }

    function onAdvance(cid, skill, oldLevel, newLevel)
        if skill == 8 then
            if levels[newLevel] ~= nil and newLevel > getPlayerStorageValue(cid, storage) then
                doPlayerAddItem(cid, levels[newLevel].item, levels[newLevel].count)
                doPlayerSendTextMessage(cid, 27, "Parabéns você atingiu o level "..newLevel.." e ganhou "..levels[newLevel].count.." "..getItemNameById(levels[newLevel].item)..".")
                setPlayerStorageValue(cid, storage, newLevel)
            end
        end
        return true
    end
this will result in the same issue, if newLevel is 51 from 49, it will not get a hit in the table
 
ok, try this :)
Code:
    local storage = 30700
    local levels = {
        {level = 30, item = 2160, count = 1},
        {level = 50, item = 2160, count = 2},
        {level = 80, item = 2160, count = 3},
        {level = 100, item = 2157, count = 4},
        {level = 150, item = 2157, count = 5},
        {level = 200, item = 2157, count = 100}
    }

    function onAdvance(cid, skill, oldLevel, newLevel)
        if skill == 8 then
            local count = 0
            for i = 1, #levels do
                if newLevel >= levels[i].level and i > getPlayerStorageValue(cid, storage) then
                    doPlayerAddItem(cid, levels[i].item, levels[i].count)
                    doPlayerSendTextMessage(cid, 27, "Parabéns você atingiu o level "..levels[i].level.." e ganhou "..levels[i].count.." "..getItemNameById(levels[i].item)..".")
                    count = i
                end
            end
            setPlayerStorageValue(cid, storage, count > 0 and count or getPlayerStorageValue(cid, storage))
        end
        return true
    end
 
ok, try this :)
Code:
    local storage = 30700
    local levels = {
        {level = 30, item = 2160, count = 1},
        {level = 50, item = 2160, count = 2},
        {level = 80, item = 2160, count = 3},
        {level = 100, item = 2157, count = 4},
        {level = 150, item = 2157, count = 5},
        {level = 200, item = 2157, count = 100}
    }

    function onAdvance(cid, skill, oldLevel, newLevel)
        if skill == 8 then
            local count = 0
            for i = 1, #levels do
                if newLevel >= levels[i].level and i > getPlayerStorageValue(cid, storage) then
                    doPlayerAddItem(cid, levels[i].item, levels[i].count)
                    doPlayerSendTextMessage(cid, 27, "Parabéns você atingiu o level "..levels[i].level.." e ganhou "..levels[i].count.." "..getItemNameById(levels[i].item)..".")
                    count = i
                end
            end
            setPlayerStorageValue(cid, storage, count > 0 and count or getPlayerStorageValue(cid, storage))
        end
        return true
    end
Not worked ... have not seen any error, just can not get the reward, but thanks for the help :)

try this:
Code:
function onAdvance(cid, skill, oldLevel, newLevel)
    local storage = 30700
    local levels = {30, 50, 80, 100, 150, 200}
    local config = {
        [30] = {item = 2160, count = 1},
        [50] = {item = 2160, count = 2},
        [80] = {item = 2160, count = 3},
        [100] = {item = 2157, count = 4},
        [150] = {item = 2157, count = 5},
        [200] = {item = 2157, count = 100},
    }

    if skill == 8 then
        for _,level in ipairs(levels) do
            if newLevel >= level and level > getPlayerStorageValue(cid, storage) then
                doPlayerAddItem(cid, config[level].item, config[level].count)
                doPlayerSendTextMessage(cid, 27, "Parabéns você atingiu o level "..newLevel.." e ganhou "..config[level].count.." "..getItemNameById(config[level].item)..".")
                setPlayerStorageValue(cid, storage, level)
            end
        end
    end
    return true
end
Work!!!! thanks bro.
 
That's weird I tested the code too :(
See
Code:
    local levels = {
        {level = 30, item = 2160, count = 1},
        {level = 50, item = 2160, count = 2},
        {level = 80, item = 2160, count = 3},
        {level = 100, item = 2157, count = 4},
        {level = 150, item = 2157, count = 5},
        {level = 200, item = 2157, count = 100}
    }

    local playerLevel = 149
    local playerStorage = 2


    function getReward(levels, currentLevel, x)
        local s = 0
        for i = 1, #levels do
            if currentLevel >= levels[i].level and i > x then
                print(" currentLevel "..currentLevel.. " - reward level "..levels[i].level .. " item " .. levels[i].item .. " count "..levels[i].count)
                s = i
            end

        end
        s = s > 0 and s or x
        print(" storage value "..s)
    end

    getReward(levels, playerLevel, playerStorage)

Code:
currentLevel 149 - reward level 80 item 2160 count 3
currentLevel 149 - reward level 100 item 2157 count 4
storage value 4
 
Not worked ... have not seen any error, just can not get the reward, but thanks for the help :)
I think I know why it didn't work for you, godoyxd's code worked better because you were already storing the level as a storage value, since you probably never reset the storage value the current storage value was always higher then i and that is why it didn't work.

If you test that code above with say -1 as a playerStorageValue being returned and your level idk 50 it will give u level 30 and 50.
It uses the index of the table rather than the level to generate the storage value.
Anyhow it was worth a shot :)
 
I think I know why it didn't work for you, godoyxd's code worked better because you were already storing the level as a storage value, since you probably never reset the storage value the current storage value was always higher then i and that is why it didn't work.

If you test that code above with say -1 as a playerStorageValue being returned and your level idk 50 it will give u level 30 and 50.
It uses the index of the table rather than the level to generate the storage value.
Anyhow it was worth a shot :)

Indeed, the problem must have been the storages, I changed and tested again

It worked perfectly: D
 
Back
Top