Your ">=" test will test true every level after 19, and is probably why you're getting the reward too often.
Take those stupid text comparisons out of your if-statement conditions, clean up your test conditions, and try again. if you really need that Storage, put usable values into it.
Code:
local sat = getPlayerStorageValue(cid, 93010) == -1 and "Values: '" .. le
vel .. "'" or getPlayerStorageValue(cid, 93010) .. ",'" .. level .. "'"
setPlayerStorageValue(cid, 93010, sat)
"Values: '" .. level .. "'" is a constant - it's always going to return the same thing.
Using unnecessary quotes in a text value is asking for trouble with escape characters.
Remove them from the contents of the storage, - if you want them on output, add them on output.[/CODE]
BTW - I can't see what you're using that storage for at all.
You get "previous level" and "new level" from the onAdvance() function call, so if all you want to do it give the player something at the specific levels in that table, you have no need for Storage:
Code:
function onAdvance(cid, skill, oldLevel, newLevel)
local config = {
[20] = {item = 2160, count = 3},
[50] = {item = 2160, count = 4},
[100] = {item = 2160, count = 8},
[200] = {item = 2160, count = 10},
[300] = {item = 2160, count = 20},
[400] = {item = 2160, count = 30},
}
if skill == 8 then
for level, info in pairs(config) do
if (newLevel == level) then
doPlayerAddItem(cid, info.item, info.count)
doPlayerSendTextMessage(cid, 27, "Congratulation você atingiu o level "..newLevel.." e ganhou "..info.count.." "..getItemNameById(info.item)..".")
end
end
end
return TRUE
end
if skill level is exactly 8, this will give the correct reward at levels 20, 50, 100, 200, 300, and 400; nothing at other levels; nothing at other skill levels
If you want to use successive indexes from the table to delimit a range, they are data, not keys.
Put them into the array as data, traverse it using a "for 1, #table" loop, and remember the previous value in a variable (requires special-case handling for the first element of course, but that's easy with an integer-indexed array). Then your test is:
if (newLevel >= savedLevel) and (newLevel <= level) then
...
end
You could also put both the start and the end values for each range into the Table, because there are so few elements That would make the coding easier (no special case on element 1), but would be a pain if you had a lot of elements.
Code:
local config = {
{lowerBound=20, upperBound=49, item = 2160, count = 3},
{lowerBound=50, upperBound=99, item = 2160, count = 4},
{lowerBound=100, upperBound=199, item = 2160, count = 8},
{lowerBound=200, upperBound=299, item = 2160, count = 10},
{lowerBound=300, upperBound=399, item = 2160, count = 20},
{lowerBound=400, upperBound=math.huge, item = 2160, count = 30},
}
for index, info in ipairs(config) do
if (newLevel >= info.lowerBound) and (newLevel <= info.upperBound) then
doPlayerAddItem(cid, info.item, info.count)
break
end
end
BTW - don't underestimate the value of clean code.
Complicated conditions and unnecessarily repeated code lead to bugs when you change things later.