• 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...
LUA:
local timesUsed = getPlayerStorageValue(cid, x)
if timesUsed >= 4 then
    -- error message, effect or w/e
    return false
end

doPlayerSetStorageValue(cid, x, timesUsed + 1)
 
LUA:
local timesUsed = getPlayerStorageValue(cid, x)
if timesUsed >= 4 then
    -- error message, effect or w/e
    return false
end

doPlayerSetStorageValue(cid, x, timesUsed + 1)
awesoem thanks! should i just paste that at the beginning? D: dont want to mess it up
 
Yes after this;
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)


Oh man, i didnt say this i didn't thought it was important, but know i know it is >.< my bad
i have 6 items like this, for every skill and if i paste your code in the 6 items, this is what happened

i used one random of the six items, i used it 5 times, yes 5 not 4, and then i wasn't able to use any of the other items :C
 
Oh man, i didnt say this i didn't thought it was important, but know i know it is >.< my bad
i have 6 items like this, for every skill and if i paste your code in the 6 items, this is what happened

i used one random of the six items, i used it 5 times, yes 5 not 4, and then i wasn't able to use any of the other items :C

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

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

Always forget that storages start at -1 :p
Not sure what you ment with the first part, but if you want to be able to use all items 4 times you need to set diffrent storage values.
 
LUA:
local timesUsed = getPlayerStorageValue(cid, x)
if timesUsed >= 4 then
    -- error message, effect or w/e
    return false
end

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

Always forget that storages start at -1 :p
Not sure what you ment with the first part, but if you want to be able to use all items 4 times you need to set diffrent storage values.


awesome man thanks, last thing, to set different storage values i have to change the x to a value i want?
 
Last edited:
awesome man thanks, last thing, to set different storage values i have to change the x to a value i want?
I'll show you a lil bit of what I know about Storages!
LUA:
--Setting Player StorageValue in your script:
doPlayerSetStorageValue(cid, x, timesUsed == -1 and 1 or timesUsed + 1)
(cid,  StorageID, StorageValue)
    cid = CreatureID --CreatureID of the Player or Monster the script is calling for.
    -1 = StorageID --Place that holds the numeric value, StorageValue.
    timesUsed = StorageValue --The number that will be stored in StorageValue.
So, that line is interpreted as..
1) Gets CreatureID
2) Sets StorageID to "x"
3) Sets the StorageValue to "timesUsed" --Which, in your script, is the amount of times you used the weapon.

Let's see another example here:
LUA:
doCreatureSetStorage(cid, StorageID, StoreageValue) --Setting Player StorageValue
    --We can give the player a storage of 666, and give that a storage value of 69
doCreatureSetStorage(cid, 666, 69)
    --Which in turn, sets the player's current StorageID to 666, and gives it a base value of 69.

However, the script can also just interpret the StorageID as a generic value by using a variable.
LUA:
doCreatureSetStorage(cid, x, 5)
    --Where the StorageID is simply "x" and the StorageValue is interpreted as "5" initially.

When using StorageValues, it's important to understand that the player's default StorageValue is -1.
So, using this script I can show you an example..
Checking if your StorageValue is greater than or less than 0:
LUA:
local getStorage = getCreatureStorage(cid,x)
if getStorage(cid, 500, < 0) then
    print("Your StorageValue is less than 0.")
else
    print("Your StorageValue is greater than 0.")
end
Item that, when used, sets your StorageValue to 1:
LUA:
local getStorage = getCreatureStorage(cid,x)
    function onUse(player, item .. etc etc)
        if getStorage(cid, 500, < 0) then
            doCreatureSetStorage(cid, 500, 1)
end
After using the item in the second script, your StorageValue on StorageID 500 will be set to 1.
If your StorageValue is greater than 0, the first script will print that outcome.

Storages are a great feature that are not very hard to learn, I hope I gave you some insight as to how they work!:)
 
awesome man thanks, last thing, to set different storage values i have to change the x to a value i want?

Correct, you could set the first one to ex 10000 then the second one to 10001 etc
Just make sure you don't have anything else thats using that storage id, lets say the DHQ reward uses 10001 then they can only use ex 3 of the items or 4 but not complete the quest.
 
I'll show you a lil bit of what I know about Storages!
LUA:
--Setting Player StorageValue in your script:
doPlayerSetStorageValue(cid, x, timesUsed == -1 and 1 or timesUsed + 1)
(cid,  StorageID, StorageValue)
    cid = CreatureID --CreatureID of the Player or Monster the script is calling for.
    -1 = StorageID --Place that holds the numeric value, StorageValue.
    timesUsed = StorageValue --The number that will be stored in StorageValue.
