• 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 Make item only useable 4 times

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
921
Location
Chile
hello guys, i want an item that can only be used a X amount of times, in this case 4, plz guys can you help me achieve this?
i use otx 2.52 version 9.83

here is an item who gives sword skill lvl, so you can see why i want it limitated hehe

Code:
local skill, amount = SKILL_SWORD, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 sword 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
 
Test this, set local ITEMSTORAGE = 1000 to a nonused storage number.
Code:
local skill, amount = SKILL_SWORD, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 sword fighting.
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local ITEMSTORAGE = 1000
   local ITEMSTORAGE_VALUE = getPlayerStorageValue(cid, ITEMSTORAGE)
   if (ITEMSTORAGE_VALUE <= 3) then
     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)
     setPlayerStorageValue(cid, ITEMSTORAGE, ITEMSTORAGE_VALUE+1)
     return true
   else
     return false
   end
end
 
Test this, set local ITEMSTORAGE = 1000 to a nonused storage number.
Code:
local skill, amount = SKILL_SWORD, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 sword fighting.
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local ITEMSTORAGE = 1000
   local ITEMSTORAGE_VALUE = getPlayerStorageValue(cid, ITEMSTORAGE)
   if (ITEMSTORAGE_VALUE <= 3) then
     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)
     setPlayerStorageValue(cid, ITEMSTORAGE, ITEMSTORAGE_VALUE+1)
     return true
   else
     return false
   end
end
with this i can use it 5 times, also could you add a message when reached the 4 times? like you can't use this item more than 4 times per player? :D
 
Code:
local skill, amount = SKILL_SWORD, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 sword fighting.
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local ITEMSTORAGE = 1000
   local ITEMSTORAGE_VALUE = getPlayerStorageValue(cid, ITEMSTORAGE)
   if (ITEMSTORAGE_VALUE <= 2) then
     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)
     setPlayerStorageValue(cid, ITEMSTORAGE, ITEMSTORAGE_VALUE+1)
     return true
   else
     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You can only use this item 4 times.")
     return true
   end
end
 
Code:
local skill, amount = SKILL_SWORD, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 sword fighting.
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local ITEMSTORAGE = 1000
   local ITEMSTORAGE_VALUE = getPlayerStorageValue(cid, ITEMSTORAGE)
   if (ITEMSTORAGE_VALUE <= 2) then
     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)
     setPlayerStorageValue(cid, ITEMSTORAGE, ITEMSTORAGE_VALUE+1)
     return true
   else
     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You can only use this item 4 times.")
     return true
   end
end


Excellent! works perfectly thanks man! and if you could explain me how you set the amount of times would be great, i have many items to edit like this :)
 
Last edited:
Code:
local skill, amount = SKILL_SWORD, 3 --Edit skill name Ex: SKILL_CLUB,1 = that means amount so, it add now 1 sword fighting.
local ITEMSTORAGE = 1000
local ITEMSTORAGE_VALUE = getPlayerStorageValue(cid, ITEMSTORAGE)
local amount = 4 -- times it can be used
function onUse(cid, item, fromPosition, itemEx, toPosition)
   if (ITEMSTORAGE_VALUE <= amount-2) then
     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)
     setPlayerStorageValue(cid, ITEMSTORAGE, ITEMSTORAGE_VALUE+1)
     return true
   else
     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You can only use this item ".amount." times.")
     return true
   end
end
 
Back
Top