• 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 Slot system mistake

_M4G0_

Well-Known Member
Joined
Feb 6, 2016
Messages
504
Solutions
16
Reaction score
98
Im using this system in my server
Action - [TFS 1.1] - Slot system
Lua:
local conf = {
maxSlotCount=3,
ignoredIds={25880, 25882, 25885, 25886, 25884, 25887, 25888, 26274, 26287, 26306, 26309, 26303, 26296, 26316, 26299, 26294, 26279, 26289, 26285, 26269, 26257, 26258, 26271, 26286, 26291, 26281, 26295, 26301}
}

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


function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey)
 
    if cid:getExhaustion(1000) <= 0 then
        cid:setExhaustion(1000, 5)
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You\'re exhausted for: '..cid:getExhaustion(1000)..' seconds.')
    return true
    end

  if item.uid == 0 or item.itemid == 0 then return false end
  toPosition.stackpos = 255
  if isInArray(conf.ignoredIds, itemEx.itemid) or
  isItemStackable(itemEx.uid) or
  itemEx.itemid == 0 or
  itemEx.type > 1 or
  not(isArmor(itemEx.uid) or isWeapon(itemEx.uid) or isShield(itemEx.uid)) then
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Este item nao pode receber encantamento.")
  end
  if isCreature(itemEx.uid) then
  return false
  end
  local nam = Item(itemEx.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
  function getper()
  local n = 5
  for i=5,10 do
  n = n+math.random(0,10)
  if n < 30*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
  if getSlotCount(nam) < conf.maxSlotCount then
  local l = choose('hp','mp','ml','melee','shield','dist')
  local p = getper()
  doSendMagicEffect(toPosition,30)
  nam = nam..' ['..l..'.+'..p..'%]'
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,l..'.+'..p..'%')
  doSetItemSpecialDescription(itemEx.uid, nam)
  doRemoveItem(item.uid,1)
  else
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"Slot limit reached.")
  end
  return true
end
Code:
local conditionMP,conditionHP,conditionML,conditionCLUB,conditionSHI,conditionDIST,conditionAMP = {},{},{},{},{},{},{}
for i=1,300 do
  conditionHP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionHP[i], CONDITION_PARAM_SUBID, 50)
  setConditionParam(conditionHP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, 100+i)

  conditionMP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionMP[i], CONDITION_PARAM_SUBID, 51)
  setConditionParam(conditionMP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, 100+i)

  conditionML[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionML[i], CONDITION_PARAM_SUBID, 52)
  setConditionParam(conditionML[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionML[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionML[i], CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, 100+i)


  conditionCLUB[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SUBID, 53)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SKILL_MELEEPERCENT, 100+i)


  conditionSHI[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SUBID, 54)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SKILL_SHIELDPERCENT, 100+i)

  conditionDIST[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SUBID, 55)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SKILL_DISTANCEPERCENT, 100+i)
end

function getSlotType(n)
    if not n then
    return false
    end
  
    if n:match('%[(.+)%]') then
        n = n:match('%[(.+)%]')
    if n == '?' then
        return 0,n
    else
        return n:match('(.-)%.([+-])(%d+)%%')
        end
    else
        return false
    end
end

local function loadSet(cid)
    local player = Player(cid)
    if not player then return false end
          local t = {}
        for slot=1,10 do
          t[slot] = ''
        local s = getPlayerSlotItem(player,slot).uid
      if s ~= 0 then
    t[slot] = Item(s):getAttribute('desc')
    end
        end
  return t
end

function chk(cid,f)
local player = Player(cid)
  if not Player(cid) then return false end
  local t = loadSet(cid)
  if not t then return false end

  for i=1,#f do
  if f[i] ~= t[i] then
  equip(player,nil,slot)
  break
  end
  end
  addEvent(chk,2000,cid,t)
end

function check_slot(aab, i)
    if i == 10 then
        if isAmmoSlot(aab) then
            return true
        end
    elseif i == 5 or i == 6 then
        if isWeapon(aab) or isShield(aab) or isBow(aab) then
            return true
        end
    else
        return true
    end
    return false
end

