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

TFS 1.2 Player:onMoveItem

lazarus321

Member
Joined
May 8, 2017
Messages
222
Reaction score
23
Anyone know why is this error happening? I moved the bow from the right hand to the left and it appeared this error, the opposite does not happen error.

1559672079272.png

C++:
Lua Script Error: [Event Interface]
data/events/scripts/party.lua:Player@onMoveItem
data/events/scripts/player.lua:119: attempt to call method 'getSize' (a nil value)
stack traceback:
        [C]: in function 'getSize'
        data/events/scripts/player.lua:119: in function <data/events/scripts/player.lua:100>

function in player.lua,

C++:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)

    if toPosition.x ~= CONTAINER_POSITION then
        return true
    end

    if item:getTopParent() == self and bit.band(toPosition.y, 0x40) == 0 then
        local itemType, moveItem = ItemType(item:getId())
        if bit.band(itemType:getSlotPosition(), SLOTP_TWO_HAND) ~= 0 and toPosition.y == CONST_SLOT_LEFT then
            moveItem = self:getSlotItem(CONST_SLOT_RIGHT)
        elseif itemType:getWeaponType() == WEAPON_SHIELD and toPosition.y == CONST_SLOT_RIGHT then
            moveItem = self:getSlotItem(CONST_SLOT_LEFT)
            if moveItem and bit.band(ItemType(moveItem:getId()):getSlotPosition(), SLOTP_TWO_HAND) == 0 then
                return true
            end
        end

        if moveItem then
            local parent = item:getParent()
            if parent:getSize() == parent:getCapacity() then
                self:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CONTAINERNOTENOUGHROOM))
                return false
            else
                return moveItem:moveTo(parent)
            end
        end
    end

    return true
end
 
Anyone know why is this error happening? I moved the bow from the right hand to the left and it appeared this error, the opposite does not happen error.

View attachment 36756

C++:
Lua Script Error: [Event Interface]
data/events/scripts/party.lua:Player@onMoveItem
data/events/scripts/player.lua:119: attempt to call method 'getSize' (a nil value)
stack traceback:
        [C]: in function 'getSize'
        data/events/scripts/player.lua:119: in function <data/events/scripts/player.lua:100>

function in player.lua,

C++:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)

    if toPosition.x ~= CONTAINER_POSITION then
        return true
    end

    if item:getTopParent() == self and bit.band(toPosition.y, 0x40) == 0 then
        local itemType, moveItem = ItemType(item:getId())
        if bit.band(itemType:getSlotPosition(), SLOTP_TWO_HAND) ~= 0 and toPosition.y == CONST_SLOT_LEFT then
            moveItem = self:getSlotItem(CONST_SLOT_RIGHT)
        elseif itemType:getWeaponType() == WEAPON_SHIELD and toPosition.y == CONST_SLOT_RIGHT then
            moveItem = self:getSlotItem(CONST_SLOT_LEFT)
            if moveItem and bit.band(ItemType(moveItem:getId()):getSlotPosition(), SLOTP_TWO_HAND) == 0 then
                return true
            end
        end

        if moveItem then
            local parent = item:getParent()
            if parent:getSize() == parent:getCapacity() then
                self:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CONTAINERNOTENOUGHROOM))
                return false
            else
                return moveItem:moveTo(parent)
            end
        end
    end

    return true
end
You're trying to get the size of a non-container item.
Confirm that the item is a container before attempting to get the size of it.
LUA:
if parent:isContainer() and parent:getSize() == parent:getCapacity() then
 
I replace for this code

C++:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if toPosition.x ~= CONTAINER_POSITION then
        return true
    end

    if item:getTopParent() == self and bit.band(toPosition.y, 0x40) == 0 then
        local itemType, moveItem = ItemType(item:getId())
        if bit.band(itemType:getSlotPosition(), SLOTP_TWO_HAND) ~= 0 and toPosition.y == CONST_SLOT_LEFT then
            moveItem = self:getSlotItem(CONST_SLOT_RIGHT)
        elseif itemType:getWeaponType() == WEAPON_SHIELD and toPosition.y == CONST_SLOT_RIGHT then
            moveItem = self:getSlotItem(CONST_SLOT_LEFT)
            if moveItem and bit.band(ItemType(moveItem:getId()):getSlotPosition(), SLOTP_TWO_HAND) == 0 then
                return true
            end
        end

        if moveItem then
            local parent = item:getParent()
            if parent:isContainer() and parent:getSize() == parent:getCapacity() then
                self:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_CONTAINERNOTENOUGHROOM))
                return false
            else
                return moveItem:moveTo(parent)
            end
        end
    end

    return true
end

and now get this error, where i can check this function?

C++:
Lua Script Error: [Event Interface]
data/events/scripts/party.lua:Player@onMoveItem
data/events/scripts/player.lua:118: attempt to call method 'isContainer' (a nil value)
stack traceback:
        [C]: in function 'isContainer'
        data/events/scripts/player.lua:118: in function <data/events/scripts/player.lua:100>

This error happens only for two-handed weapons, strange even replacing everything above.
 
Last edited:
Back
Top