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

Bag allowing certain items , similar (Gold Pouch)

alejandro762

Well-Known Member
Joined
Sep 6, 2021
Messages
225
Reaction score
64
Hello,


I want to create a simple bag, that you can only allow certains items from a table, like a Gold Pouch.

I tried many ways, the first one was to create an attribute for items that are allowed, doesnt work since you can add any item on container.
The second way i tried onMoveItem, here it was working if you try move items that are not from table inside of the bag,
but there is a trick, that you can just drag and drop above the bag to add any desired item, "calling the drag and drop" seems really hard, it works in order to check if item is equipped, for example bag on the slot backpack checking const_slot_backpack it works, but only on the slot, and not inside the backpack, example, backpack, inside the bag(gold pouch) then check inside of this back.

I see that TFS has not implemented the gold pouch, in order to simply recreate the same code and changing the gold pouch id, yeah i tried with the canary, but the same way, drag and drop is not checked so it's useless.

Finded some posts about onMoveItem that it requires source modification ( already done but not working ).
Finally i tried to copy the same code and recreate the store inbox as another slot, and check this item with a custom attribute , if this attribute is not set to the item (true/false) then do not allow, here the same problem, drag and drop allows any item, from ground, container or equiped.

There is a way to create a bag allowing certains id and checking this "drag and drop" above the bag ?

I am using TFS 1.4 from github otland and otclient.

Thanks in advance

Edit:

here is the script i writed onMoveItem that was working, better than source edit, in order to prevent items moved to 29451 on Slot Ammo (it has container) , but if you dont open container and simply drag and drop on the target item 29451, it allows any items.

Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    local itemsAllowed = {
        27481,
        27480,
    }

    local CONST_SLOT_AMMO = 10
    local CONST_SLOT_BACKPACK = 3
    local MAX_UNSIGNED_CHAR = 255
    local function negativePositiveValueFix(value, min, max)
        return math.max(min, math.min(value, max))
    end
    toPosition.y = math.min(MAX_UNSIGNED_CHAR, toPosition.y)
    local positionYfix= negativePositiveValueFix(toPosition.y - 64, 0, 255)
    local container = self:getContainerById(positionYfix)
    if toPosition.x == CONTAINER_POSITION and toPosition.y >= 64 and container and container:getId() == CONST_SLOT_AMMO and not table.find(itemsAllowed, item:getId()) then
        self:sendTextMessage(MESSAGE_INFO_DESCR, "You can only move allowed items.")
        return RETURNVALUE_NOTMOVEABLE
    end
    if toCylinder == CONST_SLOT_AMMO and container and container:getId() == CONST_SLOT_BACKPACK then
        self:sendTextMessage(MESSAGE_INFO_DESCR, "You can only move allowed items.")
        return RETURNVALUE_NOTMOVEABLE
    elseif toCylinder == CONST_SLOT_AMMO and not table.find(itemsAllowed, item:getId()) then
        self:sendTextMessage(MESSAGE_INFO_DESCR, "You can only move allowed items.")
        return RETURNVALUE_NOTMOVEABLE
    elseif fromCylinder == CONST_SLOT_AMMO and toCylinder == CONST_SLOT_AMMO then
        if not table.find(itemsAllowed, item:getId()) then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "You can only move allowed items.")
            return RETURNVALUE_NOTMOVEABLE
        end
    elseif container and (container:getId() == 29451) then
        if not table.find(itemsAllowed, item:getId()) then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "You can only move allowed items.")
            return RETURNVALUE_NOTMOVEABLE
        end
    end


    if hasEventCallback(EVENT_CALLBACK_ONMOVEITEM) then
        return EventCallback(EVENT_CALLBACK_ONMOVEITEM, self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    end
end
 
Last edited:
I found a way, to get the item allowing only items i want inside.

Now i just want to retrieve from this container an information, but seems not possible in TFS,

Changed in sources: CONST_SLOT_AMMO, to CONST_SLOT_STORE_INBOX,
Done a container not movable on Store Inbox, allowing items from table.

Now i try:

Lua:
local store = player:getSlotItem(CONST_SLOT_STORE_INBOX)
print("Slot:", store)

Is returning nil, seems the slot is not available.?
 
Back
Top