• 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 Still receiving the rewarditem onAdvance

Denziz

New Member
Joined
May 2, 2013
Messages
81
Reaction score
4
What I am trying to do here in this piece of code is, if you are a sorcerer or a master sorcerer and your level is equal or above level 20. You will get an item, however you will NOT be able to get that item again if you go below level 20 and level up to 20 again (so you wont be able to exploit this by dying and then level up again).

Basically that is what the storage values thingy comes in handy right?

So I am checking if the players storage value is less than 0 (I do that because the default storage value is -1 I believe)

IF it is less than 0 (storage value has not been touched), proceed with the code. But then I give the item and ADD a storage value + key to the player. But I level up once more and I still receive the item, WHY?

Code:
local storage = 1234

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 5 and getPlayerLevel(cid) >= 20 and player:getStorageValue(cid, storage) < 0 then
        doPlayerAddItem(cid, 2188, 1)
        player:setStorageValue(storage, 1)
        doPlayerSendTextMessage(cid, 20, "You have been awarded...")
    end
    return true
end
 
What I am trying to do here in this piece of code is, if you are a sorcerer or a master sorcerer and your level is equal or above level 20. You will get an item, however you will NOT be able to get that item again if you go below level 20 and level up to 20 again (so you wont be able to exploit this by dying and then level up again).

Basically that is what the storage values thingy comes in handy right?

So I am checking if the players storage value is less than 0 (I do that because the default storage value is -1 I believe)

IF it is less than 0 (storage value has not been touched), proceed with the code. But then I give the item and ADD a storage value + key to the player. But I level up once more and I still receive the item, WHY?

Code:
local storage = 1234

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 5 and getPlayerLevel(cid) >= 20 and player:getStorageValue(cid, storage) < 0 then
        doPlayerAddItem(cid, 2188, 1)
        player:setStorageValue(storage, 1)
        doPlayerSendTextMessage(cid, 20, "You have been awarded...")
    end
    return true
end

Since you set the storage value to 1 when they get the reward, can you not just do
Code:
player:getStorageValue(cid, storage) < 1
 
@Cornex

Thank you for the quick response, unfortunately it did not work. I still get the item if I level up once more...

Here is the updated code.

Code:
local storage = 1234

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 5 and getPlayerLevel(cid) >= 20 and player:getStorageValue(cid, storage) < 1 then
        doPlayerAddItem(cid, 2188, 1)
        player:setStorageValue(storage, 1)
        doPlayerSendTextMessage(cid, 20, "You have been awarded...")
    end
    return true
end
 
@Cornex

Thank you for the quick response, unfortunately it did not work. I still get the item if I level up once more...

Here is the updated code.

Code:
local storage = 1234

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 5 and getPlayerLevel(cid) >= 20 and player:getStorageValue(cid, storage) < 1 then
        doPlayerAddItem(cid, 2188, 1)
        player:setStorageValue(storage, 1)
        doPlayerSendTextMessage(cid, 20, "You have been awarded...")
    end
    return true
end

Saw it now,
Code:
player:getStorageValue(cid, storage) < 1
should be
Code:
player:getStorageValue(storage) < 1
 
@Cornex

Thats what I thought too haha, I just changed it and tested it. Still not working :/

Maybe this xD
Code:
local storage = 1234

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    local vocation = Vocation(player:getVocation())
    if vocation:getId() == 1 or vocation:getId() == 5 and skill == SKILL__LEVEL and newlevel == 20 and player:getStorageValue(storage) < 1 then
        player:addItem(2188, 1)
        player:setStorageValue(storage, 1)
        player:sendTextMessage(20, "You have been awarded...")
    end
    return true
end
 
@Cornex

Error at line 6: Vocation is a nil value.

Updated code:
Code:
local storage = 1234

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    local vocation = Vocation(player:getVocation())
    if vocation:getId() == 1 or vocation:getId() == 5 and skill == SKILL__LEVEL and newlevel == 20 and player:getStorageValue(storage) < 1 then
        player:addItem(2188, 1)
        player:setStorageValue(storage, 1)
        player:sendTextMessage(20, "You have been awarded...")
    end
    return true
end
 
@Cornex

Error at line 6: Vocation is a nil value.

Updated code:
Code:
local storage = 1234

