• 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 Player.onMoveItem - index nil value

Danger II

tibiara.com
Joined
Nov 21, 2012
Messages
1,773
Solutions
13
Reaction score
707
Location
Germany
The teleporter part works well.
I can push items into a teleporter and they get moved to the target position but it seems like thats the only part that works now.
I cannot pick up items, but push them on ground..

Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
   local newPos, effect

   if Tile(toPosition):getItemById(1387) then
     for k, v in pairs(teleportersConfig) do
       if (toPosition == v.teleporterPos) then
         teleporterPos = v.teleporterPos
         newPos = v.teleportTo
         effect = v.effect
       end
     end
     teleporterPos:sendMagicEffect(effect)
     item:moveTo(newPos)
     newPos:sendMagicEffect(effect)
   end
 
   return true
end
 
function Player:eek:nMoveItem(...)
if toPosition.x == CONTAINER_POSITION then
return true
end
....
....

On cellphone. And you should check if the tile exists

local tile = Tile(toPosition)
if not tile then return true end
 
Code:
if toPosition.x == CONTAINER_POSITION then
return true
end

Works, but im wondering why does it works like it should be with:
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
     return true
end
But with my code I need:
Code:
if toPosition.x == CONTAINER_POSITION then
return true
end
Thats suppose to be?
 
Wth are you talking about?
Well look if I enable the moveItem in events and use this code:
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
return true
end

It works well, I mean not the teleporter part but picking up items, push them around, etc.
But after I wrote that small teleporter part, I need the CONTAINER_POSITION part, thats normal?
 
Well look if I enable the moveItem in events and use this code:
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
return true
end

It works well, I mean not the teleporter part but picking up items, push them around, etc.
But after I wrote that small part, I need the CONTAINER_POSITION part, thats normal?

The error is in Tile(toPosition) because not every position is a valid tile.
If the x position of the toPosition is == CONTAINER_POSITION, the player is moving to a container. And the Tile constructor will return nil.
 
The error is in Tile(toPosition) because not every position is a valid tile.
If the x position of the toPosition is == CONTAINER_POSITION, the player is moving to a container. And the Tile constructor will return nil.
Oh great, thanks mate. Didnt know that, good to know in future :)
 
Back
Top