• 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+ transform item on position transforms top item

Itutorial

Excellent OT User
Joined
Dec 23, 2014
Messages
2,307
Solutions
68
Reaction score
981
For some reason I tell the code which item on the tile should be transformed but it still targets the top item on the tile. Is there something I am forgetting?

Lua:
local trees = {
    [2768] = {chance = 5, level = 0, logs = 2148, respawn = 5, skillTries = 25},
    [5376] = {chance = 5, level = 0, logs = 2148, respawn = 5, skillTries = 25},
    [8313] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2708] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2707] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2705] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2703] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2702] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2701] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2700] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2711] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2712] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2700] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
    [2700] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50}
}

local chopped = {8785, 8788, 8786}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
   
    if not tile then return false end
   
    local TREECHECK = nil
   
    for i, v in pairs(trees) do
        local foundTree = tile:getItemById(i)
        if foundTree then
            TREECHECK = tile:getItemById(i)
            break
        end
    end
   
    if not TREECHECK then return false end
   
    local TREE = trees[TREECHECK.itemid]
   
    if not TREE then return false end
   
    local skill = player:getSkillLevel(SKILL_WOODCUTTING) + 1
   
    if math.random(TREE.chance) <= skill then
        local treeId = TREECHECK.itemid
        TREECHECK:transform(chopped[math.random(#chopped)])
        local stumpId = TREECHECK.itemid
        player:addItem(TREE.logs, 1)
        toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
        player:addSkillTries(SKILL_WOODCUTTING, TREE.skillTries * 2)
        addEvent(replaceTree, TREE.respawn * 1000, treeId, stumpId, toPosition)
    else
        toPosition:sendMagicEffect(CONST_ME_POFF)
        player:addSkillTries(SKILL_WOODCUTTING, 10)
    end
    return true
end

function replaceTree(treeId, stumpId, position)
    local target = Tile(position):getItemById(stumpId)
   
    if not target then return true end

    target:transform(treeId)
    return true
end

*NOTE: Its transforming the sign. Not the bush.
 

Attachments

Solution
I can't be sure as I'm unable to test right now but it looks like you have the "grape sign" in your list of potential chopping candidates

Lua:
[5376] = {chance = 5, level = 0, logs = 2148, respawn = 5, skillTries = 25}

I think you should probably change 5376 to 2767.
I can't be sure as I'm unable to test right now but it looks like you have the "grape sign" in your list of potential chopping candidates

Lua:
[5376] = {chance = 5, level = 0, logs = 2148, respawn = 5, skillTries = 25}

I think you should probably change 5376 to 2767.
 
Solution
Back
Top