function equip(cid, item, slot)
    local player = Player(cid)
    local t = {}
    if item then
        local mm,sinal,qto = getSlotType(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
        t[mm] = tonumber(qto)
    end

    for i=1,10 do
        if i ~= slot then
            if getPlayerSlotItem(player,i).itemid ~= 0 then
                local aab = getPlayerSlotItem(player,i).uid
                if aab and check_slot(aab,i) then
                    local item = Item(aab)
                    if item then
                        for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
                            local mm,sinal,qto2 = getSlotType(_)
                            if mm then
                                if not t[mm] then
                                    t[mm] = 0
                                end
                                t[mm] = t[mm]+tonumber(qto2)
                                t[mm] = t[mm] > 300 and 300 or t[mm]
                            end
                        end
                    else
                        return false
                    end
                end
            end
        end
    end

    local fu = 0
    local ca = {}
    local s = ''
    for sl,n in pairs(t) do
        fu = fu+1
        s = s..''..n..'% more of '..sl..'\n'
        if sl == 'hp' then
            player:addCondition(conditionHP[tonumber(n)])
            ca[50] = 1
            doSendTutorial(player,19)
        elseif sl == 'mp' then
            player:addCondition(conditionMP[tonumber(n)])
            ca[51] = 1
            doSendTutorial(player,19)
        elseif sl == 'ml' then
            player:addCondition(conditionML[tonumber(n)])
            ca[52] = 1
        elseif sl == 'melee' then
            player:addCondition(conditionCLUB[tonumber(n)])
            ca[53] = 1
        elseif sl == 'shield' then
            player:addCondition(conditionSHI[tonumber(n)])
            ca[54] = 1
        elseif sl == 'dist' then
            player:addCondition(conditionDIST[tonumber(n)])
            ca[55] = 1
        end
    end

    if fu > 0 then
        for i=50,55 do
            if not ca[i] then
                doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
            end
        end
    else
        for i=50,55 do
            doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
        end
    end

    return true
end

function onLogin(cid)
local player = Player(cid)
  equip(player, nil, slot)
local cid = player:getId()
  addEvent(chk, 2000, cid, loadSet(cid))
  return true
end
it's work fine for a time and then
error
Code:
Blackjako has logged in.
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/slot.lua:onLogin
data/creaturescripts/scripts/custom/slot.lua:115: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/slot.lua:115: in function 'equip'
        data/creaturescripts/scripts/custom/slot.lua:172: in function <data/creaturescripts/scripts/custom/slot.lua:171>
Blackjako has logged out.
TFS 1.2 10.99
 
Last edited:
Solution
Lua:
local function loadSet(cid)
    local player = Player(cid)
    if not player then return false end
    local t = {}
    for slot=1,10 do
    t[slot] = ''
    local s = getPlayerSlotItem(player,slot).uid
        if s ~= 0 then
    local targetItem = Item(s)
        if not targetItem then
        print(targetItem, targetItem:getId(), s, slot)
            return false
        end
     t[slot] = targetItem:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) 
  -- print(ItemType( item_id_here ):getSlotPosition())
  end
  end
  return t
end
View attachment 30257

Lua:
local function loadSet(cid)
    local player = Player(cid)
    if not player then
        return false
    end

    local t = {}
    for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
        local...
Nil means the value dosn't exist, either it never did exist or we havn't added it yet - pretty much.

It says in slot.lua line 115 attempt to index a nil value, so let's look at line 115:
Lua:
for _ in Item(aab):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do

So we can see we are initiating a loop, the thing we now wanna look at is this;
Item(aab):function <- this good very well be the reason for the error, aab could be missing the next time we use the function, use this insted;
Lua:
local item = Item(aab)
if item then
     for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
          .....
     end
else
     return false
end

This way, if the item dosn't exist we don't continue with the script.
 
Nil means the value dosn't exist, either it never did exist or we havn't added it yet - pretty much.

It says in slot.lua line 115 attempt to index a nil value, so let's look at line 115:
Lua:
for _ in Item(aab):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do

So we can see we are initiating a loop, the thing we now wanna look at is this;
Item(aab):function <- this good very well be the reason for the error, aab could be missing the next time we use the function, use this insted;
Lua:
local item = Item(aab)
if item then
     for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
          .....
     end
else
     return false
end

