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

RevScripts throw items delay

adrenyslopez

Member
Joined
Dec 22, 2015
Messages
201
Reaction score
15
Hello, good night, someone will have a method to delay the following items by throwing them on the floor.

  • 2148 (Gold Coin)
  • 2152 (Platinum Coin)
  • 2160 (Crystal Coin)
  • 3976 (Worms)

In a nutshell, for
put a delay on the anti push

i used otbr tfs 1.3
 
Try this?

It tracks the last tile that the 'delayed items' were placed on.
If someone tries to place another delayed item onto the same tile again, they are delayed.

If someone places it on tile 1, then tile 2, then tile 1 again, there is no delay, as these are different tiles each time.

Lua:
local delayedItems = {2148, 2152, 2160, 3976}
local delay = 1000 -- milliseconds
local creatures = {}

local delayMovingItemsToSameTile = EventCallback

delayMovingItemsToSameTile.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if not table.contains(delayedItems, item:getId()) then
        return true
    end
    if toPosition.x == CONTAINER_POSITION then
        return true
    end
    local cid = self:getId()
    local mtime = os.mtime()
    if creatures[cid] and creatures[cid].position == toPosition and creatures[cid].delayTime > mtime then
        return false
    end
    creatures[cid] = {position = toPosition, delayTime = mtime + delay}
    return true
end

delayMovingItemsToSameTile:register()
 
Try this?

It tracks the last tile that the 'delayed items' were placed on.
If someone tries to place another delayed item onto the same tile again, they are delayed.

If someone places it on tile 1, then tile 2, then tile 1 again, there is no delay, as these are different tiles each time.

Lua:
local delayedItems = {2148, 2152, 2160, 3976}
local delay = 1000 -- milliseconds
local creatures = {}

local delayMovingItemsToSameTile = EventCallback

delayMovingItemsToSameTile.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if not table.contains(delayedItems, item:getId()) then
        return true
    end
    if toPosition.x == CONTAINER_POSITION then
        return true
    end
    local cid = self:getId()
    local mtime = os.mtime()
    if creatures[cid] and creatures[cid].position == toPosition and creatures[cid].delayTime > mtime then
        return false
    end
    creatures[cid] = {position = toPosition, delayTime = mtime + delay}
    return true
end

delayMovingItemsToSameTile:register()
That system is very useful, but is there another one that doesn't allow you to drop certain items under you? That you can't pull under your feet or the other player's... to eliminate the anti push completely.
 
That system is very useful, but is there another one that doesn't allow you to drop certain items under you? That you can't pull under your feet or the other player's... to eliminate the anti push completely.

Alright.
If the tile has a player on it, it won't allow the item to be moved under them.

Lua:
local disableMovingItemsUnderAPlayer = EventCallback

disableMovingItemsUnderAPlayer.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if toPosition.x ~= CONTAINER_POSITION then
        return true
    end
    local tile = Tile(toPosition)
    if not tile then
        return false
    end
    local creatures = tile:getCreatures()
    for i = 1, #creatures do
        local player = Player(creatures[i])
        if player:isPlayer() then
            return false
        end
    end
    return true
end

disableMovingItemsUnderAPlayer:register()
 
Alright.
If the tile has a player on it, it won't allow the item to be moved under them.

Lua:
local disableMovingItemsUnderAPlayer = EventCallback

disableMovingItemsUnderAPlayer.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if toPosition.x ~= CONTAINER_POSITION then
        return true
    end
    local tile = Tile(toPosition)
    if not tile then
        return false
    end
    local creatures = tile:getCreatures()
    for i = 1, #creatures do
        local player = Player(creatures[i])
        if player:isPlayer() then
            return false
        end
    end
    return true
end

disableMovingItemsUnderAPlayer:register()
It didn't work for me, it still lets me drop objects under me... am I doing something wrong? create a new file and put it inside /scripts/eventcallbacks/player.
 
Replace toPosition.x to fromPosition.x or if you want delay to work even by moving items from ground and not just from container then just replace ~= with ==
 
