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

Solved Not allowing bags inside other bags.

https://otland.net/threads/creatureevent-onmove-very-advanced.134016/
Might have the right idea but I'm not experienced enough to figure out what to do still.

I am looking to make one specific backpack only allows items, NOT containers to be put inside of it. --> This is what I need.
Replace Player onMoveItem in player.lua with the code below, make sure you backup the file 1st.
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    if item:isContainer() and toPosition.x == CONTAINER_POSITION then
        return false
    end
    return true
end
 
Last edited:
Replace Player onMoveItem in player.lua with the code below, make sure you backup the file 1st.
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    if item:isContainer() and toPosition.x == CONTAINER_POSITION then
        return false
    end
    return true
end
What about for a single item id? That itemId will be not allowing the containers :p
 
Have you tested it?
I have not, if we look at the constructionkits.lua as an example
https://github.com/otland/forgotten...ctions/scripts/other/constructionkits.lua#L22
It tells you
Code:
if fromPosition.x == CONTAINER_POSITION then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Put the construction kit on the floor first.")
That the item is in your bag

Since the item is being move to the toPosition we compare it to a bag slot and if this is the case return false, all I am doing guessing here.. while leaving the tough job of testing up to all of you :)
The player slots have CONTAINER_POSITION as well so the players wouldn't be able to move containers to their backpack slot. You have to check if toPosition.y >= 64
 
Code:
Player.bags = {}
function Player:setSpecialBag(itemid)
    if Item(itemid):isContainer() then
        self.bags[itemid] = itemid
    end
end

function Player:onMoveItem(item, count, fromPosition, toPosition)
    local backpack = self.bags[item:getId()]
    if backpack and toPosition.x == CONTAINER_POSITION then
        return false
    end
    return true
end
 
this is all too complicated for me :(
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    if toPosition.x == CONTAINER_POSITION and toPosition.y >= 64 then
        if item:isContainer() then
            local container = self:getContainerById(toPosition.y-64)
            if container:getId() == 2000 then
                self:sendTextMessage(MESSAGE_STATUS_SMALL, "You can't move this item there.")
                return false
            end
        end
    end
    return true
end

This way players cant move containers inside the item with id 2000
 
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    if toPosition.x == CONTAINER_POSITION and toPosition.y >= 64 then
        if item:isContainer() then
            local container = self:getContainerById(toPosition.y-64)
            if container:getId() == 2000 then
                self:sendTextMessage(MESSAGE_STATUS_SMALL, "You can't move this item there.")
                return false
            end
        end
    end
    return true
end

This way players cant move containers inside the item with id 2000
where do i place this code? also does this code work if the bag is in the ammo slot?
 
where do i place this code? also does this code work if the bag is in the ammo slot?
Well this will only work if you're using TFS 1.2, you put this in player.lua inside data\events\scripts (Replace the function that is there)

And you have to edit the line in events.xml to this:
<event class="Player" method="onMoveItem" enabled="1" />

And yes it will work if the bag is in the ammo slot, it will work if the bag is anywhere players are not able to move containers inside that item in any circumstance
 
Well this will only work if you're using TFS 1.2, you put this in player.lua inside data\events\scripts (Replace the function that is there)

And you have to edit the line in events.xml to this:
<event class="Player" method="onMoveItem" enabled="1" />

And yes it will work if the bag is in the ammo slot, it will work if the bag is anywhere players are not able to move containers inside that item in any circumstance
Is there any way this can work for 1.1?
 
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
    if toPosition.x == CONTAINER_POSITION and toPosition.y >= 64 then
        if item:isContainer() then
            local container = self:getContainerById(toPosition.y-64)
            if container:getId() == 2000 then
                self:sendTextMessage(MESSAGE_STATUS_SMALL, "You can't move this item there.")
                return false
            end
        end
    end
    return true
end

This way players cant move containers inside the item with id 2000
Well according to the repository it has the onMoveItem, you probably can.

https://github.com/otland/forgottenserver/blob/1.1/data/events/events.xml
You sure you wrote the script above?
If you did you would not be saying "will probably work"
 
You sure you wrote the script above?
If you did you would not be saying "will probably work"
Do you understand english?

He asked if it will work for TFS 1.1 and the only reason for it to not work is if it doesn't have the event Player:eek:nMoveItem.

"You probably can (use the script)". But he might have an old version of TFS 1.1 and then the event could not be there. So its not 100% sure if he can or cant use the script.

Edit: If you are soooooo good as you say why don't you say if its going to work or not? I can tell just by looking at your codes that it is not going to work, why can't you too? (and you should be saying probably work because you have a lot of bugged scripts in this forum)
 
Do you understand english?

He asked if it will work for TFS 1.1 and the only reason for it to not work is if it doesn't have the event Player:eek:nMoveItem.

"You probably can (use the script)". But he might have an old version of TFS 1.1 and then the event could not be there. So its not 100% sure if he can or cant use the script.

Edit: If you are soooooo good as you say why don't you say if its going to work or not? I can tell just by looking at your codes that it is not going to work, why can't you too? (and you should be saying probably work because you have a lot of bugged scripts in this forum)
Is someone getting upset?
 
Do you understand english?

He asked if it will work for TFS 1.1 and the only reason for it to not work is if it doesn't have the event Player:eek:nMoveItem.

"You probably can (use the script)". But he might have an old version of TFS 1.1 and then the event could not be there. So its not 100% sure if he can or cant use the script.

Edit: If you are soooooo good as you say why don't you say if its going to work or not? I can tell just by looking at your codes that it is not going to work, why can't you too? (and you should be saying probably work because you have a lot of bugged scripts in this forum)

omg thank you so much, i did it and it works perfectly!
Thanks to everyone that helped as well I gave you all 'likes'!
 

New problem, I cant drag bags inside the window, but I can drop bags into it by dragging to the bag itself instead of the window slots
 
New problem, I cant drag bags inside the window, but I can drop bags into it by dragging to the bag itself instead of the window slots
Forgot this, D:

Try it now:
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)
  if toPosition.x == CONTAINER_POSITION then
     if item:isContainer() then
       if toPosition.y >= 64 then
         local container = self:getContainerById(toPosition.y-64)
         local moveToItem = container:getItem(toPosition.z)
         if container:getId() == 2000 or (moveToItem and moveToItem:getId() == 2000) then
           self:sendTextMessage(MESSAGE_STATUS_SMALL, "You can't move this item there.")
           return false
         end
       else
         local moveToItem = self:getSlotItem(toPosition.y)
         if moveToItem and moveToItem:getId() == 2000 then
           self:sendTextMessage(MESSAGE_STATUS_SMALL, "You can't move this item there.")
           return false
         end
       end
     end
  end
  return true
end

Change everywhere there its 2000 :p
 
Last edited:
Back
Top