• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua doPlayerAddDepotItems+doItemSetAttribute [Help]

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,857
Reaction score
96
Location
Brazil
Its sending parcel ok but doItemSetAttribute shows in console "item not found".
Can someone help?

LUA:
local function doPlayerAddDepotItems(cid, items, town)
	if (not isPlayer(cid)) then
		error("Player not found")
	end
	local town = town or getPlayerTown(cid)
 
	local parcel = doCreateItemEx(ITEM_PARCEL)
	for item, count in pairs(items) do
		if (type(item) == "number") then
			local attritemid = doPlayerGiveItemContainer(cid, 2596, item, count, subType)
			doItemSetAttribute(attritemid, "description", "This item belongs to ".. getPlayerName(cid) ..".")
			doItemSetAttribute(attritemid, "aid", getPlayerGUID(cid)+10000)
		elseif (type(item) == "string") then
			doPlayerGiveItemContainer(cid, 2596,getItemIdByName(item), count, subType)
		else
			error("Undefinied type of item name")
		end
	end
 
	return doPlayerSendMailByName(getCreatureName(cid), parcel, town) 
end
 
LUA:
local function doPlayerAddDepotItems(cid, items, town)
	if (not isPlayer(cid)) then
		error("Player not found")
	end
	local town = town or getPlayerTown(cid)
 
	local parcel = doCreateItemEx(ITEM_PARCEL)
	for item, count in pairs(items) do
		if (type(item) == "number") then
			local attritemid = doPlayerGiveItemContainer(cid, 2596, item, count, subType)
			doItemSetAttribute(attritemid.uid, "description", "This item belongs to ".. getPlayerName(cid) ..".")
			doItemSetAttribute(attritemid.uid, "aid", getPlayerGUID(cid)+10000)
		elseif (type(item) == "string") then
			doPlayerGiveItemContainer(cid, 2596,getItemIdByName(item), count, subType)
		else
			error("Undefinied type of item name")
		end
	end
 
	return doPlayerSendMailByName(getCreatureName(cid), parcel, town) 
end

Try that
 
LUA:
local function doPlayerAddDepotItems(cid, items, town)
	if (not isPlayer(cid)) then
		error("Player not found")
	end
	local town = town or getPlayerTown(cid)
 
	local parcel = doCreateItemEx(ITEM_PARCEL)
	for item, count in pairs(items) do
		if (type(item) == "number") then
			local attritemid = doPlayerGiveItemContainer(cid, 2596, item, count, subType)
			doItemSetAttribute(attritemid, "description", "This item belongs to ".. getPlayerName(cid) ..".")
			doItemSetAttribute(attritemid, "aid", getPlayerGUID(cid)+10000)
		elseif (type(item) == "string") then
			doPlayerGiveItemContainer(cid, 2596,getItemIdByName(item), count, subType)
		else
			error("Undefinied type of item name")
		end
	end
 
	return doPlayerSendMailByName(getCreatureName(cid), parcel, town) 
end

function onThink(interval, lastExecution, thinkInterval)

	local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")
	
		if(result:getID() ~= -1) then
			while(true) do
				cid = getCreatureByName(tostring(result:getDataString("player")))
				product = tonumber(result:getDataInt("product"))
				itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
					if isPlayer(cid) then
						local id = tonumber(itemr:getDataInt("item"))
						local tid = tonumber(result:getDataInt("id"))
						local count = tonumber(itemr:getDataInt("count"))
						local tipe = tonumber(itemr:getDataInt("type"))
						local productn = tostring(itemr:getDataString("name"))
							if isInArray({5,8},tipe) then
								if isPlayer(cid) then
									local received = doPlayerAddDepotItems(cid, {[id]=count})
									if received then
										doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
										db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
										doPlayerSave(cid)
									else
										doPlayerSendTextMessage(cid,19, "Report to a gamemaster..")
									end
								else
									doPlayerSendTextMessage(cid,19, "Report to a gamemaster.")
								end
							elseif isInArray({6,7},tipe) then
									if tipe == 6 then
										bcap = 8
										bid = 1987
									elseif tipe == 7 then
										bcap = 20
										bid = 1988
									end
									if isItemRune(id) then
										count = 1
									end
									if isPlayer(cid) then
										local bag = doCreateItemEx(bid, 1)
											for i = 1,bcap do
												doAddContainerItem(bag, id, count)
											end
										received = doPlayerAddItemEx(cid, bag, true)
										if received then
											doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
											db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
											doPlayerSave(cid)
										else
											doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need a free slot on container to receive "..productn..".")
										end
									else
										doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need "..getItemWeightById(id, count).." of free capacity to receive "..productn..".")
									end
							end
					end
				itemr:free()
				if not(result:next()) then
					break
				end
			end
			result:free()
		end
	return true
