• 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 Action that changes target item.

Udun

Well-Known Member
Joined
Jan 5, 2012
Messages
193
Solutions
1
Reaction score
67
Heey guys! I've been searching for an action like this, without luck.
I'm using TFS 1.4.
Is for a crafting system, the action should do this:
When I trow 15 coal to an "empty" oven item the sprite changes to a "full" with coal oven item.
I don't know if is possible with a static-non moveable/non-pass trough item or it has to be with an item that allows place items above, in that case I can modified it.
But the item id must change to a new one to make the effect. Of course the 15 coal must be removed from the char inventory.

-To notice after fill the oven with coal I lit it with a firebug, same mechaing of machete/avage, and then decays to an empty oven again (I did this part of the script already)

Thanks alot in advance!
 
Here is an example of how to do it, using the onItemMoved event
Lua:
local coalId = 1260
local coalAmount = 15

local ovenIdOff = 1780
local ovenIdOn = 1781

local event = EventCallback

function event.onItemMoved(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if item:getId() == coalId and item:getCount() >= coalAmount then
        local tile = Tile(toPosition)
        if tile then
            local oven = tile:getItemById(ovenIdOff)
            if oven then
                oven:transform(ovenIdOn)
                item:remove(coalAmount)
            end
        end
    end
end

event:register()
 
Here is an example of how to do it, using the onItemMoved event
Lua:
local coalId = 1260
local coalAmount = 15

local ovenIdOff = 1780
local ovenIdOn = 1781

local event = EventCallback

function event.onItemMoved(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if item:getId() == coalId and item:getCount() >= coalAmount then
        local tile = Tile(toPosition)
        if tile then
            local oven = tile:getItemById(ovenIdOff)
            if oven then
                oven:transform(ovenIdOn)
                item:remove(coalAmount)
            end
        end
    end
end

event:register()
Thanks alot for your answer!
Im getting this error in the console:
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/tools/forge_coal.lua
LuaScriptInterface::luaIsScriptsInterface(). EventCallback: can only be called inside (data/scripts/)
stack traceback:
        [C]: in function 'isScriptsInterface'
        ...KS\WORLD 1.4\data\scripts/lib\event_callbacks.lua:111: in function '__newindex'
        data/actions/scripts/tools/forge_coal.lua:9: in main chunk

Lua Script Error: [Test Interface]
data/actions/scripts/tools/forge_coal.lua
LuaScriptInterface::luaIsScriptsInterface(). EventCallback: can only be called inside (data/scripts/)
stack traceback:
        [C]: in function 'isScriptsInterface'
        ...KS\WORLD 1.4\data\scripts/lib\event_callbacks.lua:90: in function 'register'
        data/actions/scripts/tools/forge_coal.lua:22: in main chunk
[Warning - Event::checkScript] Event onUse not found. scripts/tools/forge_coal.lua

How do I have to register the action in action.xml or is in movements.xml?
 
Thanks alot for your answer!
Im getting this error in the console:
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/tools/forge_coal.lua
LuaScriptInterface::luaIsScriptsInterface(). EventCallback: can only be called inside (data/scripts/)
stack traceback:
        [C]: in function 'isScriptsInterface'
        ...KS\WORLD 1.4\data\scripts/lib\event_callbacks.lua:111: in function '__newindex'
        data/actions/scripts/tools/forge_coal.lua:9: in main chunk

Lua Script Error: [Test Interface]
data/actions/scripts/tools/forge_coal.lua
LuaScriptInterface::luaIsScriptsInterface(). EventCallback: can only be called inside (data/scripts/)
stack traceback:
        [C]: in function 'isScriptsInterface'
        ...KS\WORLD 1.4\data\scripts/lib\event_callbacks.lua:90: in function 'register'
        data/actions/scripts/tools/forge_coal.lua:22: in main chunk
[Warning - Event::checkScript] Event onUse not found. scripts/tools/forge_coal.lua

How do I have to register the action in action.xml or is in movements.xml?
She posted a script that is just for REVSCRIPTS here: \data\scripts\actions.

 
Thanks alot for your answer!
Im getting this error in the console:
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/tools/forge_coal.lua
LuaScriptInterface::luaIsScriptsInterface(). EventCallback: can only be called inside (data/scripts/)
stack traceback:
        [C]: in function 'isScriptsInterface'
        ...KS\WORLD 1.4\data\scripts/lib\event_callbacks.lua:111: in function '__newindex'
        data/actions/scripts/tools/forge_coal.lua:9: in main chunk

Lua Script Error: [Test Interface]
data/actions/scripts/tools/forge_coal.lua
LuaScriptInterface::luaIsScriptsInterface(). EventCallback: can only be called inside (data/scripts/)
stack traceback:
        [C]: in function 'isScriptsInterface'
        ...KS\WORLD 1.4\data\scripts/lib\event_callbacks.lua:90: in function 'register'
        data/actions/scripts/tools/forge_coal.lua:22: in main chunk
[Warning - Event::checkScript] Event onUse not found. scripts/tools/forge_coal.lua

How do I have to register the action in action.xml or is in movements.xml?
As @Mateus Robeerto said this is a Revscript, you just have to create a LUA file inside the data/scripts/ folder and add this code fragment there.

It is not necessary to register anything in any XML file, since this is a REVSCRIPT, these are registered in the same file.
 
As @Mateus Robeerto said this is a Revscript, you just have to create a LUA file inside the data/scripts/ folder and add this code fragment there.

It is not necessary to register anything in any XML file, since this is a REVSCRIPT, these are registered in the same file.
Ok! I see! Sorry for my noobness xD
I did several tests, also I edited the item giving it some height so items can me placed above it but nothing is happening (with any error in console).
Also I tested with other items aswell to see if my item was the oroblem and still nothing happen :<
There in Scripts folder are more sub-folders (actions, eventcallbacks, creatureevents and some more) I tried place the script in those but it didn't work either. What im doing wrong?
 
Ok! I see! Sorry for my noobness xD
I did several tests, also I edited the item giving it some height so items can me placed above it but nothing is happening (with any error in console).
Also I tested with other items aswell to see if my item was the oroblem and still nothing happen :<
There in Scripts folder are more sub-folders (actions, eventcallbacks, creatureevents and some more) I tried place the script in those but it didn't work either. What im doing wrong?
By default this event is disabled, you just have to enable it.
change 0 to 1
 
By default this event is disabled, you just have to enable it.
change 0 to 1
Thanks! This is beautiful.
Now is working!
Just one issue is happening, the coal doesn't get removed from the inventory or if I place it in the ground and drag it to the oven, so when I trow it, it just stays there above the oven, and the item is changed. So you can basically trick the system and use the oven with the same coal infinitely. Is any way to fix it?

EDIT:
I was doing some tests and the script works with 1 non-stackable item, but if are several stackable it doesn't. That's seems to be the problem. :<
 
Last edited:
Back
Top