This way, if the item dosn't exist we don't continue with the script.
is that correct?
Lua:
function equip(cid, item, slot)
local player = Player(cid)
  local t = {}
  if item then
  local mm,sinal,qto = getSlotType(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
  t[mm] = tonumber(qto)
  end
  for i=1,10 do
  if i ~= slot then
  if getPlayerSlotItem(player,i).itemid ~= 0 then
  local aab = getPlayerSlotItem(player,i).uid
  if aab and check_slot(aab,i) then
  local item = Item(aab)
  if item then
  for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
  local mm,sinal,qto2 = getSlotType(_)
  if mm then
  if not t[mm] then
  t[mm] = 0
  end
  t[mm] = t[mm]+tonumber(qto2)
  t[mm] = t[mm] > 300 and 300 or t[mm]
  end
     end
else
     return false
end
  end
  end
  end
  end
  local fu = 0
  local ca = {}
  local s = ''
  for sl,n in pairs(t) do
  fu = fu+1
  s = s..''..n..'% more of '..sl..'\n'
  if sl == 'hp' then
  player:addCondition(conditionHP[tonumber(n)])
  ca[50] = 1
  doSendTutorial(player,19)
  elseif sl == 'mp' then
  player:addCondition(conditionMP[tonumber(n)])
  ca[51] = 1
  doSendTutorial(player,19)
  elseif sl == 'ml' then
  player:addCondition(conditionML[tonumber(n)])
  ca[52] = 1
  elseif sl == 'melee' then
  player:addCondition(conditionCLUB[tonumber(n)])
  ca[53] = 1
  elseif sl == 'shield' then
  player:addCondition(conditionSHI[tonumber(n)])
  ca[54] = 1
  elseif sl == 'dist' then
  player:addCondition(conditionDIST[tonumber(n)])
  ca[55] = 1
  end
  end
  if fu > 0 then
  for i=50,55 do
  if not ca[i] then
  doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
  end
  end
  else
  for i=50,55 do
  doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
  end
  end
  return true
end
 
is that correct?
Lua:
function equip(cid, item, slot)
local player = Player(cid)
  local t = {}
  if item then
  local mm,sinal,qto = getSlotType(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
  t[mm] = tonumber(qto)
  end
  for i=1,10 do
  if i ~= slot then
  if getPlayerSlotItem(player,i).itemid ~= 0 then
  local aab = getPlayerSlotItem(player,i).uid
  if aab and check_slot(aab,i) then
  local item = Item(aab)
  if item then
  for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
  local mm,sinal,qto2 = getSlotType(_)
  if mm then
  if not t[mm] then
  t[mm] = 0
  end
  t[mm] = t[mm]+tonumber(qto2)
  t[mm] = t[mm] > 300 and 300 or t[mm]
  end
     end
else
     return false
end
  end
  end
  end
  end
  local fu = 0
  local ca = {}
  local s = ''
  for sl,n in pairs(t) do
  fu = fu+1
  s = s..''..n..'% more of '..sl..'\n'
  if sl == 'hp' then
  player:addCondition(conditionHP[tonumber(n)])
  ca[50] = 1
  doSendTutorial(player,19)
  elseif sl == 'mp' then
  player:addCondition(conditionMP[tonumber(n)])
  ca[51] = 1
  doSendTutorial(player,19)
  elseif sl == 'ml' then
  player:addCondition(conditionML[tonumber(n)])
  ca[52] = 1
  elseif sl == 'melee' then
  player:addCondition(conditionCLUB[tonumber(n)])
  ca[53] = 1
  elseif sl == 'shield' then
  player:addCondition(conditionSHI[tonumber(n)])
  ca[54] = 1
  elseif sl == 'dist' then
  player:addCondition(conditionDIST[tonumber(n)])
  ca[55] = 1
  end
  end
  if fu > 0 then
  for i=50,55 do
  if not ca[i] then
  doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
  end
  end
  else
  for i=50,55 do
  doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
  end
  end
  return true
end

Yes
Also try to tab your scripts in the future, it's alot easier to find mistakes then;
Lua:
function equip(cid, item, slot)
    local player = Player(cid)
    local t = {}
    if item then
        local mm,sinal,qto = getSlotType(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
        t[mm] = tonumber(qto)
    end

    for i=1,10 do
        if i ~= slot then
            if getPlayerSlotItem(player,i).itemid ~= 0 then
                local aab = getPlayerSlotItem(player,i).uid
                if aab and check_slot(aab,i) then
                    local item = Item(aab)
                    if item then
                        for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
                            local mm,sinal,qto2 = getSlotType(_)
                            if mm then
                                if not t[mm] then
                                    t[mm] = 0
                                end
                                t[mm] = t[mm]+tonumber(qto2)
                                t[mm] = t[mm] > 300 and 300 or t[mm]
                            end
                        end
                    else
                        return false
                    end
                end
            end
        end
    end

    local fu = 0
    local ca = {}
    local s = ''
    for sl,n in pairs(t) do
        fu = fu+1
        s = s..''..n..'% more of '..sl..'\n'
        if sl == 'hp' then
            player:addCondition(conditionHP[tonumber(n)])
            ca[50] = 1
            doSendTutorial(player,19)
        elseif sl == 'mp' then
            player:addCondition(conditionMP[tonumber(n)])
            ca[51] = 1
            doSendTutorial(player,19)
        elseif sl == 'ml' then
            player:addCondition(conditionML[tonumber(n)])
            ca[52] = 1
        elseif sl == 'melee' then
            player:addCondition(conditionCLUB[tonumber(n)])
            ca[53] = 1
        elseif sl == 'shield' then
            player:addCondition(conditionSHI[tonumber(n)])
            ca[54] = 1
        elseif sl == 'dist' then
            player:addCondition(conditionDIST[tonumber(n)])
            ca[55] = 1
        end
    end

    if fu > 0 then
        for i=50,55 do
            if not ca[i] then
                doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
            end
        end
    else
        for i=50,55 do
            doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
        end
    end

    return true
end
 
sorry for re-open
now i have this error
Code:
Devon has logged in.
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/slot.lua:onLogin
data/creaturescripts/scripts/custom/slot.lua:67: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/slot.lua:67: in function 'loadSet'
        data/creaturescripts/scripts/custom/slot.lua:185: in function
Devon has logged out.
function 'loadSet'
Lua:
local function loadSet(cid)
    local player = Player(cid)
    if not player then return false end
          local t = {}
        for slot=1,10 do
          t[slot] = ''
        local s = getPlayerSlotItem(player,slot).uid
      if s ~= 0 then
    t[slot] = Item(s):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)<< Line 67
  -- print(ItemType( item_id_here ):getSlotPosition())
    end
        end
  return t
end

Lua:
function onLogin(cid)
local player = Player(cid)
  equip(player, nil, slot)
local cid = player:getId()
  addEvent(chk, 2000, cid, loadSet(cid))<< Line 185
  return true
end
 
Last edited:
Try this:
Lua:
local function loadSet(cid)
    local player = Player(cid)
    if not player then
        return false
    end

    local t = {}
    for slot=1,10 do
        local s = getPlayerSlotItem(player,slot).uid
        if s ~= 0 then
            local item = Item(s)
            if item then
                t[slot] = item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
            else
                t[slot] = ''
            end
        else
            t[slot] = ''
        end
  return t
end
Also my advice is to use consts (SLOT_FIRST, SLOT_LAST) instead of numbers in a loop, this way you ensure that any slot that is added won't break your script or force you to modify it.
 
Try this:
Lua:
local function loadSet(cid)
    local player = Player(cid)
    if not player then
        return false
    end

    local t = {}
    for slot=1,10 do
        local s = getPlayerSlotItem(player,slot).uid
        if s ~= 0 then
            local item = Item(s)
            if item then
                t[slot] = item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
            else
                t[slot] = ''
            end
        else
            t[slot] = ''
        end
  return t
end
Also my advice is to use consts (SLOT_FIRST, SLOT_LAST) instead of numbers in a loop, this way you ensure that any slot that is added won't break your script or force you to modify it.
need reload to add or remove attributes from items

BUMP

BUMP

BUMP

F5
 
Last edited by a moderator:
Lua:
local function loadSet(cid)
    local player = Player(cid)
    if not player then return false end
          local t = {}
        for slot=1,10 do
          t[slot] = ''
        local s = getPlayerSlotItem(player,slot).uid
      if s ~= 0 then
    t[slot] = Item(s):getAttribute('desc')
    end
        end
  return t
end
 
Lua:
local function loadSet(cid)
    local player = Player(cid)
    if not player then return false end
          local t = {}
        for slot=1,10 do
          t[slot] = ''
        local s = getPlayerSlotItem(player,slot).uid
      if s ~= 0 then
    t[slot] = Item(s):getAttribute('desc')
    end
        end
  return t
end
Code:
Kina Mumu has logged in.

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/slot.lua:onLogin
data/creaturescripts/scripts/custom/slot.lua:67: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/slot.lua:67: in function 'loadSet'
        data/creaturescripts/scripts/custom/slot.lua:184: in function <data/creaturescripts/scripts/custom/slot.lua:180>
Kina Mumu has logged out.
Esse Mesmo has logged in.

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/slot.lua:onLogin
data/creaturescripts/scripts/custom/slot.lua:67: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/slot.lua:67: in function 'loadSet'
        data/creaturescripts/scripts/custom/slot.lua:184: in function <data/creaturescripts/scripts/custom/slot.lua:180>
Esse Mesmo has logged out.

Bump
 
Last edited:
Code:
Kina Mumu has logged in.

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/slot.lua:onLogin
data/creaturescripts/scripts/custom/slot.lua:68: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/slot.lua:68: in function 'loadSet'
        data/creaturescripts/scripts/custom/slot.lua:185: in function <data/creaturescripts/scripts/custom/slot.lua:180>
Kina Mumu has logged out.
Esse Mesmo has logged in.

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/slot.lua:onLogin
data/creaturescripts/scripts/custom/slot.lua:68: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/slot.lua:68: in function 'loadSet'
        data/creaturescripts/scripts/custom/slot.lua:185: in function <data/creaturescripts/scripts/custom/slot.lua:180>
Esse Mesmo has logged out.

Bump

Please if you have edited the script re-post it with the new error, you could have pasted it in a diffrent way and that makes it harder to find the errors.
 
Please if you have edited the script re-post it with the new error, you could have pasted it in a diffrent way and that makes it harder to find the errors.
on first posto
real lines 67
Lua:
t[slot] = Item(s):getAttribute('desc')
and
184
Lua:
  addEvent(chk, 2000, cid, loadSet(cid))
 
on first posto
real lines 67
Lua:
t[slot] = Item(s):getAttribute('desc')
and
184
Lua:
  addEvent(chk, 2000, cid, loadSet(cid))

But the error says line 68 and 185, please in the future (aswell as in your next post) include the changes you did, this will save us all a bunch of time.
If it's line 68 you posted then add this;
Lua:
print(t)
print(slot)
print(s)

Then post a picture of the console aswell as script again, then we know what is giving us the nil error.
 
But the error says line 68 and 185, please in the future (aswell as in your next post) include the changes you did, this will save us all a bunch of time.
If it's line 68 you posted then add this;
Lua:
print(t)
print(slot)
print(s)

Then post a picture of the console aswell as script again, then we know what is giving us the nil error.
Sem título.png
Lua:
local conditionMP,conditionHP,conditionML,conditionCLUB,conditionSHI,conditionDIST,conditionAMP = {},{},{},{},{},{},{}
for i=1,300 do
  conditionHP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionHP[i], CONDITION_PARAM_SUBID, 50)
  setConditionParam(conditionHP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, 100+i)

  conditionMP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionMP[i], CONDITION_PARAM_SUBID, 51)
  setConditionParam(conditionMP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, 100+i)

  conditionML[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionML[i], CONDITION_PARAM_SUBID, 52)
  setConditionParam(conditionML[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionML[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionML[i], CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, 100+i)


  conditionCLUB[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SUBID, 53)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SKILL_MELEEPERCENT, 100+i)


  conditionSHI[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SUBID, 54)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SKILL_SHIELDPERCENT, 100+i)

  conditionDIST[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SUBID, 55)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SKILL_DISTANCEPERCENT, 100+i)
end

function getSlotType(n)
    if not n then
    return false
    end
   
    if n:match('%[(.+)%]') then
        n = n:match('%[(.+)%]')
     if n == '?' then
        return 0,n
    else
        return n:match('(.-)%.([+-])(%d+)%%')
        end
    else
        return false
    end
end

local function loadSet(cid)
    local player = Player(cid)
    if not player then return false end
          local t = {}
        for slot=1,10 do
          t[slot] = ''
        local s = getPlayerSlotItem(player,slot).uid
      if s ~= 0 then
    t[slot] = Item(s):getAttribute('desc')
    print(t)
    print(slot)
    print(s)
    end
        end
  return t
end

function chk(cid,f)
local player = Player(cid)
  if not Player(cid) then return false end
  local t = loadSet(cid)
  if not t then return false end

  for i=1,#f do
  if f[i] ~= t[i] then
  equip(player,nil,slot)
  break
  end
  end
  addEvent(chk,2000,cid,t)
end

function check_slot(aab, i)
    if i == 10 then
        if isAmmoSlot(aab) then
            return true
        end
    elseif i == 5 or i == 6 then
        if isWeapon(aab) or isShield(aab) or isBow(aab) then
            return true
        end
    else
        return true
    end
    return false
end

function equip(cid, item, slot)
    local player = Player(cid)
    local t = {}
    if item then
        local mm,sinal,qto = getSlotType(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
        t[mm] = tonumber(qto)
    end
    for i=1,10 do
        if i ~= slot then
            if getPlayerSlotItem(player,i).itemid ~= 0 then
                local aab = getPlayerSlotItem(player,i).uid
                if aab and check_slot(aab,i) then
                    local item = Item(aab)
                    if item then
                        for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
                            local mm,sinal,qto2 = getSlotType(_)
                            if mm then
                                if not t[mm] then
                                    t[mm] = 0
                                end
                                t[mm] = t[mm]+tonumber(qto2)
                                t[mm] = t[mm] > 300 and 300 or t[mm]
                            end
                        end
                    else
                        return false
                    end
                end
            end
        end
    end
    local fu = 0
    local ca = {}
    local s = ''
    for sl,n in pairs(t) do
        fu = fu+1
        s = s..''..n..'% more of '..sl..'\n'
        if sl == 'hp' then
            player:addCondition(conditionHP[tonumber(n)])
            ca[50] = 1
            doSendTutorial(player,19)
        elseif sl == 'mp' then
            player:addCondition(conditionMP[tonumber(n)])
            ca[51] = 1
            doSendTutorial(player,19)
        elseif sl == 'ml' then
            player:addCondition(conditionML[tonumber(n)])
            ca[52] = 1
        elseif sl == 'melee' then
            player:addCondition(conditionCLUB[tonumber(n)])
            ca[53] = 1
        elseif sl == 'shield' then
            player:addCondition(conditionSHI[tonumber(n)])
            ca[54] = 1
        elseif sl == 'dist' then
            player:addCondition(conditionDIST[tonumber(n)])
            ca[55] = 1
        end
    end
    if fu > 0 then
        for i=50,55 do
            if not ca[i] then
                doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
            end
        end
    else
        for i=50,55 do
            doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
        end
    end
    return true
end

function onLogin(cid)
local player = Player(cid)
  equip(player, nil, slot)
local cid = player:getId()
  addEvent(chk, 2000, cid, loadSet(cid))
  return true
end
 
Last edited:
View attachment 30190
Lua:
local conditionMP,conditionHP,conditionML,conditionCLUB,conditionSHI,conditionDIST,conditionAMP = {},{},{},{},{},{},{}
for i=1,300 do
  conditionHP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionHP[i], CONDITION_PARAM_SUBID, 50)
  setConditionParam(conditionHP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, 100+i)

  conditionMP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionMP[i], CONDITION_PARAM_SUBID, 51)
  setConditionParam(conditionMP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, 100+i)

  conditionML[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionML[i], CONDITION_PARAM_SUBID, 52)
  setConditionParam(conditionML[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionML[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionML[i], CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, 100+i)


  conditionCLUB[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SUBID, 53)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SKILL_MELEEPERCENT, 100+i)


  conditionSHI[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SUBID, 54)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SKILL_SHIELDPERCENT, 100+i)

  conditionDIST[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SUBID, 55)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SKILL_DISTANCEPERCENT, 100+i)
