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?
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