# LuaTFS 1.3 use item x id and change floor in a few minutes

#### Icaraii

##### Active Member
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...``````

#### Xikini

##### I whore myself out for likes
Senator
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()``````

OP
OP
I

#### Icaraii

##### Active Member
It work's perfectly, thanks @Xikini

#### Levi999x

##### AoT
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

OP
OP
I

#### Icaraii

##### Active Member
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()``````

OP
OP
I

#### Icaraii

##### Active Member
I didn't manage to make it work, can somebody help me?

#### Xikini

##### I whore myself out for likes
Senator
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.

• Icaraii
OP
OP
I

#### Icaraii

##### Active Member
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)

#### Xikini

##### I whore myself out for likes
Senator
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.

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

• Icaraii
OP
OP
I

#### Icaraii

##### Active Member
Yes.

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()``````

#### Xikini

##### I whore myself out for likes
Senator
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 = {
 = {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
end
end
return true
end

for itemId, _ in pairs(config) do
groundConverter:id(itemId)
end
groundConverter:register()``````

• Icaraii
OP
OP
I

#### Icaraii

##### Active Member
Lua:
``````local config = {
 = {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
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

Replies
8
Views
402
Replies
4
Views
250
Replies
4
Views
421
Replies
0
Views
61
{"ft_lang_label":"__label__en","ft_lang_prob":0.93593454,"math_prob":0.8265405,"size":626,"snap":"2022-27-2022-33","text_gpt3_token_len":149,"char_repetition_ratio":0.1414791,"word_repetition_ratio":0.9516129,"special_character_ratio":0.23961662,"punctuation_ratio":0.062937066,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9772593,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-12T16:20:21Z\",\"WARC-Record-ID\":\"<urn:uuid:a6af13fa-daa6-4933-8c52-2e3b2a804a62>\",\"Content-Length\":\"156502\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4a9def20-f934-4d4c-a9dc-3050f05b7af6>\",\"WARC-Concurrent-To\":\"<urn:uuid:bbdb90d9-012c-4579-9c3b-85aba8b18c96>\",\"WARC-IP-Address\":\"104.21.51.77\",\"WARC-Target-URI\":\"https://otland.net/threads/tfs-1-3-use-item-x-id-and-change-floor-in-a-few-minutes.281873/#post-2701870\",\"WARC-Payload-Digest\":\"sha1:7J2IOF3XPIJFFIXXTDI6ZXK5O7SPRUWK\",\"WARC-Block-Digest\":\"sha1:H6RJKOP53XZIWKFYPIQVS3N7NH42MPCY\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882571719.48_warc_CC-MAIN-20220812140019-20220812170019-00220.warc.gz\"}"}