diff --git a/src/container.h b/src/container.h index bea08bbfb5..ada43a048b 100644 --- a/src/container.h +++ b/src/container.h @@ -56,6 +56,7 @@ class Container : public Item, public Cylinder size_t size() const { return itemlist.size(); } bool empty() const { return itemlist.empty(); } uint32_t capacity() const { return maxSize; } + void setCapacity(uint32_t capacity) { maxSize = capacity; } uint32_t getAmmoCount() const { return ammoCount; } ContainerIterator iterator() const; diff --git a/src/luascript.cpp b/src/luascript.cpp index 8214157dc2..871cc169f7 100644 --- a/src/luascript.cpp +++ b/src/luascript.cpp @@ -2506,6 +2506,7 @@ void LuaScriptInterface::registerFunctions() registerMethod("Container", "getSize", LuaScriptInterface::luaContainerGetSize); registerMethod("Container", "getCapacity", LuaScriptInterface::luaContainerGetCapacity); + registerMethod("Container", "setCapacity", LuaScriptInterface::luaContainerSetCapacity); registerMethod("Container", "getEmptySlots", LuaScriptInterface::luaContainerGetEmptySlots); registerMethod("Container", "getItems", LuaScriptInterface::luaContainerGetItems); registerMethod("Container", "getItemHoldingCount", LuaScriptInterface::luaContainerGetItemHoldingCount); @@ -7378,6 +7379,20 @@ int LuaScriptInterface::luaContainerGetCapacity(lua_State* L) return 1; } +int LuaScriptInterface::luaContainerSetCapacity(lua_State* L) +{ + // container:setCapacity(capacity) + Container* container = getUserdata(L, 1); + if (container) { + uint32_t capacity = getNumber(L, 2); + container->setCapacity(capacity); + pushBoolean(L, true); + } else { + lua_pushnil(L); + } + return 1; +} + int LuaScriptInterface::luaContainerGetEmptySlots(lua_State* L) { // container:getEmptySlots([recursive = false]) diff --git a/src/luascript.h b/src/luascript.h index 5b783a0727..ec0e42b456 100644 --- a/src/luascript.h +++ b/src/luascript.h @@ -738,6 +738,7 @@ class LuaScriptInterface static int luaContainerGetSize(lua_State* L); static int luaContainerGetCapacity(lua_State* L); + static int luaContainerSetCapacity(lua_State* L); static int luaContainerGetEmptySlots(lua_State* L); static int luaContainerGetItems(lua_State* L); static int luaContainerGetItemHoldingCount(lua_State* L);