• 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 Block item throw to specified tile

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
932
Solutions
23
Reaction score
444
Location
Santiago - Chile
Using TFS 1.4 (8.6 downgrade). Hi! I want to ask for some help today, i've been decorating a coast with some seagulls and used nothing special (id:460) item to make them move in a unreachable area. The thing is, that player can still throw items to that tile (id:460). How I can disable the item throwing to that specific tile id via LUA?

ingame.png

Thanks in advance,
Regards!
 
Solution
There are several ways, I will show you two:

1) with positions
With this method you will not be able to launch things to the configured positions

data/scripts/file.lua
Lua:
local blockedPositions = {
    Position(100, 100, 7)
}

local ec = EventCallback

function ec.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    for _, pos in pairs(blockedPositions) do
        if toPosition == pos then
            return false
        end
    end
    return true
end

ec:register(-1)
2) with actionId - i prefer this
With actionID you will only have to add the configured actionID to the object, and no one will be able to launch things on top of this object with the configured actionID...

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,032
Solutions
102
Reaction score
1,084
Location
London
GitHub
MillhioreBT
There are several ways, I will show you two:

1) with positions
With this method you will not be able to launch things to the configured positions

data/scripts/file.lua
Lua:
local blockedPositions = {
    Position(100, 100, 7)
}

local ec = EventCallback

function ec.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    for _, pos in pairs(blockedPositions) do
        if toPosition == pos then
            return false
        end
    end
    return true
end

ec:register(-1)
2) with actionId - i prefer this
With actionID you will only have to add the configured actionID to the object, and no one will be able to launch things on top of this object with the configured actionID
data/scripts/file.lua
Lua:
local blockedThrowAid = 8001

local ec = EventCallback

function ec.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    local tile = Tile(toPosition)
    if tile then
        for _, i in pairs(tile:getItems()) do
            if i:getActionId() == blockedThrowAid then
                return false
            end
        end
    end
    return true
end

ec:register(-1)

3) With ground a bit optimized
This method is similar to number 2, only that we only check if the ground has the actionID and in this way we do not have to go through a loop in each throwning
data/scripts/file.lua
Lua:
local blockedThrowAid = 8001

local ec = EventCallback

function ec.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    local tile = Tile(toPosition)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getActionId() == blockedThrowAid then
                return false
            end
        end
    end
    return true
end

ec:register(-1)

4) With areas
With this method, ranges of areas are used, in this way it is enough to set an area and it is a little easier than the previous methods
data/scripts/file.lua
Lua:
local blockedAreas = {
    { from=Position(100, 100, 7), to=Position(110, 110, 7) }
}

local ec = EventCallback

function ec.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    for _, area in pairs(blockedAreas) do
        if toPosition:isInRange(area.from, area.to) then
            return false
        end
    end
    return true
end

ec:register(-1)
 
Last edited:
Solution

Boy67

Intermediate OT User
Joined
Jul 4, 2007
Messages
265
Solutions
11
Reaction score
108
Location
England
Why not just check if any of the ID's in a tile are ID 460, that way you don't have to spam the map editor with action ID's?
 
Last edited:
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
932
Solutions
23
Reaction score
444
Location
Santiago - Chile
Boy67 said:
Why not just check if any of the ID's in a tile are ID 460, that way you don't have to spam the map editor with action ID's?
This can be a good method, since I can create new tiles on object builder specifically for this. If you wish to add this solution to the thread would be great! :D
zbisu said:
Just build id 1548 around the floors.
Hmm I always used 1548 to block paths, never used that way i'll test, thanks!!
zbisu said:
Or build it on +2, you can't throw items to +2 anywhere
For this it's a bit complicated because of mehah's shading system, +2 floors will shade the lower floors

I'm still happy with the current result since I asked to do via LUA, but if you guys have more ideas to achieve this post on this thread, the title will guide easily for those who search for this
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Support Team
Joined
Mar 16, 2017
Messages
1,032
Solutions
102
Reaction score
1,084
Location
London
GitHub
MillhioreBT
@ralke I have added for you, a fourth method with areas, so that you do not have to edit objects or add many actionIDs, it may be useful for something else
 
Top