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

Copy item/container

Gesior.pl

Mega Noob&LOL 2012
Senator
Joined
Sep 18, 2007
Messages
2,966
Solutions
99
Reaction score
3,383
Location
Poland
GitHub
gesior
This function work only if you add in LUA (in engine - C++) new function getCharges():
PHP:
int32_t LuaScriptInterface::luaGetCharges(lua_State* L)
{
	//getCharges(uid)
	uint32_t uid = popNumber(L);
	ScriptEnviroment* env = getScriptEnv();

	Item* item = env->getItemByUID(uid);
	if(item)
	{
		lua_pushnumber(L, item->getSubType());
	}
	else
		lua_pushnumber(L, -1);

	return 1;
}
LUA script:
PHP:
function copyItem(item)
	if (isContainer(item.uid) == TRUE) then
		return copyContainer(item.uid, item.itemid)
	else
		return doCreateItemEx(item.itemid, getCharges(item.uid))
	end
end

function copyContainer(uid, itemid)
	local container = doCreateItemEx(itemid, 1)
	local iterator = getContainerSize(uid)
	while iterator >= 0  do
		doAddContainerItemEx(container, copyItem(getContainerItem(uid, iterator)))
		iterator = iterator - 1
	end
	return container
end
If you want copy container use copyItem(item),where item = container, not copyContainer!
I use it to drop copy of EQ when player die:
PHP:
function dropLoot(cid, container)
	i = CONST_SLOT_AMMO
	while i >= CONST_SLOT_HEAD do
		local slot_item = getPlayerSlotItem(cid, i)
		if (slot_item.itemid ~= 0) then
			if (isContainer(slot_item.uid) == TRUE) then
				doAddContainerItemEx(container, copyItem(slot_item))
			elseif (math.random(1, 100) <= 40) then
				doAddContainerItemEx(container, copyItem(slot_item))
			end
		end
		i = i - 1
	end
end
container = corpse from onDEath
 
i know this is a bit old but how can u use it with the function slawkens said, tried to use it but got tons of errors
 
i know this is a bit old but how can u use it with the function slawkens said, tried to use it but got tons of errors

Code:
function copyItem(item)
	if(isContainer(item.uid) == TRUE) then
		local container = doCreateItemEx(item.itemid, 1)
		local iterator = getContainerSize(item.uid)
		while(iterator >= 0) do
			doAddContainerItemEx(container, copyItem(getContainerItem(item.uid, iterator)))
			iterator = iterator - 1
		end
		return container
	end
	return doCreateItemEx(item.itemid, getThing(item.uid).type)
end
 
Back
Top