So, that line is interpreted as..
1) Gets CreatureID
2) Sets StorageID to "x"
3) Sets the StorageValue to "timesUsed" --Which, in your script, is the amount of times you used the weapon.

Let's see another example here:
LUA:
doCreatureSetStorage(cid, StorageID, StoreageValue) --Setting Player StorageValue
    --We can give the player a storage of 666, and give that a storage value of 69
doCreatureSetStorage(cid, 666, 69)
    --Which in turn, sets the player's current StorageID to 666, and gives it a base value of 69.

However, the script can also just interpret the StorageID as a generic value by using a variable.
LUA:
doCreatureSetStorage(cid, x, 5)
    --Where the StorageID is simply "x" and the StorageValue is interpreted as "5" initially.

When using StorageValues, it's important to understand that the player's default StorageValue is -1.
So, using this script I can show you an example..
Checking if your StorageValue is greater than or less than 0:
LUA:
local getStorage = getCreatureStorage(cid,x)
if getStorage(cid, 500, < 0) then
    print("Your StorageValue is less than 0.")
else
    print("Your StorageValue is greater than 0.")
end
Item that, when used, sets your StorageValue to 1:
LUA:
local getStorage = getCreatureStorage(cid,x)
    function onUse(player, item .. etc etc)
        if getStorage(cid, 500, < 0) then
            doCreatureSetStorage(cid, 500, 1)
end
After using the item in the second script, your StorageValue on StorageID 500 will be set to 1.
If your StorageValue is greater than 0, the first script will print that outcome.

Storages are a great feature that are not very hard to learn, I hope I gave you some insight as to how they work!:)
wow thank you so much for this! i haven't had the time to read it yet, but i will for sure thanks! :D

Correct, you could set the first one to ex 10000 then the second one to 10001 etc
Just make sure you don't have anything else thats using that storage id, lets say the DHQ reward uses 10001 then they can only use ex 3 of the items or 4 but not complete the quest.
thank you man!
 
Last edited by a moderator:
Correct, you could set the first one to ex 10000 then the second one to 10001 etc
Just make sure you don't have anything else thats using that storage id, lets say the DHQ reward uses 10001 then they can only use ex 3 of the items or 4 but not complete the quest.
oh man im sorry but i did this to my scripts
Code:
local timesUsed = getPlayerStorageValue(cid, 63425)

like that, and a different number for each item but that didn't work, i can use the items multiple times, what am i doing wrong?
 
oh man im sorry but i did this to my scripts
Code:
local timesUsed = getPlayerStorageValue(cid, 63425)

like that, and a different number for each item but that didn't work, i can use the items multiple times, what am i doing wrong?

Did you remember the set function aswell?
 
im sorry i don't know what that means :(

The get function is getPlayerStorageValue(cid, id)
The set function is setPlayerStorageValue(cid, id, value)

Unless you set the value you can't use the get function, it will just return -1 and never increase = players can use it as many times as they like
 
The get function is getPlayerStorageValue(cid, id)
The set function is setPlayerStorageValue(cid, id, value)

Unless you set the value you can't use the get function, it will just return -1 and never increase = players can use it as many times as they like
Hello wibbenz, glad to tell you that he doesnt want a good answer, he wants the solution.
 
Hello wibbenz, glad to tell you that he doesnt want a good answer, he wants the solution.

And that is the solution, he isn't setting the storage value he is just trying to get it.
You know it's not good to always do everything for people, let them try and learn insted.

If you wish to do everything feel free to do that, but just remember that next week when they have the same problem they won't know what to do.
 
I appreciate a lot the way you explain @WibbenZ but i can't understand what u are saying, i appreciate you are trying to teach, but it's like understanding a language without knowing the abc ;( when i see your explanations something makes sense but i can't fully understand it in order to edit the file and knowing where to put what...is not like im a complete noob btw xd some things just escape my knowledge :(
and yes, i still don't know what to do D:

i understand now that i have to set the storage value before getting it, you can't get smething you don't have right? but i don't know how to write it or where to put it
 
Last edited:
I appreciate a lot the way you explain @WibbenZ but i can't understand what u are saying, i appreciate you are trying to teach, but it's like understanding a language without knowing the abc ;( when i see your explanations something makes sense but i can't fully understand it in order to edit the file and knowing where to put what...is not like im a complete noob btw xd some things just escape my knowledge :(
and yes, i still don't know what to do D:

i understand now that i have to set the storage value before getting it, you can't get smething you don't have right? but i don't know how to write it or where to put it

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
 
Back
Top