- Joined
- Nov 17, 2010
- Messages
- 6,830
- Solutions
- 586
- Reaction score
- 5,413
Idea from here.
This script will stop specific items from being dropped on the floor.
This will also stop those specified items from being dropped on the floor, even if they are inside a container, or if you try to put the item into a container, that is on the floor.
Exception made for the items to be allowed to be put into a depot.
One small caveat;
If the item is on a player, and the player dies, the items can be dropped into the player corpse by the server, thereby technically allowing the item to reach the floor.
As the above situation might be something a server owner might want to happen, I have not included any script to stop this function.
drop this into
I have left my test comments inside the script, so you can test yourself and know what's going on.
This script will stop specific items from being dropped on the floor.
This will also stop those specified items from being dropped on the floor, even if they are inside a container, or if you try to put the item into a container, that is on the floor.
Exception made for the items to be allowed to be put into a depot.
One small caveat;
If the item is on a player, and the player dies, the items can be dropped into the player corpse by the server, thereby technically allowing the item to reach the floor.
As the above situation might be something a server owner might want to happen, I have not included any script to stop this function.
drop this into
data/scripts
as per usual.I have left my test comments inside the script, so you can test yourself and know what's going on.
Lua:
local disallowedItems = {1988}
-- if an item in the array is inside the container, return true, else false
local function checkContainerForItems(container, itemArray)
if not container:isContainer() then
return false
end
local containers = {}
table.insert(containers, container)
while #containers > 0 do
for i = 0, containers[1]:getSize() - 1 do
local item = containers[1]:getItem(i)
if table.contains(itemArray, item:getId()) then
return true, item
end
if item:isContainer() then
table.insert(containers, item)
end
end
table.remove(containers, 1)
end
return false
end
local disableMovingItemsToGround = EventCallback
disableMovingItemsToGround.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
local isGround = false
if toPosition.x ~= CONTAINER_POSITION then
isGround = true
end
if not isGround then
if toCylinder:isPlayer() or toCylinder:getTopParent():isPlayer() then
-- print("Item is being moved onto/inside a player inventory.")
return true
end
if toCylinder:isItem() then
if table.contains({2594}, toCylinder:getId()) or table.contains({2589, 2590, 2591, 2592}, toCylinder:getTopParent():getId()) then
-- print("Item is being moved into/inside a players depot.")
return true
end
end
end
if table.contains(disallowedItems, item:getId()) then
if not isGround then
print("-> Item ON disallowedItems list being placed into a container on the floor. (itemid: " .. item:getId() .. ", itemName: " .. item:getName() .. ")")
else
print("-> Item ON disallowedItems list. (itemid: " .. item:getId() .. ", itemName: " .. item:getName() .. ")")
end
return false
end
local check, itemFound = checkContainerForItems(item, disallowedItems)
if check then
if not isGround then
print("-> An item inside container ON disallowedItems list is being placed into a container on the floor. (itemid: " .. itemFound:getId() .. ", itemName: " .. itemFound:getName() .. ")")
else
print("-> An item inside container is ON disallowedItems list. (itemid: " .. itemFound:getId() .. ", itemName: " .. itemFound:getName() .. ")")
end
return false
end
return true
end
disableMovingItemsToGround:register()
Last edited: