• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Delete Empty Backpacks

BeniS

Advanced OT User
Senator
Joined
Aug 8, 2009
Messages
1,850
Reaction score
189
Location
New Zealand
Backpack.gif
Delete Empty Backpacks
Backpack.gif


pawlacz741 requested a script that will check for all the players empty backpacks with the item id 1988. Here

So I thought I would help out.

The script will check the main backpack and ammo slot backpack (if they are there) for all the empty backpacks inside them and removes them all. It will not remove a backpack that has any other item in it. If you have a backpack inside a backpack then an item inside that backpack, that whole chain of backpacks won't be removed (I may change it so it moves the backpack with the items out to the main backpack when I have time). I Made it fairly configurable so you can add more backpacks types if you like.

I have tested it out and it works perfectly fine with 0.3.6pl1 and should work on 0.4, how ever I would suggest that you test it in your server first before making it public to your OT community :p

Add to drop.lua:
LUA:
--[[
	!---------------------------------!
	!---Created by Teh Maverick-------!
	!-------www.otland.net------------!
	!---------------------------------!
]]

--Config---
	bagsToDelete = {1988, 2000, 2001} -- Add the backpack ids you want to be deleted here

function onSay(cid, words, param)

local container, bagItems = {}, {}
local firstBag = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
local arrowBag = getPlayerSlotItem(cid, CONST_SLOT_AMMO)
local bagCount = 0

	--Check Main Backpack
	if isItemContainer(firstBag.itemid) then
		for i = 0, getContainerSize(firstBag.uid)-1 do
			for i = 0, getContainerSize(firstBag.uid)-1 do
				container[i] = getContainerItem(firstBag.uid, i)
				if container[i].itemid > 0 then
					if isItemContainer(container[i].itemid) then
						doCheckNextBag(container[i])
					end
				end
			end
		end
	end
	--Check Arrow Slot
	if isItemContainer(arrowBag.itemid) then
		for i = 0, getContainerSize(arrowBag.uid)-1 do
			for i = 0, getContainerSize(arrowBag.uid)-1 do
				container[i] = getContainerItem(arrowBag.uid, i)
				if container[i].itemid > 0 then
					if isItemContainer(container[i].itemid) then
						doCheckNextBag(container[i])
					end
				end
			end
		end
	end
end
	
function doCheckNextBag(container)
local itemsInBag = {}
local bagEmptySlotCheck = 0
local bagSize = getContainerSize(container.uid)

	for i = 0, getContainerSize(container.uid)-1 do
		itemsInBag[i] = getContainerItem(container.uid, i)
		if itemsInBag[i].itemid > 0 then
			if isItemContainer(itemsInBag[i].itemid) then
				doCheckNextBag(itemsInBag[i])
			end
		else
			bagEmptySlotCheck = bagEmptySlotCheck + 1
		end
	end
	if bagEmptySlotCheck == bagSize and isInArray(bagsToDelete, container.itemid) then
		doRemoveItem(container.uid, 1)
		bagEmptySlotCheck = 0
	end
end

Add to your talkactions.xml:
XML:
<talkaction words="!drop" event="script" value="drop.lua"/>

Hope this is useful! I will probably get around to updating this later on as its late here and probably could tidy up the code a but haha.

Rep++ If you like!
 
I've edited Cykotitan's script and now if the containers have some action id it won't be removed (Some quest are using backpack with action id)
LUA:
local removable = {1987, 1988}
 
function removeEmptyContainers(uid, ids)
	local ret, i = 0, 0
	while i < getContainerSize(uid) do
		local v = getContainerItem(uid, i)
		if isContainer(v.uid) then
			if getContainerSize(v.uid) ~= 0 then
				ret = ret + removeEmptyContainers(v.uid, removable)
				if isInArray(removable, v.itemid) and getContainerSize(v.uid) == 0 then
					i = i - 1
				end
			elseif isInArray(removable, v.itemid) then
				if v.actionid < 1 then
					doRemoveItem(v.uid)
					i = i - 1
					ret = ret + 1
				end
			end
		end
		i = i + 1
	end
	return ret
end
 
function onSay(cid, words, param, channel)
	local ret = 0
	for i = 1, 10 do
		local v = getPlayerSlotItem(cid, i).uid
		if v > 0 and isContainer(v) then
			ret = ret + removeEmptyContainers(v, removable)
		end
	end
	ret = tostring(ret)
	return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, ret .. " empty container" .. (ret:sub(-1) == "1" and ret:sub(-2) ~= "11" and "" or "s") .. " removed.")
end
 
Back
Top