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

Lua How can I get it to NOT remove the item already got MAX slots?

Neptera

Member
Joined
Mar 3, 2018
Messages
71
Reaction score
17
As title says, how can I get this code to NOT remove the item on usage if the target item already got max slots?
Where it says "Slot limit reached" in the end of the script.

Lua:
local conf = {
maxSlotCount=1,
ignoredIds={}
}

function choose(...)
  local arg = {...}
  return arg[math.random(1,#arg)]
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if item.uid == 0 or item.itemid == 0 then return false end
  toPosition.stackpos = 255
  if isInArray(conf.ignoredIds, itemEx.itemid)
  or (getItemWeaponType(itemEx.uid) == 0 and not isArmor(itemEx.uid))
  or itemEx.itemid == 0 or itemEx.type > 1 or isItemStackable(itemEx.uid) then
  return false
  end
  if isCreature(itemEx.uid) then
  return false
  end
  local nam = Item(itemEx.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
  function getper()
    local n = 1
    for i=0,2 do
      n = n+math.random(0,2)
      if n < 8*i then
        break
      end
    end
    return n
  end

  function getSlotCount(nam)
    local c = 0
    for _ in nam:gmatch('%[(.-)%]') do
      c = c+1
    end
    return c
  end
 
  local number = math.random(0,10)
  doPlayerSendTextMessage(cid,20,number)

--  if number <= 3 then
--      doPlayerSendTextMessage(cid,20,"Your item broke in the proccess.")
--      doRemoveItem(item.uid,1)
--      doRemoveItem(itemEx.uid,1)
--      return false
--  end

  if number <= 5 then
      doPlayerSendTextMessage(cid,20,"Failed to upgrade item.")
      doRemoveItem(item.uid,1)
      return false
  end

 

  if getSlotCount(nam) < conf.maxSlotCount then
    local l = choose('hp','mp','ml','melee','shield','dist')
    local p = getper()
    doSendMagicEffect(toPosition,11)
    nam = nam..' ['..l..'.+'..p..'%]'
    doPlayerSendTextMessage(cid, 20,l..'.+'..p..'%')
    doSetItemSpecialDescription(itemEx.uid, nam)
    doRemoveItem(item.uid,1)
    return false
  else
    doPlayerSendTextMessage(cid, 20,"Slot limit reached.")
  end
  return true
end
 
move this
Lua:
if getSlotCount(nam) < conf.maxSlotCount then
above this
Lua:
local number = math.random(0,10)
 
Back
Top Bottom