function onAdvance(cid, skill, oldlevel, newlevel)
    local player = Player(cid)
    local vocation = Vocation(player:getVocation())
    if vocation:getId() == 1 or vocation:getId() == 5 and skill == SKILL__LEVEL and newlevel == 20 and player:getStorageValue(storage) < 1 then
        player:addItem(2188, 1)
        player:setStorageValue(storage, 1)
        player:sendTextMessage(20, "You have been awarded...")
    end
    return true
end

Try this
Code:
function onAdvance(cid, skill, oldlevel, newlevel)
    local storage = 12345
    local player = Player(cid)
    local vocation = player:getVocation()
    if skill == SKILL_LEVEL and newlevel >= 20 and (vocation:getId() == 1 or vocation:getId() == 5) and (player:getStorageValue(storage) > 0) == false then
        player:addItem(2188, 1)
        player:setStorageValue(storage, 1)
        player:sendTextMessage(20, "You have been awarded...")
    end
    return true
end
 
@Cornex

Nice mate it works, but how would I make it so the if statements are separate?

Tried this but it doesnt work. I dont get anything and no errors.
Code:
function onAdvance(cid, skill, oldlevel, newlevel)
    local storage = 12345
    local player = Player(cid)
    local vocation = player:getVocation()
    if skill == SKILL_LEVEL then
        if newlevel >= 20 then 
            if (vocation:getId() == 1 or vocation:getId() == 5) then
                if (player:getStorageValue(storage) > 0) == false then
                    player:addItem(2188, 1)
                    player:setStorageValue(storage, 1)
                    player:sendTextMessage(20, "You have been awarded...")
                end
            end
        end
    end
    return true
end
 
If you really want it all broken down into different if statements, here is an example with some comments/changes explaining why everything was done the way it was.

Code:
function onAdvance(player, skill, oldlevel, newlevel) -- changed cid to player to prevent future confusion
    -- local storage = 12345 -- we dont need this because it's pointless, storage is not used enough in this script to make it worth while
    -- local player = Player(cid) -- we dont need this anymore because onAdvance already has player userdata
    if(skill == SKILL_LEVEL and newlevel >= 20) then -- check to make sure skill is level and the level is greater or equal to 20
        local vocation = player:getVocation() -- moved this after the skill check for efficiency
        if(vocation:getId() == 1 or vocation:getId() == 5) then -- check if player is master/sorc
            if(player:getStorageValue(12345) <= 0) then -- check that the storage is less than or equal to 0
                player:addItem(2188, 1)
                player:setStorageValue(12345, 1)
                player:sendTextMessage(20, "You have been awarded...")
            end
        end
    end
    return true
end
 
@Danger II

I appreciate your help but I am not looking for a finished script, I want to learn to script xD

@Xagul

I tried your code but nothing happens, no errors in the console or anything. Maybe I should try to debug it and check where the code stops at?

Updated code:
Code:
function onAdvance(player, skill, oldlevel, newlevel) -- changed cid to player to prevent future confusion
    if(skill == 8 and newlevel >= 20) then -- check to make sure skill is level and the level is greater or equal to 20
        local vocation = player:getVocation() -- moved this after the skill check for efficiency
        if(vocation:getId() == 1 or vocation:getId() == 5) then -- check if player is master/sorc
            if(player:getStorageValue(12345) <= 0) then -- check that the storage is less than or equal to 0
                player:addItem(2188, 1)
                player:setStorageValue(12345, 1)
                player:sendTextMessage(20, "You have been awarded...")
            end
        end
    end
    return true
end

EDIT: The if statement that is checking the storage value is stopping the code from proceeding. I commented it out and I got the item...

Updated code:
Code:
function onAdvance(player, skill, oldlevel, newlevel) -- changed cid to player to prevent future confusion
    print(getPlayerLevel(player))
    if(skill == 8 and newlevel >= 20) then -- check to make sure skill is level and the level is greater or equal to 20
        local vocation = player:getVocation() -- moved this after the skill check for efficiency
        print(getPlayerVocation(player))
        if(vocation:getId() == 1 or vocation:getId() == 5) then -- check if player is master/sorc
            --if player:getStorageValue(12345) <= 0 then -- check that the storage is less than or equal to 0
                player:addItem(2188, 1)
                player:setStorageValue(12345, 1)
                player:sendTextMessage(20, "You have been awarded...")
           -- end
        end
    end
    return true
end
 
Last edited:
When troubleshooting something like this, once you locate where the script is "hanging", you should print out the stuff you are checking. In this case you should print the storage value being checked.
Code:
print(player:getStorageValue(12345))

I think you will find that the storage has already been set to a value > 0, which is why it is not giving the reward.
 
Back
Top