• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

transforming an item and then addEvent transforming it back...

PhoebeG

New Member
Joined
Aug 29, 2017
Messages
5
Reaction score
1
LUA:
function onUseAccessKey(player, item, fromPosition, target, toPosition, isHotkey)
   local WATER = {4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4626, 4627, 4628, 4629, 4630, 4631}
   local targetId, targetActionId = target.itemid, target.actionid
   if isInArray(WATER, targetId) then
       target:transform(671)
       addEvent(target:transform(targetId)
       end, 3000, targetId:getPosition(), onUseAccessKey(toPosition):getItemById(671))
    else
       return false
    end
    return true
end

I for the life of me can not understand why this will not work...
I intend to use an item on only the water tiles in the table.
The water tile should turn to ice 671.
3 seconds later it should turn back to the same type of water tile.
(i could simply turn it back to a specfic water tile with decay but i may wish to use this item to change any item into another temporarily, and have it change back.. that's my theory anyways!)
Please.. any assistance would be lovely.
 
Last edited by a moderator:
1. You should say your project version (TFS 1.2, 1.3, etc).
2. Is not "onUseAccessKey", it's "onUse".
3. You forgot to show what did you put on actions.xml file for make this works.
 
right my bad! tfs 1.2
I copied shovel.lua from actions>tools to make a lunar staff able to work like a shovel at first, then i am putting this script as a new function in actions.lua...sorry if it's roundabout but it's my first attempt with lua.
<action itemid="7424" script="tools/accesskey.lua" />

LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   return onUseAccessKey(player, item, fromPosition, target, toPosition, isHotkey)
end

that is what is in the actions>tools folder as accesskey.lua

Now.. i've been able to get the following to do what i want by using items.xml to decay ice into a specific water:
LUA:
function onUseAccessKey(player, item, fromPosition, target, toPosition, isHotkey)
   local targetId, targetActionId = target.itemid, target.actionid
   if isInArray(WATER, targetId) then
       target:transform(671)
       target:decay()
   else toPosition:sendMagicEffect(CONST_ME_POFF)
   end
end
but well.. is that all the needed information now? sorry i'm mostly a disaster..
 
LUA:
local config = {
    items = {
        [4608] = {toId = 671, delay = 3000},
        [4609] = {toId = 671, delay = 3000},
    }
}

local function transformBack(pos, fromId, toId)
    local item = Tile(pos):getItemById(fromId)
    if item then
        return item:transform(toId)
    end
    return false
end

function onUseAccessKey(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId, targetActionId = target.itemid, target.actionid
    local itemConfig = config.items[targetId]
    if itemConfig then
        target:transform(itemConfig.toId)
        addEvent(transformBack, itemConfig.delay, toPosition, itemConfig.toId, targetId)
        return true
    else
        return toPosition:sendMagicEffect(CONST_ME_POFF)
    end
    return true
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    return onUseAccessKey(player, item, fromPosition, target, toPosition, isHotkey)
end
 
why are you insisting on not using onUse as your main function and instead using onUse as a macro to call your own function?
that's just another useless step to do when you have onUse
 
oh not insisting! just how i had it before! totally open to however it has to be to get it to work i promise :)

okay from a fresh actions folder from the original 1.2 tfs i puts the following into accesskey.lua within actions>tools
LUA:
local config = {
    items = {
        [4608] = {toId = 671, delay = 3000},
        [4609] = {toId = 671, delay = 3000},
        [4610] = {toId = 671, delay = 3000},
        [4611] = {toId = 671, delay = 3000},
        [4612] = {toId = 671, delay = 3000},
        [4613] = {toId = 671, delay = 3000},
        [4614] = {toId = 671, delay = 3000},
        [4615] = {toId = 671, delay = 3000},
       [4616] = {toId = 671, delay = 3000},
       [4617] = {toId = 671, delay = 3000},
        [4618] = {toId = 671, delay = 3000},
        [4619] = {toId = 671, delay = 3000},
        [4620] = {toId = 671, delay = 3000},
        [4621] = {toId = 671, delay = 3000},
        [4622] = {toId = 671, delay = 3000},
        [4623] = {toId = 671, delay = 3000},
        [4624] = {toId = 671, delay = 3000},
        [4625] = {toId = 671, delay = 3000},
       [4626] = {toId = 671, delay = 3000},
       [4627] = {toId = 671, delay = 3000},
        [4628] = {toId = 671, delay = 3000},
        [4629] = {toId = 671, delay = 3000},
       [4630] = {toId = 671, delay = 3000},
       [4631] = {toId = 671, delay = 3000},


    }
}
local function transformBack(pos, fromId, toId)
    local item = Tile(pos):getItemById(fromId)
    if item then
        return item:transform(toId)
    end
    return false
end
function onUseAccessKey(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId, targetActionId = target.itemid, target.actionid
    local itemConfig = config.items[targetId]
    if itemConfig then
        target:transform(itemConfig.toId)
        addEvent(transformBack, itemConfig.delay, toPosition, itemConfig.toId, targetId)
        return true
    else
        return toPosition:sendMagicEffect(CONST_ME_POFF)
    end
    return true
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    return onUseAccessKey(player, item, fromPosition, target, toPosition, isHotkey)
end
the actions.xml
<action itemid="7424" script="tools/accesskey.lua" />
but this isn't working. just to double check that i didn't break anything i tried exactly what you posted also but that didn't work, then i noticed that in the code you gave there SEEMED to be an extra comma on the second entry in the table of water values. so i tried deleting that one comma but still no dice. any other ideas?

I redact my statement after seemingly waiting 5 minutes and reloading a second time it's working just how i wished! thanks for all the help guys,
Frija especially~!!
 
Last edited by a moderator:
I redact my statement after seemingly waiting 5 minutes and reloading a second time it's working just how i wished! thanks for all the help guys,
Frija especially~!!

LUA:
local items = {
    [4608] = {toId = 671, delay = 3000},
    [4609] = {toId = 671, delay = 3000},
    [4610] = {toId = 671, delay = 3000},
    [4611] = {toId = 671, delay = 3000},
    [4612] = {toId = 671, delay = 3000},
    [4613] = {toId = 671, delay = 3000},
    [4614] = {toId = 671, delay = 3000},
    [4615] = {toId = 671, delay = 3000},
    [4616] = {toId = 671, delay = 3000},
    [4617] = {toId = 671, delay = 3000},
    [4618] = {toId = 671, delay = 3000},
    [4619] = {toId = 671, delay = 3000},
    [4620] = {toId = 671, delay = 3000},
    [4621] = {toId = 671, delay = 3000},
    [4622] = {toId = 671, delay = 3000},
    [4623] = {toId = 671, delay = 3000},
    [4624] = {toId = 671, delay = 3000},
    [4625] = {toId = 671, delay = 3000},
    [4626] = {toId = 671, delay = 3000},
    [4627] = {toId = 671, delay = 3000},
    [4628] = {toId = 671, delay = 3000},
    [4629] = {toId = 671, delay = 3000},
    [4630] = {toId = 671, delay = 3000},
    [4631] = {toId = 671, delay = 3000}
}

local function transformBack(pos, fromId, toId)
    local item = Tile(pos):getItemById(fromId)
    if item then
        return item:transform(toId)
    end
    return false
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetId = target.itemid
    local itemConfig = items[targetId]
    if itemConfig then
        target:transform(itemConfig.toId)
        addEvent(transformBack, itemConfig.delay, toPosition, itemConfig.toId, targetId)
    else
        toPosition:sendMagicEffect(CONST_ME_POFF)
    end
    return true
end
 
Back
Top