alejandro762
Well-Known Member
- Joined
- Sep 6, 2021
- Messages
- 242
- Reaction score
- 68
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.
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: