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

[TFS 1.4] Disallow specific items from being dropped on the floor

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,756
Solutions
578
Reaction score
5,305
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 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:
Thank you Xikini I didn't want to disturb thats why i dont made the support thread. I'm testing it with nekiros downgrade 1.4 and it's not working somehow If I have the item inside a container it's removing skull also no error in console
 
Thank you Xikini I didn't want to disturb thats why i dont made the support thread. I'm testing it with nekiros downgrade 1.4 and it's not working somehow If I have the item inside a container it's removing skull also no error in console
I would definitely open a support thread for that.

The script above only returns true or false, and thus it's only function is to allow or disallow an item from being moved.

There is no reason/scenario why it would interact with a player and remove their skull. :/
 
Oh I actually know whats going on with the skulls :p

Anyone else tested?
 
Last edited:
Back
Top