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

Lua TFS(0.4) - onRemoveItem

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,529
Solutions
1
Reaction score
85
Location
Portugal
Hi, based on other script, I'm creating this one to avoid players moving some items and I'm having some issues like:

1. If you throw an item that's not on the list and it's not stackable on the tile you also can't move that item..

2. If the item is on the list but it's stackable you can still move it..

Lua:
local list = {1964, 2160} -- list of items that can't be moved

function onRemoveItem(moveitem, tileitem, position, cid)
    for k, v in ipairs(list) do
        if getTileItemById(position, v) then
            doTeleportThing(moveitem.uid, position)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            doPlayerSendCancel(cid, "You can't move this item.")
        else
            doTeleportThing(moveitem.uid, getCreaturePosition(cid)) -- teleports items that are not on the list to player pos
        end
    end
    return true
end
 
Solution
Yeah you're right but I'm only planning to use this script to avoid people moving map items, I know it would be easier to just set unique ID's so I feel that it's more efficient doing this with action-ID so there's no mistakes :p

The array fixed it but still having the issue if item is stack-able it can still be moved :|
I've dealt with this so much in the past, and it's super annoying. xP

in 0.3.7 we have a feature called 'onThrow' that allows us to check the item being moved and it's destination before the item is moved.
This allowed us to bypass the issue with checking the item being moved prior to it actually being moved, instead of moving the item then checking to see what should happen, like with onRemoveItem and...
Hi, based on other script, I'm creating this one to avoid players moving some items and I'm having some issues like:

1. If you throw an item that's not on the list and it's not stackable on the tile you also can't move that item..

2. If the item is on the list but it's stackable you can still move it..

Lua:
local list = {1964, 2160} -- list of items that can't be moved

function onRemoveItem(moveitem, tileitem, position, cid)
    for k, v in ipairs(list) do
        if getTileItemById(position, v) then
            doTeleportThing(moveitem.uid, position)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
            doPlayerSendCancel(cid, "You can't move this item.")
        else
            doTeleportThing(moveitem.uid, getCreaturePosition(cid)) -- teleports items that are not on the list to player pos
        end
    end
    return true
end
I don't think this is a good method for whatever your doing, since a item that can be moved, can have a cannot be moved item thrown on top, and then the can be moved item would be permanently lost underneath.
In either case, this should do the trick.
Lua:
local list = {1964, 2160} -- list of items that can't be moved

function onRemoveItem(moveitem, tileitem, position, cid)
    if isInArray(list, moveitem.itemid) then
        doTeleportThing(moveitem.uid, position)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "You can't move this item.")
    end
    return true
end
 
Yeah you're right but I'm only planning to use this script to avoid people moving map items, I know it would be easier to just set unique ID's so I feel that it's more efficient doing this with action-ID so there's no mistakes :p

The array fixed it but still having the issue if item is stack-able it can still be moved :|
 
Yeah you're right but I'm only planning to use this script to avoid people moving map items, I know it would be easier to just set unique ID's so I feel that it's more efficient doing this with action-ID so there's no mistakes :p

The array fixed it but still having the issue if item is stack-able it can still be moved :|
I've dealt with this so much in the past, and it's super annoying. xP

in 0.3.7 we have a feature called 'onThrow' that allows us to check the item being moved and it's destination before the item is moved.
This allowed us to bypass the issue with checking the item being moved prior to it actually being moved, instead of moving the item then checking to see what should happen, like with onRemoveItem and onAddItem.
This then causes a cascade of unforeseen issues, such as players trading the items with each other, or if the item has the attribute 'onUse' they can stand x squares away from item and destination, and the system picks up the item to be used elsewhere, but then the item is trapped in the player inventory.

Without some sort source modification it's impossible to fully stop players from moving items, unless you only use it for items which don't have the onUse functionality.
That being said, you don't have the 'onThrow' in 0.4 by default, and would need to add that.

The only full-proof method is to use the item called 'something sparkly' which sits on top of the items and you can look-through it, however you still have the ugly sparkles sitting everywhere.
Even then, this item on top of items trick only works until you reach a client version that has the 'see everything on the tile' feature.
But you'd want to be using the newer TFS 1.2 or 1.3 by then anyways.

Anyways tldr,
without a source edit, 0.4 can't solve this issue, since stackable items are generally hard to deal with.. due to them constantly.. stacking. xD
Or at least, I haven't been able to think of a viable solution.

If you can add the onThrow feature though, and keep in mind the 'onUse' items, and also block the trading of such items, you could have a viable solution there, I suppose.
 
Solution
Yeah I was afraid of that answer, I know that in TFS 1.2 it's so easy to fix this using player events but I really have to use 0.4 here xD
Well thanks again for your help <3

I decided that I'll be using this only for non-stack-able items, also tested if people can trade them and gladly they can't trade cuz they can't move xD
 
Yeah I was afraid of that answer, I know that in TFS 1.2 it's so easy to fix this using player events but I really have to use 0.4 here xD
Well thanks again for your help <3

I decided that I'll be using this only for non-stack-able items, also tested if people can trade them and gladly they can't trade cuz they can't move xD
You can trade items on the ground though.
But with it teleporting back to it's original location, it appears as if the trade is not going through. ;)

I doubt it matters, but figured I'd point that out.
 
Yeah I noticed xD the trade goes through, traded aol for gem, the guy got the aol and the other got nothing I'll be carefull using it xD thanks for pointing it out <3
 
Back
Top Bottom