• 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 TFS 1.X a nil value

Manigold

Active Member
Joined
Nov 2, 2017
Messages
198
Solutions
8
Reaction score
48
I'm having a problem ,(line 22 :attempt to index local 'conjureItem' <a nil value>)
With this function :

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
    if not conjureCount and conjureId ~= 0 then
        local itemType = ItemType(conjureId)
        if itemType:getId() == 0 then
            return false
        end

        local charges = itemType:getCharges()
        if charges ~= 0 then
            conjureCount = charges
        end
    end

    local conjureItem = self:getItemById(reagentId, true, -1)

    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
        item:decay()
    end

    conjureItem:remove(1)
    self:getPosition():sendMagicEffect(item:getType():isRune() and CONST_ME_MAGIC_RED or effect)
    return true
end
 
Solution
Same error in line 281.

With this code the items are conjured with the magic effect ,but another error occurs:

View attachment 67417

Send me your Discord through PM. Here it works, don't know why it is not working for you.

---

Edit: Upgrade it to handle with stackable runes.

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
  -- Ensures conjureCount
  if not conjureCount and conjureId ~= 0 then
    local itemType = ItemType(conjureId)
    if itemType:getId() == 0 then
      return false
    end

    local charges = itemType:getCharges()
    if charges ~= 0 then
      conjureCount = charges
    end
  end

  local conjureItem

  -- A reagent id is needed
  if reagentId ~= 0 then
    conjureItem =...
Same error in line 281.

With this code the items are conjured with the magic effect ,but another error occurs:

View attachment 67417

Send me your Discord through PM. Here it works, don't know why it is not working for you.

---

Edit: Upgrade it to handle with stackable runes.

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
  -- Ensures conjureCount
  if not conjureCount and conjureId ~= 0 then
    local itemType = ItemType(conjureId)
    if itemType:getId() == 0 then
      return false
    end

    local charges = itemType:getCharges()
    if charges ~= 0 then
      conjureCount = charges
    end
  end

  local conjureItem

  -- A reagent id is needed
  if reagentId ~= 0 then
    conjureItem = self:getItemById(reagentId, true, -1)

    -- Needed reagent item not found
    if not conjureItem then
      self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
      self:getPosition():sendMagicEffect(CONST_ME_POFF)
      return false
    end

    local itemParent = conjureItem:getParent()

    -- Parent not found; or parent is not player and not item; or cannot remove reagent item
    if not itemParent or (not itemParent:isPlayer() and not itemParent:isItem()) or not conjureItem:remove(1) then
      self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
      self:getPosition():sendMagicEffect(CONST_ME_POFF)
      return false
    end

    -- itemParent is player, then try add to player
    if itemParent:isPlayer() then
      conjureItem = self:addItem(conjureId, conjureCount)

    -- itemParent is container item
    else
      -- Have available space within, then try add to this container
      if itemParent:getCapacity() - itemParent:getSize() > 0 then
        conjureItem = itemParent:addItem(conjureId, conjureCount)

      -- Have no space within, then try add to player
      else
        conjureItem = self:addItem(conjureId, conjureCount)
      end
    end

  -- A reagent id is not needed
  else
    -- Add item
    conjureItem = self:addItem(conjureId, conjureCount)
  end

  -- Could not transform/add conjure item
  if not conjureItem then
    self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
    self:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
  end

  -- If has duration attribute, start decaying
  if conjureItem:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
    conjureItem:decay()
  end

  -- Send magic effect

  effect = conjureItem:getType():isRune() and CONST_ME_MAGIC_RED or effect
  if effect then
    self:getPosition():sendMagicEffect(effect)
  end

  return true
end

@Manigold
 
Last edited:
Solution
Could you explain what this text does?
I'm having a problem ,(line 22 :attempt to index local 'conjureItem' <a nil value>)
With this function :

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
    if not conjureCount and conjureId ~= 0 then
        local itemType = ItemType(conjureId)
        if itemType:getId() == 0 then
            return false
        end

        local charges = itemType:getCharges()
        if charges ~= 0 then
            conjureCount = charges
        end
    end

    local conjureItem = self:getItemById(reagentId, true, -1)

    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
        item:decay()
    end

    conjureItem:remove(1)
    self:getPosition():sendMagicEffect(item:getType():isRune() and CONST_ME_MAGIC_RED or effect)
    return true
end
 
I'm having a problem ,(line 22 :attempt to index local 'conjureItem' <a nil value>)
With this function :

Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
    if not conjureCount and conjureId ~= 0 then
        local itemType = ItemType(conjureId)
        if itemType:getId() == 0 then
            return false
        end

        local charges = itemType:getCharges()
        if charges ~= 0 then
            conjureCount = charges
        end
    end

    local conjureItem = self:getItemById(reagentId, true, -1)

    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
        item:decay()
    end

    conjureItem:remove(1)
    self:getPosition():sendMagicEffect(item:getType():isRune() and CONST_ME_MAGIC_RED or effect)
    return true
end
Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
    if not conjureCount and conjureId ~= 0 then
        local itemType = ItemType(conjureId)
        if itemType:getId() == 0 then
            return false
        end

        local charges = itemType:getCharges()
        if charges ~= 0 then
            conjureCount = charges
        end
    end

    local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
        item:decay()
    end

    conjureItem:remove(1)
    self:getPosition():sendMagicEffect(item:getType():isRune() and CONST_ME_MAGIC_RED or effect)
    return true
end
 
Lua:
function Player:conjureItem(reagentId, conjureId, conjureCount, effect)
    if not conjureCount and conjureId ~= 0 then
        local itemType = ItemType(conjureId)
        if itemType:getId() == 0 then
            return false
        end

        local charges = itemType:getCharges()
        if charges ~= 0 then
            conjureCount = charges
        end
    end

    local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    if item:hasAttribute(ITEM_ATTRIBUTE_DURATION) then
        item:decay()
    end

    conjureItem:remove(1)
    self:getPosition():sendMagicEffect(item:getType():isRune() and CONST_ME_MAGIC_RED or effect)
    return true
end
Did you post the right code?Cause the only difference is that you removed the line 15.
 
Replace

Lua:
local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

with

Lua:
if reagentId ~= 0 and not self:removeItem(reagentId, 1, -1) then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = self:addItem(conjureId, conjureCount)
    if not item then
        self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

and try again.
 
Replace

Lua:
local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

with

Lua:
if reagentId ~= 0 and not self:removeItem(reagentId, 1, -1) then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = self:addItem(conjureId, conjureCount)
    if not item then
        self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

and try again.
It does work ,but i was trying to keep the runes in the same position on the backpack.
 
Replace

Lua:
local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

with

Lua:
local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
else
conjureItem:transform(conjureId, conjureCount)
    end
 
Replace

Lua:
local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local item = conjureItem:getParent():addItem(conjureId, conjureCount)
    if not item then
        item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

with

Lua:
local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
else
conjureItem:transform(conjureId, conjureCount)
    end
Same error.
nil value.png
 
Code:
local conjureItem = self:getItemById(reagentId, true)
if reagentId ~= 0 and not conjureItem then
    self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
    self:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
else
    self:getItemById(reagentId, true):transform(conjureId, conjureCount)
end
 
Code:
local conjureItem = self:getItemById(reagentId, true)
if reagentId ~= 0 and not conjureItem then
    self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
    self:getPosition():sendMagicEffect(CONST_ME_POFF)
    return false
else
    self:getItemById(reagentId, true):transform(conjureId, conjureCount)
end
Another error now:
nil value.png
Edit:
Sorry i cut the lines from the pic the line 271 is this one
Lua:
self:getItemById(reagentId, true):transform(conjureId, conjureCount)
 
Another error now:
View attachment 67290
Edit:
Sorry i cut the lines from the pic the line 271 is this one
Lua:
self:getItemById(reagentId, true):transform(conjureId, conjureCount)
Code:
    local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    elseif reagentId ~= 0 and conjureItem then
        self:getItemById(reagentId, true, -1):transform(conjureId, conjureCount)
    else
        local item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end
 
Code:
    local conjureItem = self:getItemById(reagentId, true, -1)
    if reagentId ~= 0 and not conjureItem then
        self:sendCancelMessage(RETURNVALUE_YOUNEEDAMAGICITEMTOCASTSPELL)
        self:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    elseif reagentId ~= 0 and conjureItem then
        self:getItemById(reagentId, true, -1):transform(conjureId, conjureCount)
    else
        local item = self:addItem(conjureId, conjureCount)
        if not item then
            self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            self:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end
Error again.
 

Attachments

Back
Top