• 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 [1.2] relocate container content

emil92b

Intermediate OT User
Joined
Aug 21, 2013
Messages
335
Solutions
13
Reaction score
135
Location
Sweden
how can i get all the items from inside a box container when i click on it and then move all of those items to the clickers current position?
 
Solution
Try this
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local size = item:isContainer() and Container(item.uid):getSize() or 0
    for i = 0, size-1 do
        Container(item.uid):getItem(0):moveTo(player:getPosition())
    end
end
Try this
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local size = item:isContainer() and Container(item.uid):getSize() or 0
    for i = 0, size-1 do
        Container(item.uid):getItem(0):moveTo(player:getPosition())
    end
end
 
Last edited:
Solution
Try this
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local size = item:isContainer() and Container(item.uid):getSize() or 0
    if size > 0 then
        local container = Container(item.uid)
        for i = 0, container:getSize() - 1 do
            container:getItem(i):moveTo(player:getPosition())
        end
    end
end

Code:
int LuaScriptInterface::luaItemTypeIsContainer(lua_State* L)
{
    // itemType:isContainer()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (itemType) {
        pushBoolean(L, itemType->isContainer());
    } else {
        lua_pushnil(L);
    }
    return 1;
}


Lua:
function Container.isContainer(self)
return true
end

so...
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemType = ItemType(item.itemid)
    local container = itemType:isContainer() and Container(item.uid) or nil
    if container then
        for i = 0, container:getSize() - 1 do
            container:getItem(i):moveTo(player:getPosition())
        end
    end
    return true
end
 
Back
Top