• 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!

Solved Mystery Box doesn't dissapear

God Mythera

Veteran OT User
Joined
Aug 11, 2012
Messages
2,051
Solutions
2
Reaction score
260
Location
United States
Hello im trying to use this script, when i try to use it the item will not dissapear, can someone make it so it will? ^^

this is the script for it:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

   local rewarditems = {
      {id = 6132, chance = 5, count = 1}, -- start with the lowest chances
      {id = 2361, chance = 10, count = 1},
      {id = 2798, chance = 15, count = 15},
      {id = 2160, chance = 100, count = math.random(1, 50)}
   }

   local chance = math.random(1,100)
   for i = 1, #rewarditems, 1 do
      if(chance < rewarditems[i].chance) then
         local info = getItemInfo(rewarditems[i].id)
         if(rewarditems[i].count > 1) then
            text = rewarditems[i].count .. " " .. info.plural
         else
            text = info.article .. " " .. info.name
         end

         local item = doCreateItemEx(rewarditems[i].id, rewarditems[i].count)
         if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            text = "You have failed to open your mystery box. The item is to heavy or you have not enough space to take it."
         else
            text = "You have received " .. text .. "."
            doRemoveItem(item.uid, 1)
         end
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
         return true
      else
         chance = chance - rewarditems[i].chance
      end
   end
end
 
Try to use the meta-table function item:remove() directly.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

   local rewarditems = {
      {id = 6132, chance = 5, count = 1}, -- start with the lowest chances
      {id = 2361, chance = 10, count = 1},
      {id = 2798, chance = 15, count = 15},
      {id = 2160, chance = 100, count = math.random(1, 50)}
   }

   local chance = math.random(1,100)
   for i = 1, #rewarditems, 1 do
      if(chance < rewarditems[i].chance) then
         local info = getItemInfo(rewarditems[i].id)
         if(rewarditems[i].count > 1) then
            text = rewarditems[i].count .. " " .. info.plural
         else
            text = info.article .. " " .. info.name
         end

         local item = doCreateItemEx(rewarditems[i].id, rewarditems[i].count)
         if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            text = "You have failed to open your mystery box. The item is to heavy or you have not enough space to take it."
         else
            text = "You have received " .. text .. "."
            item:remove()
         end
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
         return true
      else
         chance = chance - rewarditems[i].chance
      end
   end
end
 
Code:
doRemoveItem(item.uid)

Try to use the meta-table function item:remove() directly.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

   local rewarditems = {
      {id = 6132, chance = 5, count = 1}, -- start with the lowest chances
      {id = 2361, chance = 10, count = 1},
      {id = 2798, chance = 15, count = 15},
      {id = 2160, chance = 100, count = math.random(1, 50)}
   }

   local chance = math.random(1,100)
   for i = 1, #rewarditems, 1 do
      if(chance < rewarditems[i].chance) then
         local info = getItemInfo(rewarditems[i].id)
         if(rewarditems[i].count > 1) then
            text = rewarditems[i].count .. " " .. info.plural
         else
            text = info.article .. " " .. info.name
         end

         local item = doCreateItemEx(rewarditems[i].id, rewarditems[i].count)
         if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            text = "You have failed to open your mystery box. The item is to heavy or you have not enough space to take it."
         else
            text = "You have received " .. text .. "."
            item:remove()
         end
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
         return true
      else
         chance = chance - rewarditems[i].chance
      end
   end
end

i tried both and wont work ;s
 
Last edited:
This should work man.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

   local rewarditems = {
      {id = 6132, chance = 5, count = 1}, -- start with the lowest chances
      {id = 2361, chance = 10, count = 1},
      {id = 2798, chance = 15, count = 15},
      {id = 2160, chance = 100, count = math.random(1, 50)}
   }

   local chance = math.random(1,100)
   for i = 1, #rewarditems, 1 do
      if(chance < rewarditems[i].chance) then
         local info = getItemInfo(rewarditems[i].id)
         if(rewarditems[i].count > 1) then
            text = rewarditems[i].count .. " " .. info.plural
         else
            text = info.article .. " " .. info.name
         end

         local rewardItem = doCreateItemEx(rewarditems[i].id, rewarditems[i].count)
         if(doPlayerAddItemEx(cid, rewardItem, false) ~= RETURNVALUE_NOERROR) then
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            text = "You have failed to open your mystery box. The item is to heavy or you have not enough space to take it."
         else
            text = "You have received " .. text .. "."
            doRemoveItem(item.uid, 1)
         end
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
         return true
      else
         chance = chance - rewarditems[i].chance
      end
   end
end
 
This should work man.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

   local rewarditems = {
      {id = 6132, chance = 5, count = 1}, -- start with the lowest chances
      {id = 2361, chance = 10, count = 1},
      {id = 2798, chance = 15, count = 15},
      {id = 2160, chance = 100, count = math.random(1, 50)}
   }

   local chance = math.random(1,100)
   for i = 1, #rewarditems, 1 do
      if(chance < rewarditems[i].chance) then
         local info = getItemInfo(rewarditems[i].id)
         if(rewarditems[i].count > 1) then
            text = rewarditems[i].count .. " " .. info.plural
         else
            text = info.article .. " " .. info.name
         end

         local rewardItem = doCreateItemEx(rewarditems[i].id, rewarditems[i].count)
         if(doPlayerAddItemEx(cid, rewardItem, false) ~= RETURNVALUE_NOERROR) then
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            text = "You have failed to open your mystery box. The item is to heavy or you have not enough space to take it."
         else
            text = "You have received " .. text .. "."
            doRemoveItem(item.uid, 1)
         end
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
         return true
      else
         chance = chance - rewarditems[i].chance
      end
   end
end
ty it worked ^^
 
Back
Top