It didn't work for me, it still lets me drop objects under me... am I doing something wrong? create a new file and put it inside /scripts/eventcallbacks/player.
made a mistake
Lua:
if toPosition.x ~= CONTAINER_POSITION then
change to ==
 
Try this?

It tracks the last tile that the 'delayed items' were placed on.
If someone tries to place another delayed item onto the same tile again, they are delayed.

If someone places it on tile 1, then tile 2, then tile 1 again, there is no delay, as these are different tiles each time.

Lua:
local delayedItems = {2148, 2152, 2160, 3976}
local delay = 1000 -- milliseconds
local creatures = {}

local delayMovingItemsToSameTile = EventCallback

delayMovingItemsToSameTile.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if not table.contains(delayedItems, item:getId()) then
        return true
    end
    if toPosition.x == CONTAINER_POSITION then
        return true
    end
    local cid = self:getId()
    local mtime = os.mtime()
    if creatures[cid] and creatures[cid].position == toPosition and creatures[cid].delayTime > mtime then
        return false
    end
    creatures[cid] = {position = toPosition, delayTime = mtime + delay}
    return true
end

delayMovingItemsToSameTile:register()
I have this error
Lua:
Lua Script Error: [Scripts Interface]
/home/forgottenserver/data/scripts/antipush.lua
/home/forgottenserver/data/scripts/antipush.lua:21: attempt to index local 'delayMovingItemsToSameTile' (a nil value)
stack traceback:
        [C]: in function '__newindex'
        /home/forgottenserver/data/scripts/antipush.lua:21: in main chunk
> antipush.lua [error]
 
I have this error
Lua:
Lua Script Error: [Scripts Interface]
/home/forgottenserver/data/scripts/antipush.lua
/home/forgottenserver/data/scripts/antipush.lua:21: attempt to index local 'delayMovingItemsToSameTile' (a nil value)
stack traceback:
        [C]: in function '__newindex'
        /home/forgottenserver/data/scripts/antipush.lua:21: in main chunk
> antipush.lua [error]
You must have copied it wrong.

I just tested it and have no problems
 
You must have copied it wrong.

I just tested it and have no problems
error
1647216050532.png

script.lua
Lua:
local delayedItems = {2148, 2152, 2160, 3976}
local delay = 1000 -- milliseconds
local creatures = {}

local delayMovingItemsToSameTile = EventCallback

delayMovingItemsToSameTile.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if not table.contains(delayedItems, item:getId()) then
        return true
    end
    if toPosition.x == CONTAINER_POSITION then
        return true
    end
    local cid = self:getId()
    local mtime = os.mtime()
    if creatures[cid] and creatures[cid].position == toPosition and creatures[cid].delayTime > mtime then
        return false
    end
    creatures[cid] = {position = toPosition, delayTime = mtime + delay}
    return true
end

delayMovingItemsToSameTile:register()
1647216074726.png
 
Dunno what to do for you here.

It works on regular tfs, but not your otbr version.

My only solution for you is to go find a working onMoveItem script.. and transplant my script into it?
 
Try this?

It tracks the last tile that the 'delayed items' were placed on.
If someone tries to place another delayed item onto the same tile again, they are delayed.

If someone places it on tile 1, then tile 2, then tile 1 again, there is no delay, as these are different tiles each time.

Lua:
local delayedItems = {2148, 2152, 2160, 3976}
local delay = 1000 -- milliseconds
local creatures = {}

local delayMovingItemsToSameTile = EventCallback

delayMovingItemsToSameTile.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if not table.contains(delayedItems, item:getId()) then
        return true
    end
    if toPosition.x == CONTAINER_POSITION then
        return true
    end
    local cid = self:getId()
    local mtime = os.mtime()
    if creatures[cid] and creatures[cid].position == toPosition and creatures[cid].delayTime > mtime then
        return false
    end
    creatures[cid] = {position = toPosition, delayTime = mtime + delay}
    return true
end

delayMovingItemsToSameTile:register()
Hey @Xikini! Sorry to revive the topic, but is it possible to apply the same logic from your script in TFS 0.4? Thanks!
 
Back
Top