end

function getSlotType(n)
    if not n then
    return false
    end
  
    if n:match('%[(.+)%]') then
        n = n:match('%[(.+)%]')
     if n == '?' then
        return 0,n
    else
        return n:match('(.-)%.([+-])(%d+)%%')
        end
    else
        return false
    end
end

local function loadSet(cid)
    local player = Player(cid)
    if not player then return false end
          local t = {}
        for slot=1,10 do
          t[slot] = ''
        local s = getPlayerSlotItem(player,slot).uid
      if s ~= 0 then
    t[slot] = Item(s):getAttribute('desc')
    print(t)
    print(slot)
    print(s)
    end
        end
  return t
end

function chk(cid,f)
local player = Player(cid)
  if not Player(cid) then return false end
  local t = loadSet(cid)
  if not t then return false end

  for i=1,#f do
  if f[i] ~= t[i] then
  equip(player,nil,slot)
  break
  end
  end
  addEvent(chk,2000,cid,t)
end

function check_slot(aab, i)
    if i == 10 then
        if isAmmoSlot(aab) then
            return true
        end
    elseif i == 5 or i == 6 then
        if isWeapon(aab) or isShield(aab) or isBow(aab) then
            return true
        end
    else
        return true
    end
    return false
end

function equip(cid, item, slot)
    local player = Player(cid)
    local t = {}
    if item then
        local mm,sinal,qto = getSlotType(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
        t[mm] = tonumber(qto)
    end
    for i=1,10 do
        if i ~= slot then
            if getPlayerSlotItem(player,i).itemid ~= 0 then
                local aab = getPlayerSlotItem(player,i).uid
                if aab and check_slot(aab,i) then
                    local item = Item(aab)
                    if item then
                        for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
                            local mm,sinal,qto2 = getSlotType(_)
                            if mm then
                                if not t[mm] then
                                    t[mm] = 0
                                end
                                t[mm] = t[mm]+tonumber(qto2)
                                t[mm] = t[mm] > 300 and 300 or t[mm]
                            end
                        end
                    else
                        return false
                    end
                end
            end
        end
    end
    local fu = 0
    local ca = {}
    local s = ''
    for sl,n in pairs(t) do
        fu = fu+1
        s = s..''..n..'% more of '..sl..'\n'
        if sl == 'hp' then
            player:addCondition(conditionHP[tonumber(n)])
            ca[50] = 1
            doSendTutorial(player,19)
        elseif sl == 'mp' then
            player:addCondition(conditionMP[tonumber(n)])
            ca[51] = 1
            doSendTutorial(player,19)
        elseif sl == 'ml' then
            player:addCondition(conditionML[tonumber(n)])
            ca[52] = 1
        elseif sl == 'melee' then
            player:addCondition(conditionCLUB[tonumber(n)])
            ca[53] = 1
        elseif sl == 'shield' then
            player:addCondition(conditionSHI[tonumber(n)])
            ca[54] = 1
        elseif sl == 'dist' then
            player:addCondition(conditionDIST[tonumber(n)])
            ca[55] = 1
        end
    end
    if fu > 0 then
        for i=50,55 do
            if not ca[i] then
                doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
            end
        end
    else
        for i=50,55 do
            doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
        end
    end
    return true
end

function onLogin(cid)
local player = Player(cid)
  equip(player, nil, slot)
local cid = player:getId()
  addEvent(chk, 2000, cid, loadSet(cid))
  return true
end

Did you get any error with that? All the values are "what they should be"
 
it's work fine for a time and then this error

Okay then swap the code around like this;
Lua:
    print(t)
    print(slot)
    print(s)
    t[slot] = Item(s):getAttribute('desc')

Then when you get the error post what line it's on.
If it's ex s thats the problem you will see 2 prints then the error comes, if you don't see anything it's t etc
 
Okay then swap the code around like this;
Lua:
    print(t)
    print(slot)
    print(s)
    t[slot] = Item(s):getAttribute('desc')

Then when you get the error post what line it's on.
If it's ex s thats the problem you will see 2 prints then the error comes, if you don't see anything it's t etc
Ok thanks for help

Okay then swap the code around like this;
Lua:
    print(t)
    print(slot)
    print(s)
    t[slot] = Item(s):getAttribute('desc')

Then when you get the error post what line it's on.
If it's ex s thats the problem you will see 2 prints then the error comes, if you don't see anything it's t etc
Lua:
local conditionMP,conditionHP,conditionML,conditionCLUB,conditionSHI,conditionDIST,conditionAMP = {},{},{},{},{},{},{}
for i=1,300 do
  conditionHP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionHP[i], CONDITION_PARAM_SUBID, 50)
  setConditionParam(conditionHP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, 100+i)

  conditionMP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionMP[i], CONDITION_PARAM_SUBID, 51)
  setConditionParam(conditionMP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, 100+i)

  conditionML[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionML[i], CONDITION_PARAM_SUBID, 52)
  setConditionParam(conditionML[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionML[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionML[i], CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, 100+i)


  conditionCLUB[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SUBID, 53)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SKILL_MELEEPERCENT, 100+i)


  conditionSHI[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SUBID, 54)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SKILL_SHIELDPERCENT, 100+i)

  conditionDIST[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SUBID, 55)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SKILL_DISTANCEPERCENT, 100+i)
