• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

make item only useable 4 times per character

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
923
Location
Chile
hello guys, i have an item that gives you skill, but i need it to have a limit per player, 4 times it's ok
can u help me plz??
this is the item

Code:
local skill, amount = SKILL_AXE, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 axe fighting.
function onUse(cid, item, fromPosition, itemEx, toPosition)
    for i = 1, amount do
        doPlayerAddSkillTry(cid, skill, (getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill) + 1) - getPlayerSkillTries(cid, skill)), false)
    end
    doSendMagicEffect(getThingPos(cid),math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
    doCreatureSay(cid, "SKILL UP!", TALKTYPE_ORANGE_1)
    doRemoveItem(item.uid, 1)
    return true
end
 
Solution
oh man im sorry i just had the time to check this and didn't work :( maybe i messed it up, this is what i have now
Code:
local skill, amount = SKILL_AXE, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 axe fighting.
function onUse(cid, item, fromPosition, itemEx, toPosition)
local storageValue = 63425
local timesUsed = getPlayerStorageValue(cid, 63425)
if timesUsed >= 4 then
    -- error message, effect or w/e
    return false
end
doPlayerSetStorageValue(cid, x, timesUsed == -1 and 1 or timesUsed + 1)
    for i = 1, amount do
        doPlayerAddSkillTry(cid, skill, (getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill) + 1) - getPlayerSkillTries(cid, skill)), false)
    end...
Thats fine, just look at my prev post and what I wrote;
LUA:
local storageValue = 10000

local timesUsed = getPlayerStorageValue(cid, storageValue)
if timesUsed >= 4 then
    -- error message, effect or w/e
    return false
end

doPlayerSetStorageValue(cid, storageValue, timesUsed == -1 and 1 or timesUsed + 1)

As you can see I changed x to storageValue, if you use this just change 10000 to the value you wanna use (the storage value id)

The timesUsed is the "get" function, to know what the value of a storage id is.
At the last line you can see the "set" function, where you can alter the storage id, in this case it will check if it's -1 (the starting value), if it is we bump that to 1 (first value we wanna use), if its not -1 we will just increase the value by 1.
Then we have the if statment to check if it's 4 or above, if it is we escape (send a warning message that you have reached the max value etc

oh man im sorry i just had the time to check this and didn't work :( maybe i messed it up, this is what i have now
Code:
local skill, amount = SKILL_AXE, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 axe fighting.
function onUse(cid, item, fromPosition, itemEx, toPosition)
local storageValue = 63425
local timesUsed = getPlayerStorageValue(cid, 63425)
if timesUsed >= 4 then
    -- error message, effect or w/e
    return false
end
doPlayerSetStorageValue(cid, x, timesUsed == -1 and 1 or timesUsed + 1)
    for i = 1, amount do
        doPlayerAddSkillTry(cid, skill, (getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill) + 1) - getPlayerSkillTries(cid, skill)), false)
    end
    doSendMagicEffect(getThingPos(cid),math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
    doCreatureSay(cid, "SKILL UP!", TALKTYPE_ORANGE_1)
    doRemoveItem(item.uid, 1)
    return true
end

also no error in console :(
 
oh man im sorry i just had the time to check this and didn't work :( maybe i messed it up, this is what i have now
Code:
local skill, amount = SKILL_AXE, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 axe fighting.
function onUse(cid, item, fromPosition, itemEx, toPosition)
local storageValue = 63425
local timesUsed = getPlayerStorageValue(cid, 63425)
if timesUsed >= 4 then
    -- error message, effect or w/e
    return false
end
doPlayerSetStorageValue(cid, x, timesUsed == -1 and 1 or timesUsed + 1)
    for i = 1, amount do
        doPlayerAddSkillTry(cid, skill, (getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill) + 1) - getPlayerSkillTries(cid, skill)), false)
    end
    doSendMagicEffect(getThingPos(cid),math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
    doCreatureSay(cid, "SKILL UP!", TALKTYPE_ORANGE_1)
    doRemoveItem(item.uid, 1)
    return true
end

also no error in console :(

As StreamSide wrote, you didn't use the storage value variable, changed it for you also try to keep your codes clean :p
LUA:
local skill, amount = SKILL_AXE, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 axe fighting.
local storageValue = 63425

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local timesUsed = getPlayerStorageValue(cid, storageValue)
    if timesUsed >= 4 then
        -- error message, effect or w/e
        return false
    end

    doPlayerSetStorageValue(cid, storageValue, timesUsed == -1 and 1 or timesUsed + 1)

    for i = 1, amount do
        doPlayerAddSkillTry(cid, skill, (getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill) + 1) - getPlayerSkillTries(cid, skill)), false)
    end

    doSendMagicEffect(getThingPos(cid), math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
    doCreatureSay(cid, "SKILL UP!", TALKTYPE_ORANGE_1)
    doRemoveItem(item.uid, 1)

    return true
end
 
Solution
Back
Top