end
 
Yeah, I think it's the subType argument, it's not defined anywhere on the script.
So, get change all the functions that use "subType".

LUA:
local function doPlayerAddDepotItems(cid, items, town)
	if (not isPlayer(cid)) then
		error("Player not found")
	end
	local town = town or getPlayerTown(cid)
 
	local parcel = doCreateItemEx(ITEM_PARCEL)
	for item, count in pairs(items) do
		if (type(item) == "number") then
			local attritemid = doPlayerGiveItemContainer(cid, 2596, item, count)
			doItemSetAttribute(attritemid.uid, "description", "This item belongs to ".. getPlayerName(cid) ..".")
			doItemSetAttribute(attritemid.uid, "aid", getPlayerGUID(cid)+10000)
		elseif (type(item) == "string") then
			doPlayerGiveItemContainer(cid, 2596,getItemIdByName(item), count)
		else
			error("Undefinied type of item name")
		end
	end
 
	return doPlayerSendMailByName(getCreatureName(cid), parcel, town) 
end
 
function onThink(interval, lastExecution, thinkInterval)
 
	local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")
 
		if(result:getID() ~= -1) then
			while(true) do
				cid = getCreatureByName(tostring(result:getDataString("player")))
				product = tonumber(result:getDataInt("product"))
				itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
					if isPlayer(cid) then
						local id = tonumber(itemr:getDataInt("item"))
						local tid = tonumber(result:getDataInt("id"))
						local count = tonumber(itemr:getDataInt("count"))
						local tipe = tonumber(itemr:getDataInt("type"))
						local productn = tostring(itemr:getDataString("name"))
							if isInArray({5,8},tipe) then
								if isPlayer(cid) then
									local received = doPlayerAddDepotItems(cid, {[id]=count})
									if received then
										doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
										db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
										doPlayerSave(cid)
									else
										doPlayerSendTextMessage(cid,19, "Report to a gamemaster..")
									end
								else
									doPlayerSendTextMessage(cid,19, "Report to a gamemaster.")
								end
							elseif isInArray({6,7},tipe) then
									if tipe == 6 then
										bcap = 8
										bid = 1987
									elseif tipe == 7 then
										bcap = 20
										bid = 1988
									end
									if isItemRune(id) then
										count = 1
									end
									if isPlayer(cid) then
										local bag = doCreateItemEx(bid, 1)
											for i = 1,bcap do
												doAddContainerItem(bag, id, count)
											end
										received = doPlayerAddItemEx(cid, bag, true)
										if received then
											doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
											db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
											doPlayerSave(cid)
										else
											doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need a free slot on container to receive "..productn..".")
										end
									else
										doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need "..getItemWeightById(id, count).." of free capacity to receive "..productn..".")
									end
							end
					end
				itemr:free()
				if not(result:next()) then
					break
				end
			end
			result:free()
		end
	return true
end
 
I only fixed function doPlayerAddDepotItems. I didn't checked the other inside onThink function.
LUA:
function doPlayerAddDepotItems(cid, items, town)
	if (not isPlayer(cid)) then
		error("Player not found")
	end
	local town = town or getPlayerTown(cid)
 
	--doPlayerGiveItemContainer returns boolean. Instead, use doCreateItemEx and add items with doAddContainerItem.
	local attritemid = doCreateItemEx(2596, 1)
	doItemSetAttribute(attritemid, "description", "This item belongs to " .. getPlayerName(cid) .. ".")
	doItemSetAttribute(attritemid, "owner", getPlayerGUID(cid))
	for item, count in pairs(items) do
		if (type(item) == "number") then
			doAddContainerItem(attritemid, item, count) --add item to parcel.
		elseif (type(item) == "string") then
			if getItemIdByName(item) then
				doAddContainerItem(attritemid, item, count)
			end
		else
			error("Undefinied type of item name")
		end
	end
 
	return doPlayerSendMailByName(getCreatureName(cid), attritemid, town) 
end
 
