• 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 1.3 use item x id and change floor in a few minutes

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hi guys,

I'm looking for a script where the player uses a item x id on a y id floor and after a few minutes it would change to floor id z. Can somebody help me out?
For example, the player would use shovel(item x id) on the desert floor(y id floor) and after a few minutes the floor would change to grass(floor id z).
 
Solution
like this:

Lua:
local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() and target:getId() == 351 then -- 1111 is the itemId of the ground you want to convert
         if math.random(100) <= 25 then
         doRemoveItem(item.uid, 1)
        addEvent(convertGround, 100, target:getPosition(), 351, 806) -- 806 is the itemId of the ground to...
This works exactly as your description.
Many problems with the idea itself, but you'll figure those out quickly, I imagine.
Lua:
local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() and target:getId() == 1111 then -- 1111 is the itemId of the ground you want to convert
        addEvent(convertGround, 5000, target:getPosition(), 1111, 2222) -- 2222 is the itemId of the ground to convert into
    end
    return true
end

groundConverter:id(33333) -- item you want to use on the tile
groundConverter:register()
 
This works exactly as your description.
Many problems with the idea itself, but you'll figure those out quickly, I imagine.
Lua:
local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() and target:getId() == 1111 then -- 1111 is the itemId of the ground you want to convert
        addEvent(convertGround, 5000, target:getPosition(), 1111, 2222) -- 2222 is the itemId of the ground to convert into
    end
    return true
end

groundConverter:id(33333) -- item you want to use on the tile
groundConverter:register()
the g.o.a.t
 
This works exactly as your description.
Many problems with the idea itself, but you'll figure those out quickly, I imagine.
Lua:
local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() and target:getId() == 1111 then -- 1111 is the itemId of the ground you want to convert
        addEvent(convertGround, 5000, target:getPosition(), 1111, 2222) -- 2222 is the itemId of the ground to convert into
    end
    return true
end

groundConverter:id(33333) -- item you want to use on the tile
groundConverter:register()
If I would like to implement for the item to desapear with a certain chance would be like this?

Lua:
local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
                 if math.random(100) <= 25 then
                doRemoveItem(item.uid, 1)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() and target:getId() == 351 then -- 1111 is the itemId of the ground you want to convert
        addEvent(convertGround, 100, target:getPosition(), 351, 806) -- 806 is the itemId of the ground to convert into
    end
    return true
end

groundConverter:id(2552) -- item you want to use on the tile
groundConverter:register()
 
If I would like to implement for the item to desapear with a certain chance would be like this?

Lua:
local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
                 if math.random(100) <= 25 then
                doRemoveItem(item.uid, 1)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() and target:getId() == 351 then -- 1111 is the itemId of the ground you want to convert
        addEvent(convertGround, 100, target:getPosition(), 351, 806) -- 806 is the itemId of the ground to convert into
    end
    return true
end

groundConverter:id(2552) -- item you want to use on the tile
groundConverter:register()

There is no way to send the item data to the addEvent to be removed later, unless there is an accurate way to 'find' the item again.
There's no way to guarantee that the player will be online to check their inventory.
Even if we force the player to be online, there's no way to guarantee the item is in their inventory when we check for it later. (They could drop it, trade it, store it in another container.. et cetera)
We could maybe force all of these combinations by actively restricting the player into doing literally nothing.. but that takes away control of their entire character while waiting for the ground to convert. (and technically doesn't stop other players from interfering, like killing the player, for example)

So.. no. There is no (good or easy) way to remove the item when the ground is transformed at a later time.
 
There is no way to send the item data to the addEvent to be removed later, unless there is an accurate way to 'find' the item again.
There's no way to guarantee that the player will be online to check their inventory.
Even if we force the player to be online, there's no way to guarantee the item is in their inventory when we check for it later. (They could drop it, trade it, store it in another container.. et cetera)
We could maybe force all of these combinations by actively restricting the player into doing literally nothing.. but that takes away control of their entire character while waiting for the ground to convert. (and technically doesn't stop other players from interfering, like killing the player, for example)

So.. no. There is no (good or easy) way to remove the item when the ground is transformed at a later time.
But can we remove the item when the player uses it? I mean before the player set it on the floor. Like for example, the player uses the item and it break (disappear)
 
But can we remove the item when the player uses it? I mean before the player set it on the floor. Like for example, the player uses the item and it break (disappear)
Yes.

Move your added code into the main onUse function. (before addEvent, and after if statement)

and you should use the proper tfs 1.x function instead of compat. item:remove(1)
 
Yes.

Move your added code into the main onUse function. (before addEvent, and after if statement)

and you should use the proper tfs 1.x function instead of compat. item:remove(1)

like this:

Lua:
local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() and target:getId() == 351 then -- 1111 is the itemId of the ground you want to convert
         if math.random(100) <= 25 then
         doRemoveItem(item.uid, 1)
        addEvent(convertGround, 100, target:getPosition(), 351, 806) -- 806 is the itemId of the ground to convert into
    end
    return true
end

groundConverter:id(2552) -- item you want to use on the tile
groundConverter:register()
 
like this:

Lua:
local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() and target:getId() == 351 then -- 1111 is the itemId of the ground you want to convert
         if math.random(100) <= 25 then
         doRemoveItem(item.uid, 1)
        addEvent(convertGround, 100, target:getPosition(), 351, 806) -- 806 is the itemId of the ground to convert into
    end
    return true
end

groundConverter:id(2552) -- item you want to use on the tile
groundConverter:register()
Lua:
local config = {
    [2552] = {targetId = 351, transformId = 806, chanceToRemoveItem = 25, groundConvertTimerInMilliseconds = 100},
}

local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() then
        local index = config[item:getId()]
        if target:getId() == index.targetId then
            if math.random(100) <= index.chanceToRemoveItem then
                item:remove(1)
            end
            addEvent(convertGround, index.groundConvertTimerInMilliseconds, target:getPosition(), index.targetId, index.transformId)
        end
    end
    return true
end

for itemId, _ in pairs(config) do
    groundConverter:id(itemId)
end
groundConverter:register()
 
Solution
Lua:
local config = {
    [2552] = {targetId = 351, transformId = 806, chanceToRemoveItem = 25, groundConvertTimerInMilliseconds = 100},
}

local function convertGround(position, targetTileId, newTileId)
    local tile = Tile(position)
    if tile then
        local ground = tile:getGround()
        if ground then
            if ground:getId() == targetTileId then
                ground:transform(newTileId)
            end
        end
    end
end

local groundConverter = Action()

function groundConverter.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:isItem() then
        local index = config[item:getId()]
        if target:getId() == index.targetId then
            if math.random(100) <= index.chanceToRemoveItem then
                item:remove(1)
            end
            addEvent(convertGround, index.groundConvertTimerInMilliseconds, target:getPosition(), index.targetId, index.transformId)
        end
    end
    return true
end

for itemId, _ in pairs(config) do
    groundConverter:id(itemId)
end
groundConverter:register()
Thank you @Xikini , like always you are a Jedi
 
Back
Top