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

Lua Useitem and change item with time

hyz

Member
Joined
Oct 30, 2008
Messages
39
Reaction score
16
I need a script that when using XXX1 on another item XXX2 it will change into another item XXX3 for 30 minutes, and then it will change into XXX2 and the player will be able to use it again.

I took the fishing rod script to try to edit it and I managed to do it, I reduced it until I got to that point but it gave a bug.
I can make him send me the item and remove the used item, but I am not able to do the time action
-


Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if targetId == 2722 then
player:addItem(2667, 1)
target:transform(2720)
target:decay()
player:addItem(13139, 25)
toPosition:sendMagicEffect(32)
player:addSkillTries(SKILL_FISHING, 1)
    end
    return true
end
 
I need a script that when using XXX1 on another item XXX2 it will change into another item XXX3 for 30 minutes, and then it will change into XXX2 and the player will be able to use it again.

I took the fishing rod script to try to edit it and I managed to do it, I reduced it until I got to that point but it gave a bug.
I can make him send me the item and remove the used item, but I am not able to do the time action
-


Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if targetId == 2722 then
player:addItem(2667, 1)
target:transform(2720)
target:decay()
player:addItem(13139, 25)
toPosition:sendMagicEffect(32)
player:addSkillTries(SKILL_FISHING, 1)
    end
    return true
end

If the item can be moved..
You would want to edit items.xml for the transformed item, to decay into the previous item.
This would take care of the 'timer'.

In your case however, it appears you are changing a tree, which is not moveable, so we'd want to do something a bit different.

Something like this, should work
Lua:
local targetItemId = 2722
local transformedItemId = 2720
local transformTimer = 30 -- seconds

local function resetTransform(position, itemReturnId, itemToBeReturnedId)
    local tile = Tile(position)
    if not tile then
        return
    end
    local target = tile:getItemById(itemToBeReturnedId)
    if target then
        target:transform(itemReturnId)
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:getId() == targetItemId then
        local transformedItem = target:transform(transformedItemId)
        local position = transformedItem:getPosition()
        addEvent(resetTransform, 1000 * transformTimer, position, targetItemId, transformedItemId)
        
        player:addItem(13139, 25)
        player:addSkillTries(SKILL_FISHING, 1)
        position:sendMagicEffect(CONST_ME_STUN)
    end
    return true
end
 
Xikini, I managed to solve the timer issue in items.xml, thanks a lot friend!
In relation to the tree, it has the ID of the tree because I am customizing my server, and the item in question will not be able to move anyway.

Thanks a lot for the help!
 
Back
Top