• 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!

How to callback a position for addEvent? Lumberjacking example.

oserc

Advanced OT User
Joined
Mar 5, 2022
Messages
148
Solutions
1
Reaction score
196
Location
Brazil
Hey boys and girls, how you all doing?

I'm working on a lumberjacking system, which works as follow: when you a lumberjacking axe (new custom item on my server) on a fir tree, you obtain some woods from it. For game aesthetics, when the player right click the axe and then the fir tree, he gets frozen for a few secs, and then he gives 3 hits on the tree, with 3 magic effects running over the fir tree (POFFS). The wood is added to his backpack at the final hit (second event). I'm workin with AddEvents, but I can't get the events to call back the tree position, in order to send the magic effec at the same position.

Anny suggestions to make this work?

BTW, I'm using TFS 1.4.1.



Script below:

Lua:
function chop1(player, item, fromPosition, target, toPosition, isHotkey)
    for _, player in ipairs(Game.getPlayers()) do
    player:say("Chop!", TALKTYPE_MONSTER_SAY)
    tree:sendMagicEffect(CONST_ME_POFF)
    addEvent(chop2, 2500, tree)
end
return true
end

function chop2(player, item, fromPosition, target, toPosition, isHotkey)
    for _, player in ipairs(Game.getPlayers()) do
    player:say("Chop!", TALKTYPE_MONSTER_SAY)
    tree:sendMagicEffect(CONST_ME_POFF)
    player:addItem(5901, 1)
    player:sendCancelMessage("You were able to chop some wood.")
    player:setMovementBlocked(false)
    player:setStorageValue(lumberjacking, 0)
end
return true
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if getTileItemById(toPosition, 2700).uid > 0 then
    if player:getStorageValue(lumberjacking) == 0 then
    player:setStorageValue(lumberjacking, 1)
    player:setMovementBlocked(true)
    player:say("Chop!", TALKTYPE_MONSTER_SAY)
    local tree = target:getPosition()
    tree:sendMagicEffect(CONST_ME_POFF)
    addEvent(chop1, 2500, tree)
    player:addSkillTries(SKILL_LUMBERJACKING, 1)
    else
    player:sendCancelMessage("Your hands are already busy.")
end
return true
end
end
 
Last edited by a moderator:
Solution
Hey boys and girls, how you all doing?

I'm working on a lumberjacking system, which works as follow: when you a lumberjacking axe (new custom item on my server) on a fir tree, you obtain some woods from it. For game aesthetics, when the player right click the axe and then the fir tree, he gets frozen for a few secs, and then he gives 3 hits on the tree, with 3 magic effects running over the fir tree (POFFS). The wood is added to his backpack at the final hit (second event). I'm workin with AddEvents, but I can't get the events to call back the tree position, in order to send the magic effec at the same position.

Anny suggestions to make this work?

BTW, I'm using TFS 1.4.1.



Script below:

Lua:
function chop1(player, item...
Hey boys and girls, how you all doing?

I'm working on a lumberjacking system, which works as follow: when you a lumberjacking axe (new custom item on my server) on a fir tree, you obtain some woods from it. For game aesthetics, when the player right click the axe and then the fir tree, he gets frozen for a few secs, and then he gives 3 hits on the tree, with 3 magic effects running over the fir tree (POFFS). The wood is added to his backpack at the final hit (second event). I'm workin with AddEvents, but I can't get the events to call back the tree position, in order to send the magic effec at the same position.

Anny suggestions to make this work?

BTW, I'm using TFS 1.4.1.



Script below:

Lua:
function chop1(player, item, fromPosition, target, toPosition, isHotkey)
    for _, player in ipairs(Game.getPlayers()) do
    player:say("Chop!", TALKTYPE_MONSTER_SAY)
    tree:sendMagicEffect(CONST_ME_POFF)
    addEvent(chop2, 2500, tree)
end
return true
end

function chop2(player, item, fromPosition, target, toPosition, isHotkey)
    for _, player in ipairs(Game.getPlayers()) do
    player:say("Chop!", TALKTYPE_MONSTER_SAY)
    tree:sendMagicEffect(CONST_ME_POFF)
    player:addItem(5901, 1)
    player:sendCancelMessage("You were able to chop some wood.")
    player:setMovementBlocked(false)
    player:setStorageValue(lumberjacking, 0)
end
return true
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if getTileItemById(toPosition, 2700).uid > 0 then
    if player:getStorageValue(lumberjacking) == 0 then
    player:setStorageValue(lumberjacking, 1)
    player:setMovementBlocked(true)
    player:say("Chop!", TALKTYPE_MONSTER_SAY)
    local tree = target:getPosition()
    tree:sendMagicEffect(CONST_ME_POFF)
    addEvent(chop1, 2500, tree)
    player:addSkillTries(SKILL_LUMBERJACKING, 1)
    else
    player:sendCancelMessage("Your hands are already busy.")
end
return true
end
end

There is quite a few things wrong, and I'm not sure how to explain all of them.

Soo, I just altered the code to work as intended.

Hopefully you can read it and learn

Lua:
local function chop(playerId, treePosition, chopStatus)
    local player = Player(playerId)
    if not player then
        return
    end
    chopStatus = chopStatus + 1
    if chopStatus == 0 then
        player:setStorageValue(lumberjacking, 1)
        player:setMovementBlocked(true)
        player:addSkillTries(SKILL_LUMBERJACKING, 1)
        player:say("Chop!", TALKTYPE_MONSTER_SAY)
        treePosition:sendMagicEffect(CONST_ME_POFF)
        addEvent(chop, 2500, playerId, treePosition, chopStatus)
    elseif chopStatus == 1 then
        player:say("Chop!", TALKTYPE_MONSTER_SAY)
        treePosition:sendMagicEffect(CONST_ME_POFF)
        addEvent(chop, 2500, playerId, treePosition, chopStatus)
    else
        player:say("Chop!", TALKTYPE_MONSTER_SAY)
        treePosition:sendMagicEffect(CONST_ME_POFF)
        player:addItem(5901, 1)
        player:sendCancelMessage("You were able to chop some wood.")
        player:setMovementBlocked(false)
        player:setStorageValue(lumberjacking, 0)
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
    if tile then
        if tile:getItemCountById(2700) > 0 then
            if player:getStorageValue(lumberjacking) == 0 then
                chop(player:getId(), toPosition, -1) -- chop(playerId, treePosition, chopStatus)
            else
                player:sendCancelMessage("Your hands are already busy.")
            end
        end
    end
    return true
end
 
Last edited:
Solution
Back
Top