• 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, block player move item

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
151
Reaction score
9
Forgotten server 1.2

how can i stop a player from moving 2 items from their sqm position? Without modific theys on items.otb, Only allow for use theys.

Item id 1: 2007
Item id 2: 3085

Position of id 2007
2034,1023,7

Position of id 3085
2034,1025,7
 
Solution
data/events/player.lua
Make sure you replace the existing Player:onMoveItem with what I posted.
Lua:
local restricted = {
    [Position(2034, 1023, 7)] = {
        2007
    },
    [Position(2034, 1025, 7)] = {
        3085
    }
}

function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    for position, restrictedIds in pairs(restricted) do
        if position == fromPosition and isInArray(restrictedIds, item:getId()) then
            return false
        end
    end

    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...
Forgotten server 1.2

how can i stop a player from moving 2 items from their sqm position? Without modific theys on items.otb, Only allow for use theys.

Item id 1: 2007
Item id 2: 3085

Position of id 2007
2034,1023,7

Position of id 3085
2034,1025,7
If the itens are in others positions, can be moved?
This will block to move all itens that have itemId in blockedToMoveItensId table, to any position:
In: data\events\scripts\player.lua on fuction Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder) put this above last return true:
Lua:
local blockedToMoveItensId = {2007, 3085} --ItemId here will be blocked to move
        if isInArray(blockedToMoveItensId, item:getId()) then 
            return false
       end
    end
Check if data\events\events.xml tag <event class="Player" method="onMoveItem" enabled="1" /> the enabled value is 1, if not, change to 1.
Just try ;)
 
Last edited:
If the itens are in others positions, can be moved?
This will block to move all itens that have itemId in blockedToMoveItensId table, to any position:
In: data\events\scripts\player.lua on fuction Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder) put this above last return true:
Lua:
local blockedToMoveItensId = {2007, 3085} --ItemId here will be blocked to move
    for i = 1, #blockedToMoveItensId do
        if item.itemId == blockedToMoveItensId[i] then
            return false
        end
    end
Check if data\events\events.xml tag <event class="Player" method="onMoveItem" enabled="1" /> the enabled value is 1, if not, change to 1.
Just try ;)
if isInArray(blockedToMoveItensId, item:getId()) then
;)
 
data/events/player.lua
Make sure you replace the existing Player:onMoveItem with what I posted.
Lua:
local restricted = {
    [Position(2034, 1023, 7)] = {
        2007
    },
    [Position(2034, 1025, 7)] = {
        3085
    }
}

function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    for position, restrictedIds in pairs(restricted) do
        if position == fromPosition and isInArray(restrictedIds, item:getId()) then
            return false
        end
    end

    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
 
Solution
Back
Top