• 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.X+ Machete problem in wild growth

Solution
Change your onUseMachete function to this:
Lua:
function onUseMachete(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    if not targetId then
        return true
    end

    for _,tileItem in pairs(Tile(toPosition):getItems()) do
        if table.contains(wildGrowth, tileItem:getId()) then
            toPosition:sendMagicEffect(CONST_ME_POFF)
            tileItem:remove()
            return true
        end
    end

    local grass = jungleGrass[targetId]
    if grass then
        target:transform(grass)
        target:decay()
        player:addAchievementProgress("Nothing Can Stop Me", 100)
        return true
    end

    return destroyItem(player, target, toPosition)
end
*Not tested btw
Change your onUseMachete function to this:
Lua:
function onUseMachete(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    if not targetId then
        return true
    end

    for _,tileItem in pairs(Tile(toPosition):getItems()) do
        if table.contains(wildGrowth, tileItem:getId()) then
            toPosition:sendMagicEffect(CONST_ME_POFF)
            tileItem:remove()
            return true
        end
    end

    local grass = jungleGrass[targetId]
    if grass then
        target:transform(grass)
        target:decay()
        player:addAchievementProgress("Nothing Can Stop Me", 100)
        return true
    end

    return destroyItem(player, target, toPosition)
end
*Not tested btw
 
Solution
Change your onUseMachete function to this:
Lua:
function onUseMachete(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    if not targetId then
        return true
    end

    for _,tileItem in pairs(Tile(toPosition):getItems()) do
        if table.contains(wildGrowth, tileItem:getId()) then
            toPosition:sendMagicEffect(CONST_ME_POFF)
            tileItem:remove()
            return true
        end
    end

    local grass = jungleGrass[targetId]
    if grass then
        target:transform(grass)
        target:decay()
        player:addAchievementProgress("Nothing Can Stop Me", 100)
        return true
    end

    return destroyItem(player, target, toPosition)
end
*Not tested btw
Worked, thanks!
 
Change your onUseMachete function to this:
Lua:
function onUseMachete(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    if not targetId then
        return true
    end

    for _,tileItem in pairs(Tile(toPosition):getItems()) do
        if table.contains(wildGrowth, tileItem:getId()) then
            toPosition:sendMagicEffect(CONST_ME_POFF)
            tileItem:remove()
            return true
        end
    end

    local grass = jungleGrass[targetId]
    if grass then
        target:transform(grass)
        target:decay()
        player:addAchievementProgress("Nothing Can Stop Me", 100)
        return true
    end

    return destroyItem(player, target, toPosition)
end
*Not tested btw

I don't know exactly in what situation this occurs, but I get these errors in the distro.
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/tools/machete.lua:onUse
data/actions/lib/actions.lua:568: attempt to index a nil value
stack traceback:
    [C]: in function '__index'
    data/actions/lib/actions.lua:568: in function <data/actions/lib/actions.lua:562>

1636142626442.png
 
It should be when you use the machete somewhere that doesn't have a tile. This should fix:

Lua:
if Tile(toPosition) then
    for _,tileItem in pairs(Tile(toPosition):getItems()) do
        if table.contains(wildGrowth, tileItem:getId()) then
            toPosition:sendMagicEffect(CONST_ME_POFF)
            tileItem:remove()
            return true
        end
    end
end
 
This error has appeared now.

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/tools/machete.lua:onUse
data/actions/lib/actions.lua:550: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
    [C]: at 0x004ff7d0
    [C]: in function 'pairs'
    data/actions/lib/actions.lua:550: in function <data/actions/lib/actions.lua:543>
 
Lua:
if Tile(toPosition) and Tile(toPosition):getItems() then
    for _,tileItem in pairs(Tile(toPosition):getItems()) do
        if table.contains(wildGrowth, tileItem:getId()) then
            toPosition:sendMagicEffect(CONST_ME_POFF)
            tileItem:remove()
            return true
        end
    end
end
 
Lua:
if Tile(toPosition) and Tile(toPosition):getItems() then
    for _,tileItem in pairs(Tile(toPosition):getItems()) do
        if table.contains(wildGrowth, tileItem:getId()) then
            toPosition:sendMagicEffect(CONST_ME_POFF)
            tileItem:remove()
            return true
        end
    end
end
I will try that! Thanks!
 
Back
Top