• 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 0.X I need a script that transforms an item into another item

Enderlop

Banned User
Joined
Jan 10, 2024
Messages
93
Reaction score
16
I need a script that transforms an item into another item alone


type that Untitled Project123.gifUntitled Project123.gif
 
Last edited:
Solution
The script I gave you is startup, logically it will not work like onthink, and there is no problem using it that way, as addevent does the job. the problem there is doCreateItem, it has to be doTransformItem.


here is your dream AI generated onthink, good luck
Lua:
local config = {
    itemIds = {2445, 2550, 2436, 6101, 2408, 7435, 7429},
    position = {x = 151, y = 55, z = 7}
}

local currentIndex = 1

function onThink(interval)
    local tile = getThingfromPos(config.position)
    local item = nil
    for _, id in ipairs(config.itemIds) do
        item = getTileItemById(config.position, id)
        if item.uid ~= 0 then
            doTransformItem(item.uid, config.itemIds[currentIndex])
            doSendMagicEffect(config.position...
create script for me item id only 2445-2550-2436-6101-2408-7435-7429

no function @highsanta

Lua:
local config = {
    itemid = {2445, 2550, 2436, 6101, 2408, 7435, 7429}, -- IDs of the items to be transformed
    position = {x = 151, y = 55, z = 7} -- Coordinates of the items to be transformed
}

function changeItemsToMagicGreenEffect()
    for _, itemId in ipairs(config.itemid) do
        local item = getTileItemById(config.position, itemId)
        if item then
            doSendMagicEffect(config.position, CONST_ME_MAGIC_GREEN)
        end
    end
end

function onStartup()
    changeItemsToMagicGreenEffect()
    addEvent(changeItemsToMagicGreenEffect, 5000) -- 5000 milliseconds = 5 seconds
    return true
end
 
Last edited:
help I want it to look like the gif

Lua:
local config = {
    itemid = {2445, 2550, 2436, 6101, 2408, 7435, 7429},
    position = {x = 156, y = 58, z = 7},
    tempo_criacao = 3
}

function changeItemToMagicGreenEffect()
    local posX, posY, posZ = config.position.x, config.position.y, config.position.z
    local itemId = config.itemid[math.random(1, #config.itemid)]
   
    -- Criar novo item com o efeito CONST_ME_MAGIC_GREEN
    local newItem = doCreateItem(itemId, 1, {x = posX, y = posY, z = posZ})
    if newItem then
        doSendMagicEffect({x = posX, y = posY, z = posZ}, CONST_ME_MAGIC_GREEN)
       
        -- Agendar remoção do novo item após 3 segundos
        addEvent(function()
            doRemoveItem(newItem)
            changeItemToMagicGreenEffect() -- Criar outro item após remoção
        end, config.tempo_criacao * 1000) -- Tempo em milissegundos para remoção do item
    end
end

function onThink(interval)
    addEvent(changeItemToMagicGreenEffect, config.tempo_criacao * 1000)
    return true
end
 
Last edited:
create script for me item id only 2445-2550-2436-6101-2408-7435-7429

no function @highsanta

Lua:
local config = {
    itemid = {2445, 2550, 2436, 6101, 2408, 7435, 7429}, -- IDs of the items to be transformed
    position = {x = 151, y = 55, z = 7} -- Coordinates of the items to be transformed
}

function changeItemsToMagicGreenEffect()
    for _, itemId in ipairs(config.itemid) do
        local item = getTileItemById(config.position, itemId)
        if item then
            doSendMagicEffect(config.position, CONST_ME_MAGIC_GREEN)
        end
    end
end

function onStartup()
    changeItemsToMagicGreenEffect()
    addEvent(changeItemsToMagicGreenEffect, 5000) -- 5000 milliseconds = 5 seconds
    return true
end
When you start your server, the script change the item then stop?


Try this onStartUp, make sure to add the item 2445 in the correct position in mapeditor, then register the script in your globalevents folder as startup..
Lua:
local config = {
    itemIds = {2445, 2550, 2436, 6101, 2408, 7435, 7429},
    position = {x = 151, y = 55, z = 7},
    changeInterval = 3000 -- Interval in milliseconds
}

local currentIndex = 1

local function changeItem()
    local tile = getThingfromPos(config.position)
    local item = nil
    for _, id in ipairs(config.itemIds) do
        item = getTileItemById(config.position, id)
        if item.uid ~= 0 then
            break
        end
    end

    if item and item.uid ~= 0 then
        doRemoveItem(item.uid)
        currentIndex = currentIndex % #config.itemIds + 1
        local nextItemId = config.itemIds[currentIndex]
        doCreateItem(nextItemId, 1, config.position)
        doSendMagicEffect(config.position, CONST_ME_MAGIC_GREEN)
    end
    addEvent(changeItem, config.changeInterval) -- restart the change
end

function onStartup()
    changeItem()
    addEvent(changeItem, config.changeInterval) -- start the change
    return true
end
 
Last edited:
@mano368 no function

XML:
[29/03/2024 08:04:52] [Error - GlobalEvent Interface]
[29/03/2024 08:04:52] data/globalevents/scripts/item.lua:onStartup
[29/03/2024 08:04:53] Description:
[29/03/2024 08:04:53] data/globalevents/scripts/item.lua:30: attempt to call global 'changeItemsToMagicGreenEffect' (a nil value)
[29/03/2024 08:04:53] stack traceback:
[29/03/2024 08:04:54]     data/globalevents/scripts/item.lua:30: in function <data/globalevents/scripts/item.lua:29>
 
Last edited:
@mano368 no function

XML:
[29/03/2024 08:04:52] [Error - GlobalEvent Interface]
[29/03/2024 08:04:52] data/globalevents/scripts/item.lua:onStartup
[29/03/2024 08:04:53] Description:
[29/03/2024 08:04:53] data/globalevents/scripts/item.lua:30: attempt to call global 'changeItemsToMagicGreenEffect' (a nil value)
[29/03/2024 08:04:53] stack traceback:
[29/03/2024 08:04:54]     data/globalevents/scripts/item.lua:30: in function <data/globalevents/scripts/item.lua:29>
sorry, copy the script again, I made a mistake when inserting the function name
 
does not exchange items for another with CONST_ME_MAGIC_GREEN effect and with id 8047 on top of the item so no one takes it when exchanging item randomly test script
Lua:
local config = {
    itemIds = {2445, 2550, 2436, 6101, 2408, 7435, 7429},
    position = {x = 151, y = 55, z = 7},
    changeInterval = 3000 -- Interval in milliseconds
}

local currentIndex = 1

local function changeItem()
    local tile = getThingfromPos(config.position)
    local item = nil
    for _, id in ipairs(config.itemIds) do
        item = getTileItemById(config.position, id)
        if item.uid ~= 0 then
            break
        end
    end

    if item and item.uid ~= 0 then
        doRemoveItem(item.uid)
        currentIndex = currentIndex % #config.itemIds + 1
        local nextItemId = config.itemIds[currentIndex]
        doCreateItem(nextItemId, 1, config.position)
        doSendMagicEffect(config.position, CONST_ME_MAGIC_GREEN)
    end
    addEvent(changeItem, config.changeInterval) -- restart the change
end

function onStartup()
    changeItem()
    addEvent(changeItem, config.changeInterval) -- start the change
    return true
end

only get it via onThink

Untitled Project123.gif

Lua:
[29/03/2024 09:09:06] [Error - GlobalEvent Interface]
[29/03/2024 09:09:06] data/globalevents/scripts/item.lua:onThink
[29/03/2024 09:09:06] Description:
[29/03/2024 09:09:07] (luaAddEvent) Callback parameter should be a function.
 
Last edited:
The script I gave you is startup, logically it will not work like onthink, and there is no problem using it that way, as addevent does the job. the problem there is doCreateItem, it has to be doTransformItem.


here is your dream AI generated onthink, good luck
Lua:
local config = {
    itemIds = {2445, 2550, 2436, 6101, 2408, 7435, 7429},
    position = {x = 151, y = 55, z = 7}
}

local currentIndex = 1

function onThink(interval)
    local tile = getThingfromPos(config.position)
    local item = nil
    for _, id in ipairs(config.itemIds) do
        item = getTileItemById(config.position, id)
        if item.uid ~= 0 then
            doTransformItem(item.uid, config.itemIds[currentIndex])
            doSendMagicEffect(config.position, CONST_ME_MAGIC_GREEN)
            currentIndex = (currentIndex % #config.itemIds) + 1
            break
        end
    end
    return true
end
 
Last edited:
Solution
XML:
[29/03/2024 09:11:02] [Error - GlobalEvent Interface]
[29/03/2024 09:11:02] data/globalevents/scripts/item.lua:onThink
[29/03/2024 09:11:02] Description:
[29/03/2024 09:11:02] (luaAddEvent) Callback parameter should be a function.
 
XML:
[29/03/2024 09:11:02] [Error - GlobalEvent Interface]
[29/03/2024 09:11:02] data/globalevents/scripts/item.lua:onThink
[29/03/2024 09:11:02] Description:
[29/03/2024 09:11:02] (luaAddEvent) Callback parameter should be a function.
just clean your item.lua script and change for what I give to you, don't mix scripts

Edited: removed cid from script
 
Last edited:
Back
Top