end

function getSlotType(n)
    if not n then
    return false
    end
   
    if n:match('%[(.+)%]') then
        n = n:match('%[(.+)%]')
     if n == '?' then
        return 0,n
    else
        return n:match('(.-)%.([+-])(%d+)%%')
        end
    else
        return false
    end
end

local function loadSet(cid)
    local player = Player(cid)
    if not player then return false end
    local t = {}
    for slot=1,10 do
    t[slot] = ''
    local s = getPlayerSlotItem(player,slot).uid
        if s ~= 0 then
    print(t)
    print(slot)
    print(s)
  t[slot] = Item(s):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
  -- print(ItemType( item_id_here ):getSlotPosition())
  end
  end
  return t
end

function chk(cid,f)
local player = Player(cid)
  if not Player(cid) then return false end
  local t = loadSet(cid)
  if not t then return false end

  for i=1,#f do
  if f[i] ~= t[i] then
  equip(player,nil,slot)
  break
  end
  end
  addEvent(chk,2000,cid,t)
end

function check_slot(aab, i)
    if i == 10 then
        if isAmmoSlot(aab) then
            return true
        end
    elseif i == 5 or i == 6 then
        if isWeapon(aab) or isShield(aab) or isBow(aab) then
            return true
        end
    else
        return true
    end
    return false