function onThink(interval, lastExecution, thinkInterval)
 
	local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")
 
		if(result:getID() ~= -1) then
			while(true) do
				cid = getCreatureByName(tostring(result:getDataString("player")))
				product = tonumber(result:getDataInt("product"))
				itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
					if isPlayer(cid) then
						local id = tonumber(itemr:getDataInt("item"))
						local tid = tonumber(result:getDataInt("id"))
						local count = tonumber(itemr:getDataInt("count"))
						local tipe = tonumber(itemr:getDataInt("type"))
						local productn = tostring(itemr:getDataString("name"))
							if isInArray({5,8},tipe) then
								if isPlayer(cid) then
									local received = doPlayerAddDepotItems(cid, {[id]=count})
									if received then
										doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
										db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
										doPlayerSave(cid)
									else
										doPlayerSendTextMessage(cid,19, "Report to a gamemaster..")
									end
								else
									doPlayerSendTextMessage(cid,19, "Report to a gamemaster.")
								end
							elseif isInArray({6,7},tipe) then
									if tipe == 6 then
										bcap = 8
										bid = 1987
									elseif tipe == 7 then
										bcap = 20
										bid = 1988
									end
									if isItemRune(id) then
										count = 1
									end
									if isPlayer(cid) then
										local bag = doCreateItemEx(bid, 1)
											for i = 1,bcap do
												doAddContainerItem(bag, id, count)
											end
										received = doPlayerAddItemEx(cid, bag, true)
										if received then
											doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
											db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
											doPlayerSave(cid)
										else
											doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need a free slot on container to receive "..productn..".")
										end
									else
										doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need "..getItemWeightById(id, count).." of free capacity to receive "..productn..".")
									end
							end
					end
				itemr:free()
				if not(result:next()) then
					break
				end
			end
			result:free()
		end
	return true
end

Not tested.
 
Last edited:
Oh ok, i thought the item that must receive the attr is the parcel
LUA:
function doPlayerAddDepotItems(cid, items, town)
	if (not isPlayer(cid)) then
		error("Player not found")
	end
	local town = town or getPlayerTown(cid)
 
	--doPlayerGiveItemContainer returns boolean. Instead, use doCreateItemEx and add items with doAddContainerItem.
	local attritemid = doCreateItemEx(2596, 1)
	for item, count in pairs(items) do
		local thing = nil
		if (type(item) == "number") then
			thing = doAddContainerItem(attritemid, item, count) --add item to parcel.
		elseif (type(item) == "string") then
			if getItemIdByName(item) then
				thing = doAddContainerItem(attritemid, item, count)
			end
		end
		if not thing then
			error("Undefinied type of item id or name: " .. item)
		else
			doItemSetAttribute(thing, "description", "This item belongs to " .. getPlayerName(cid) .. ".")
			doItemSetAttribute(thing, "owner", getPlayerGUID(cid))
		end
	end
 
	return doPlayerSendMailByName(getCreatureName(cid), attritemid, town) 
end
 
function onThink(interval, lastExecution, thinkInterval)
 
	local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")
 
		if(result:getID() ~= -1) then
			while(true) do
				cid = getCreatureByName(tostring(result:getDataString("player")))
				product = tonumber(result:getDataInt("product"))
				itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
					if isPlayer(cid) then
						local id = tonumber(itemr:getDataInt("item"))
						local tid = tonumber(result:getDataInt("id"))
						local count = tonumber(itemr:getDataInt("count"))
						local tipe = tonumber(itemr:getDataInt("type"))
						local productn = tostring(itemr:getDataString("name"))
							if isInArray({5,8},tipe) then
								if isPlayer(cid) then
									local received = doPlayerAddDepotItems(cid, {[id]=count})
									if received then
										doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
										db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
										doPlayerSave(cid)
									else
										doPlayerSendTextMessage(cid,19, "Report to a gamemaster..")
									end
								else
									doPlayerSendTextMessage(cid,19, "Report to a gamemaster.")
								end
							elseif isInArray({6,7},tipe) then
									if tipe == 6 then
										bcap = 8
										bid = 1987
									elseif tipe == 7 then
										bcap = 20
										bid = 1988
									end
									if isItemRune(id) then
										count = 1
									end
									if isPlayer(cid) then
										local bag = doCreateItemEx(bid, 1)
											for i = 1,bcap do
												doAddContainerItem(bag, id, count)
											end
										received = doPlayerAddItemEx(cid, bag, true)
										if received then
											doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received "..productn.." in depot of your hometown.")
											db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
											doPlayerSave(cid)
										else
											doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need a free slot on container to receive "..productn..".")
										end
									else
										doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need "..getItemWeightById(id, count).." of free capacity to receive "..productn..".")
									end
							end
					end
				itemr:free()
				if not(result:next()) then
					break
				end
			end
			result:free()
		end
	return true
end
 
Well i work with custom attributes, you can set an item the attr you want. I used 'owner' to save the player's ID in the item, but you can change it to 'aid' or any other.
 
Not sure functions onEquip or onDeEquip works like that, you can try creating a script with something like
LUA:
function onEquip(cid, item, ...) --(...) because i don't remember the params for that function.
	if getItemAttribute(item.uid, "owner") and getItemAttribute(item.uid, "owner") ~= getPlayerGUID(cid) then
		return false
	end
	return true
end
 
Back
Top