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

tfs 1.2 script request

jackl90

Member
Joined
Jul 25, 2017
Messages
249
Reaction score
12
Is there any way to send x msg to the player only if he moves any item 6 square meters away to the central Tile?
I have never seen any function related to tile counting ^^ exist?



Sem título.jpg
 
Is there any way to send x msg to the player only if he moves any item 6 square meters away to the central Tile?
I have never seen any function related to tile counting ^^ exist?



View attachment 39444
It should be possible, but instead of counting tiles you should just compare the distance.
Where the center tile should be the items position(fromPosition)or player position if you throw it from your backpack.
and the target position should just be the position you throw the item to (toPosition)

then you can do something like this
Lua:
if (math.abs(fromPosition.x - toPosition.x) >= 6 || math.abs(fromPosition.y - toPosition.y) >= 6) then
    --send x Msg
end

Edit: this is more complete code
Lua:
function onRemoveItem(item, tile, position)
    local itemPosition = item:getPosition()
    if itemPosition:getDistance(position) >= 6 then
        -- send msg
    end
    return true
end
 
Last edited:
I understand, but in my case I would like it to work only for items that are on the floor(on work with the items are in backpack for example), also two more questions, how can i declare the 2 specific target id on script? and i need this working in all tiles of map, so i need this script work in events onMoveItem? because looking here using the function onRemoveItem, i need put on specifics tiles to work.
 
I understand, but in my case I would like it to work only for items that are on the floor(on work with the items are in backpack for example), also two more questions, how can i declare the 2 specific target id on script? and i need this working in all tiles of map, so i need this script work in events onMoveItem? because looking here using the function onRemoveItem, i need put on specifics tiles to work.
Then you want to use a actionid on the tile you want this to work on, this will work for any item you remove from the tile. Unless you make a check for a special itemid in the if statement.

moveitemexample.lua
Lua:
function onRemoveItem(item, tile, position)
    local tilePosition = tile:getPosition()
    if tilePosition:getDistance(position) >= 6 then
        -- send msg
    end
    return true
end

add this inside
movements.xml
XML:
<movevent event="RemoveItem" actionid="1234" script="moveitemexample.lua" />

hopefully i got this right, im not to familiar whit tfs 1.x+
Im only guessing that position will return the new position the item is moved to

Edit:
I missed the part where you stated that you want this to work on all tiles on the map.
Do you only want this to work only whit a specific item?
 
Last edited:
Then you want to use a actionid on the tile you want this to work on, this will work for any item you remove from the tile. Unless you make a check for a special itemid in the if statement.

moveitemexample.lua
Lua:
function onRemoveItem(item, tile, position)
    local tilePosition = tile:getPosition()
    if tilePosition:getDistance(position) >= 6 then
        -- send msg
    end
    return true
end

add this inside
movements.xml
XML:
<movevent event="RemoveItem" actionid="1234" script="moveitemexample.lua" />

hopefully i got this right, im not to familiar whit tfs 1.x+
Im only guessing that position will return the new position the item is moved to

Edit:
I missed the part where you stated that you want this to work on all tiles on the map.
Do you only want this to work only whit a specific item?
not specific item, i need this work with all server items moved to main tile central with the distance of 6 sqm

maybe this need be implemented by some function on data/events/player
 
what is main tile central?
you mean there is a unique position X?
and send a message if you throw any item thats its 6sqm away from position X? or you mean main tile central as player position? can not get it
 
what is main tile central?
you mean there is a unique position X?
and send a message if you throw any item thats its 6sqm away from position X? or you mean main tile central as player position? can not get it

Hello, main tile is a central tile grey, like my imagem there,
so main tile is = 3 items id, 3120, 3590, 2390, so if the player is 6+ sqm from distance of main tile, and push any item to main tile, will receive the msg, otherwise nothing will happen
 
Back
Top