end

function equip(cid, item, slot)
    local player = Player(cid)
    local t = {}
    if item then
        local mm,sinal,qto = getSlotType(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
        t[mm] = tonumber(qto)
    end
    for i=1,10 do
        if i ~= slot then
            if getPlayerSlotItem(player,i).itemid ~= 0 then
                local aab = getPlayerSlotItem(player,i).uid
                if aab and check_slot(aab,i) then
                    local item = Item(aab)
                    if item then
                        for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
                            local mm,sinal,qto2 = getSlotType(_)
                            if mm then
                                if not t[mm] then
                                    t[mm] = 0
                                end
                                t[mm] = t[mm]+tonumber(qto2)
                                t[mm] = t[mm] > 300 and 300 or t[mm]
                            end
                        end
                    else
                        return false
                    end
                end
            end
        end
    end
    local fu = 0
    local ca = {}
    local s = ''
    for sl,n in pairs(t) do
        fu = fu+1
        s = s..''..n..'% more of '..sl..'\n'
        if sl == 'hp' then
            player:addCondition(conditionHP[tonumber(n)])
            ca[50] = 1
            doSendTutorial(player,19)
        elseif sl == 'mp' then
            player:addCondition(conditionMP[tonumber(n)])
            ca[51] = 1
            doSendTutorial(player,19)
        elseif sl == 'ml' then
            player:addCondition(conditionML[tonumber(n)])
            ca[52] = 1
        elseif sl == 'melee' then
            player:addCondition(conditionCLUB[tonumber(n)])
            ca[53] = 1
        elseif sl == 'shield' then
            player:addCondition(conditionSHI[tonumber(n)])
            ca[54] = 1
        elseif sl == 'dist' then
            player:addCondition(conditionDIST[tonumber(n)])
            ca[55] = 1
        end
    end
    if fu > 0 then
        for i=50,55 do
            if not ca[i] then
                doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
            end
        end
    else
        for i=50,55 do
            doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
        end
    end
    return true
end

function onLogin(cid)
local player = Player(cid)
  equip(player, nil, slot)
local cid = player:getId()
  addEvent(chk,2000,cid,loadSet(cid))
  return true
end
Changes
t[slot] = Item(s):getAttribute('desc') for
t[slot] = Item(s):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
why dont load attributes from items
error:
Sem título.png
 
Last edited by a moderator:
Lua:
local conditionMP,conditionHP,conditionML,conditionCLUB,conditionSHI,conditionDIST,conditionAMP = {},{},{},{},{},{},{}
for i=1,300 do
  conditionHP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionHP[i], CONDITION_PARAM_SUBID, 50)
  setConditionParam(conditionHP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionHP[i], CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, 100+i)

  conditionMP[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionMP[i], CONDITION_PARAM_SUBID, 51)
  setConditionParam(conditionMP[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionMP[i], CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, 100+i)

  conditionML[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionML[i], CONDITION_PARAM_SUBID, 52)
  setConditionParam(conditionML[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionML[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionML[i], CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, 100+i)


  conditionCLUB[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SUBID, 53)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionCLUB[i], CONDITION_PARAM_SKILL_MELEEPERCENT, 100+i)


  conditionSHI[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SUBID, 54)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionSHI[i], CONDITION_PARAM_SKILL_SHIELDPERCENT, 100+i)

  conditionDIST[i] = createConditionObject(CONDITION_ATTRIBUTES)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SUBID, 55)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_BUFF_SPELL, 1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_TICKS, -1)
  setConditionParam(conditionDIST[i], CONDITION_PARAM_SKILL_DISTANCEPERCENT, 100+i)
end

function getSlotType(n)
    if not n then
    return false
    end
  
    if n:match('%[(.+)%]') then
        n = n:match('%[(.+)%]')
     if n == '?' then
        return 0,n
    else
        return n:match('(.-)%.([+-])(%d+)%%')
        end
    else
        return false
    end
end

local function loadSet(cid)
    local player = Player(cid)
    if not player then return false end
    local t = {}
    for slot=1,10 do
    t[slot] = ''
    local s = getPlayerSlotItem(player,slot).uid
        if s ~= 0 then
    print(t)
    print(slot)
    print(s)
  t[slot] = Item(s):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
  -- print(ItemType( item_id_here ):getSlotPosition())
  end
  end
  return t
end

function chk(cid,f)
local player = Player(cid)
  if not Player(cid) then return false end
  local t = loadSet(cid)
  if not t then return false end

  for i=1,#f do
  if f[i] ~= t[i] then
  equip(player,nil,slot)
  break
  end
  end
  addEvent(chk,2000,cid,t)
end

function check_slot(aab, i)
    if i == 10 then
        if isAmmoSlot(aab) then
            return true
        end
    elseif i == 5 or i == 6 then
        if isWeapon(aab) or isShield(aab) or isBow(aab) then
            return true
        end
    else
        return true
    end
    return false
end

function equip(cid, item, slot)
    local player = Player(cid)
    local t = {}
    if item then
        local mm,sinal,qto = getSlotType(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
        t[mm] = tonumber(qto)
    end
    for i=1,10 do
        if i ~= slot then
            if getPlayerSlotItem(player,i).itemid ~= 0 then
                local aab = getPlayerSlotItem(player,i).uid
                if aab and check_slot(aab,i) then
                    local item = Item(aab)
                    if item then
                        for _ in item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
                            local mm,sinal,qto2 = getSlotType(_)
                            if mm then
                                if not t[mm] then
                                    t[mm] = 0
                                end
                                t[mm] = t[mm]+tonumber(qto2)
                                t[mm] = t[mm] > 300 and 300 or t[mm]
                            end
                        end
                    else
                        return false
                    end
                end
            end
        end
    end
    local fu = 0
    local ca = {}
    local s = ''
    for sl,n in pairs(t) do
        fu = fu+1
        s = s..''..n..'% more of '..sl..'\n'
        if sl == 'hp' then
            player:addCondition(conditionHP[tonumber(n)])
            ca[50] = 1
            doSendTutorial(player,19)
        elseif sl == 'mp' then
            player:addCondition(conditionMP[tonumber(n)])
            ca[51] = 1
            doSendTutorial(player,19)
        elseif sl == 'ml' then
            player:addCondition(conditionML[tonumber(n)])
            ca[52] = 1
        elseif sl == 'melee' then
            player:addCondition(conditionCLUB[tonumber(n)])
            ca[53] = 1
        elseif sl == 'shield' then
            player:addCondition(conditionSHI[tonumber(n)])
            ca[54] = 1
        elseif sl == 'dist' then
            player:addCondition(conditionDIST[tonumber(n)])
            ca[55] = 1
        end
    end
    if fu > 0 then
        for i=50,55 do
            if not ca[i] then
                doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
            end
        end
    else
        for i=50,55 do
            doRemoveCondition(player:getId(),CONDITION_ATTRIBUTES,i)
        end
    end
    return true
end

function onLogin(cid)
local player = Player(cid)
  equip(player, nil, slot)
local cid = player:getId()
  addEvent(chk,2000,cid,loadSet(cid))
  return true
end
Changes
t[slot] = Item(s):getAttribute('desc') for
t[slot] = Item(s):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
why dont load attributes from items
error:
View attachment 30208

Do you have a valid item in that slot position?
Try this;
Lua:
local targetItem = Item(s)
if not targetItem then
     return false
end

t[slot] = targetItem:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
 
Do you have a valid item in that slot position?
Try this;
Lua:
local targetItem = Item(s)
if not targetItem then
     return false
end

t[slot] = targetItem:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
slot 1 is helmet, i have edited items in my otb
in test

Do you have a valid item in that slot position?
Try this;
Lua:
local targetItem = Item(s)
if not targetItem then
     return false
end

t[slot] = targetItem:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
Thanks for help @WibbenZ it's working, but everytime don't load attributes,
Not erros on login
How I can use for print item id?
 
Last edited by a moderator:
slot 1 is helmet, i have edited items in my otb
in test


Thanks for help @WibbenZ it's working, but everytime don't load attributes,
Not erros on login
How I can use for print item id?

Humm thats strange, try to print it out and see what it could be.
Lua:
print(targetItem, targetItem:getId(), s, slot)
 
Back
Top