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

RevScripts Help adapting revscript from onuse function to on stepin/out tfs 1.3

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,753
Solutions
9
Reaction score
281
Location
Chile
Hello Im trying to adapt a rescript made by xikini that is working with levers (with function on use ).I want it to be working with function onstepin/ out-
I
have adapted it a bit changing key words, variables and declarations?
like:
Lua:
 --{unused = left}  {used =down} {tiles = levers}  {1945 = 426}  {1946 =425} local leverActions = Action() = local usingTiles = Action()// data changed
and this
Code:
--function usingTiles.onUse(player, item, fromPosition, target, toPosition, isHotkey) //datachanged
function usingTiles.onStepIn(creature, item, position, fromPosition)--(player, item, fromPosition, target, toPosition, isHotkey)

the script used to be like this
Code:
  "add" / "remove" -> tells the script what to do when lever is on the left. (after it flops, it will do the opposite)
    "replace" -> transforms an item into another item, instead of adding/removing
    
]]--

local levers = {left = 1945, right = 1946}
local config = {
-- [actionid] = {"object", "add", position, itemid, relocate_direction}
-- [actionid] = {"object", "remove", position, itemid, relocate_direction}
-- [actionid] = {"object", "replace", position, {itemid_from, itemid_to}}

    [45001] = {"object", "add", Position(94, 93, 7), 1026, "south"},
    [45002] = {"object", "remove", Position(96, 93, 7), 1026, "south"},
    [45003] = {"object", "replace", Position(98, 93, 7), {1026, 1050}},
    
-- [actionid] = {"floor", "add", position, itemid}
-- [actionid] = {"floor", "remove", position, itemid}
-- [actionid] = {"floor", "replace", position, {itemid_from, itemid_to}, {relocate_from, relocate_to}}

    [45004] = {"floor", "add", Position(100, 93, 7), 406},
    [45005] = {"floor", "remove", Position(102, 93, 7), 406},
    [45006] = {"floor", "replace", Position(104, 93, 7), {406, 407}, {false, false}},
    [45007] = {"floor", "replace", Position(106, 93, 6), {461, 462}, {false, true}}, -- true means YES do relocate.
}

local relocateDirections = {
    ["north"] = {0, -1},
    ["east"]  = {1, 0},
    ["south"] = {0, 1},
    ["west"]  = {-1, 0},
}

local function transposeFields(fromPosition, toPosition, transpose)
    local tile = Tile(fromPosition)
    if tile then
        local items = tile:getItems()
        if items then
            for i, item in ipairs(items) do
                if transpose == true then
                    item:moveTo(toPosition)
                else
                    item:remove()
                end
            end
        end
    end
end

local leverActions = Action()

function leverActions.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local item_id = item.itemid
    local index = config[item.actionid]
    local tile = Tile(index[3])
    
    -- add
    if index[2] == "add" and item_id == levers.left or index[2] == "remove" and item_id == levers.right then
        if index[1] == "object" then
            local relocatePosition = Position(index[3].x + relocateDirections[index[5]][1], index[3].y + relocateDirections[index[5]][2], index[3].z)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, true)
            Game.createItem(index[4], 1, index[3])
        elseif index[1] == "floor" then
            Game.createTile(index[3], true)
            Game.createItem(index[4], 1, index[3])
        end
        
    -- remove
    elseif index[2] == "remove" and item_id == levers.left or index[2] == "add" and item_id == levers.right then
        if index[1] == "object" then
            local object = tile:getItemById(index[4])
            object:remove()
        elseif index[1] == "floor" then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
            tile:getGround():remove()
        end
        
    -- replace
    elseif index[2] == "replace" then
        local transformTo = tile:getItemCountById(index[4][1]) > 0 and 2 or 1
        local object = tile:getItemById(transformTo == 2 and index[4][1] or index[4][2])           
        object:transform(index[4][transformTo])
        if index[1] == "floor" and index[5][transformTo] == true then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
        end
        
    end
    
    item:transform(item_id == levers.left and levers.right or levers.left)
    return true
end

for k, v in pairs(config) do
    leverActions:aid(k)
end
leverActions:register()

And now it looks like this. But im having an errors in console that have no idea how to fix. Please help
Code:
Lua Script Error: [Scripts Interface]
D:\Escritorio Externo\Tibia\forgottenserver-8.7-downgrade\data\scripts\onstep_in_out_tile.lua
data/lib/compat/compat.lua:91: bad argument #1 to 'rawset' (table expected, got userdata)
stack traceback:
        [C]: at 0x7ff69b002830
        [C]: in function 'rawset'
        data/lib/compat/compat.lua:91: in function '__newindex'
        ...server-8.7-downgrade\data\scripts\onstep_in_out_tile.lua:63: in main chunk
> onstep_in_out_tile.lua [error]

Code:
--[[
    "object" -> anything that is not a floor tile.
    "floor" floor tiles (roof/ground/hole)
    
    "add" / "remove" -> tells the script what to do when lever is on the unused. (after it flops, it will do the opposite)
    "replace" -> transforms an item into another item, instead of adding/removing
    
]]--

local tiles = {unused = 426, used = 425}    --unused = l3ft  us3d =down tiles = lebers  1945 = 426  1946 =425// data changed
local config = {
-- [actionid] = {"object", "add", position, itemid, relocate_direction}
-- [actionid] = {"object", "remove", position, itemid, relocate_direction}
-- [actionid] = {"object", "replace", position, {itemid_from, itemid_to}}

   -- [45001] = {"object", "add", Position(94, 93, 7), 1026, "south"},
  --  [45002] = {"object", "remove", Position(96, 93, 7), 1026, "south"},
   -- [45003] = {"object", "replace", Position(98, 93, 7), {1026, 1050}},
    
-- [actionid] = {"floor", "add", position, itemid}
-- [actionid] = {"floor", "remove", position, itemid}
-- [actionid] = {"floor", "replace", position, {itemid_from, itemid_to}, {relocate_from, relocate_to}}
    --[4021] = {"object", "remove", Position(32566, 32119, 7), 1026, "east"}, -- old
    --[4021] = {"object", "remove", Position(32566, 32119, 7), 1025, "east"}, -- new triangle tower
    --[4024] = {"floor", "replace", Position(32398, 32239, 6), {405, 429}, {false, true}}, --switchneartemple
   -- [4025] = {"floor", "replace", Position(32399, 32239, 6), {405, 429}, {false, true}}, --switchneartemple
    [40166] = {"floor", "replace", Position(320006, 32006, 8), {354, 427}, {false, true}}, --Lighthouse
--
   -- [45004] = {"floor", "add", Position(100, 93, 7), 406},
   -- [45005] = {"floor", "remove", Position(102, 93, 7), 406},
   -- [45006] = {"floor", "replace", Position(104, 93, 7), {406, 407}, {false, false}},
   -- [45007] = {"floor", "replace", Position(106, 93, 6), {461, 462}, {false, true}}, -- true means YES do relocate.
}

local relocateDirections = {
    ["north"] = {0, -1},
    ["east"]  = {1, 0},
    ["south"] = {0, 1},
    ["west"]  = {-1, 0},
}

local function transposeFields(fromPosition, toPosition, transpose)
    local tile = Tile(fromPosition)
    if tile then
        local items = tile:getItems()
        if items then
            for i, item in ipairs(items) do
                if transpose == true then
                    item:moveTo(toPosition)
                else
                    item:remove()
                end
            end
        end
    end
end

--local usingTiles = Action() l3verActions == usingTiles// data changed
local usingTiles = Action()

--function usingTiles.onUse(player, item, fromPosition, target, toPosition, isHotkey) //datachanged
function usingTiles.onStepIn(creature, item, position, fromPosition)--(player, item, fromPosition, target, toPosition, isHotkey)
    local item_id = item.itemid
    local index = config[item.actionid]
    local tile = Tile(index[3])
    
    -- add
    if index[2] == "add" and item_id == tiles.unused or index[2] == "remove" and item_id == tiles.used then
        if index[1] == "object" then
            local relocatePosition = Position(index[3].x + relocateDirections[index[5]][1], index[3].y + relocateDirections[index[5]][2], index[3].z)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, true)
            Game.createItem(index[4], 1, index[3])
        elseif index[1] == "floor" then
            Game.createTile(index[3], true)
            Game.createItem(index[4], 1, index[3])
        end
        
    -- remove
    elseif index[2] == "remove" and item_id == tiles.unused or index[2] == "add" and item_id == tiles.used then
        if index[1] == "object" then
            local object = tile:getItemById(index[4])
            object:remove()
        elseif index[1] == "floor" then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
            tile:getGround():remove()
        end
        
    -- replace
    elseif index[2] == "replace" then
        local transformTo = tile:getItemCountById(index[4][1]) > 0 and 2 or 1
        local object = tile:getItemById(transformTo == 2 and index[4][1] or index[4][2])           
        object:transform(index[4][transformTo])
        if index[1] == "floor" and index[5][transformTo] == true then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
        end
        
    end
    
    item:transform(item_id == tiles.unused and tiles.used or tiles.unused)
    return true
end

for k, v in pairs(config) do
    usingTiles:aid(k)
end
usingTiles:register()
 
OP
Felipe93

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,753
Solutions
9
Reaction score
281
Location
Chile
i posted the original script in the main post bro. i'll post it again.
so the script work with onuse function with levers, i want it to be changed for on stepin/Out function
si it will work when a players stand on a tile with X aid or uid
THE UNEDITED SCRIPT
Lua:
the script used to be like this
Code:
  "add" / "remove" -> tells the script what to do when lever is on the left. (after it flops, it will do the opposite)
    "replace" -> transforms an item into another item, instead of adding/removing
  
]]--

local levers = {left = 1945, right = 1946}
local config = {
-- [actionid] = {"object", "add", position, itemid, relocate_direction}
-- [actionid] = {"object", "remove", position, itemid, relocate_direction}
-- [actionid] = {"object", "replace", position, {itemid_from, itemid_to}}

    [45001] = {"object", "add", Position(94, 93, 7), 1026, "south"},
    [45002] = {"object", "remove", Position(96, 93, 7), 1026, "south"},
    [45003] = {"object", "replace", Position(98, 93, 7), {1026, 1050}},
  
-- [actionid] = {"floor", "add", position, itemid}
-- [actionid] = {"floor", "remove", position, itemid}
-- [actionid] = {"floor", "replace", position, {itemid_from, itemid_to}, {relocate_from, relocate_to}}

    [45004] = {"floor", "add", Position(100, 93, 7), 406},
    [45005] = {"floor", "remove", Position(102, 93, 7), 406},
    [45006] = {"floor", "replace", Position(104, 93, 7), {406, 407}, {false, false}},
    [45007] = {"floor", "replace", Position(106, 93, 6), {461, 462}, {false, true}}, -- true means YES do relocate.
}

local relocateDirections = {
    ["north"] = {0, -1},
    ["east"]  = {1, 0},
    ["south"] = {0, 1},
    ["west"]  = {-1, 0},
}

local function transposeFields(fromPosition, toPosition, transpose)
    local tile = Tile(fromPosition)
    if tile then
        local items = tile:getItems()
        if items then
            for i, item in ipairs(items) do
                if transpose == true then
                    item:moveTo(toPosition)
                else
                    item:remove()
                end
            end
        end
    end
end

local leverActions = Action()

function leverActions.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local item_id = item.itemid
    local index = config[item.actionid]
    local tile = Tile(index[3])
  
    -- add
    if index[2] == "add" and item_id == levers.left or index[2] == "remove" and item_id == levers.right then
        if index[1] == "object" then
            local relocatePosition = Position(index[3].x + relocateDirections[index[5]][1], index[3].y + relocateDirections[index[5]][2], index[3].z)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, true)
            Game.createItem(index[4], 1, index[3])
        elseif index[1] == "floor" then
            Game.createTile(index[3], true)
            Game.createItem(index[4], 1, index[3])
        end
      
    -- remove
    elseif index[2] == "remove" and item_id == levers.left or index[2] == "add" and item_id == levers.right then
        if index[1] == "object" then
            local object = tile:getItemById(index[4])
 
OP
Felipe93

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,753
Solutions
9
Reaction score
281
Location
Chile
try change this
Lua:
local usingTiles = Action()
for
Lua:
local usingTiles = MoveEvent()
ok it solved the issue but im facing a new one now
i added this to the edited script (on step out function)
Lua:
function usingTiles.onStepOut(creature, item, position, fromPosition)--(player, item, fromPosition, target, toPosition, isHotkey)
    local item_id = item.itemid
    local index = config[item.actionid]
    local tile = Tile(index[3])
 
    -- add
    if index[2] == "add" and item_id == tiles.unused or index[2] == "remove" and item_id == tiles.used then
        if index[1] == "object" then
            local relocatePosition = Position(index[3].x + relocateDirections[index[5]][1], index[3].y + relocateDirections[index[5]][2], index[3].z)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, true)
            Game.createItem(index[4], 1, index[3])
        elseif index[1] == "floor" then
            Game.createTile(index[3], true)
            Game.createItem(index[4], 1, index[3])
        end
     
    -- remove
    elseif index[2] == "remove" and item_id == tiles.unused or index[2] == "add" and item_id == tiles.used then
        if index[1] == "object" then
            local object = tile:getItemById(index[4])
            object:remove()
        elseif index[1] == "floor" then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
            tile:getGround():remove()
        end
     
    -- replace
    elseif index[2] == "replace" then
        local transformTo = tile:getItemCountById(index[4][1]) > 0 and 2 or 1
        local object = tile:getItemById(transformTo == 2 and index[4][1] or index[4][2])        
        object:transform(index[4][transformTo])
        if index[1] == "floor" and index[5][transformTo] == true then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
        end
     
    end
 
    item:transform(item_id == tiles.unused and tiles.used or tiles.unused)
    return true
end

for k, v in pairs(config) do
    usingTiles:aid(k)
end
usingTiles:register()
so the script now look like this

Lua:
--[[
    "object" -> anything that is not a floor tile.
    "floor" floor tiles (roof/ground/hole)
 
    "add" / "remove" -> tells the script what to do when lever is on the unused. (after it flops, it will do the opposite)
    "replace" -> transforms an item into another item, instead of adding/removing
 
]]--

local tiles = {unused = 426, used = 425}    --unused = l3ft  us3d =down tiles = lebers  1945 = 426  1946 =425// data changed
local config = {

--
   -- [45004] = {"floor", "add", Position(100, 93, 7), 406},
   -- [45005] = {"floor", "remove", Position(102, 93, 7), 406},
   -- [45006] = {"floor", "replace", Position(104, 93, 7), {406, 407}, {false, false}},
   -- [45007] = {"floor", "replace", Position(106, 93, 6), {461, 462}, {false, true}}, -- true means YES do relocate.
}

local relocateDirections = {
    ["north"] = {0, -1},
    ["east"]  = {1, 0},
    ["south"] = {0, 1},
    ["west"]  = {-1, 0},
}

local function transposeFields(fromPosition, toPosition, transpose)
    local tile = Tile(fromPosition)
    if tile then
        local items = tile:getItems()
        if items then
            for i, item in ipairs(items) do
                if transpose == true then
                    item:moveTo(toPosition)
                else
                    item:remove()
                end
            end
        end
    end
end

--local usingTiles = Action() l3verActions == usingTiles// data changed
--local usingTiles = Action()
local usingTiles = MoveEvent()

--function usingTiles.onUse(player, item, fromPosition, target, toPosition, isHotkey) //datachanged
function usingTiles.onStepIn(creature, item, position, fromPosition)--(player, item, fromPosition, target, toPosition, isHotkey)
    local item_id = item.itemid
    local index = config[item.actionid]
    local tile = Tile(index[3])
 
    -- add
    if index[2] == "add" and item_id == tiles.unused or index[2] == "remove" and item_id == tiles.used then
        if index[1] == "object" then
            local relocatePosition = Position(index[3].x + relocateDirections[index[5]][1], index[3].y + relocateDirections[index[5]][2], index[3].z)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, true)
            Game.createItem(index[4], 1, index[3])
        elseif index[1] == "floor" then
            Game.createTile(index[3], true)
            Game.createItem(index[4], 1, index[3])
        end
    
    -- remove
    elseif index[2] == "remove" and item_id == tiles.unused or index[2] == "add" and item_id == tiles.used then
        if index[1] == "object" then
            local object = tile:getItemById(index[4])
            object:remove()
        elseif index[1] == "floor" then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
            tile:getGround():remove()
        end
    
    -- replace
    elseif index[2] == "replace" then
        local transformTo = tile:getItemCountById(index[4][1]) > 0 and 2 or 1
        local object = tile:getItemById(transformTo == 2 and index[4][1] or index[4][2])        
        object:transform(index[4][transformTo])
        if index[1] == "floor" and index[5][transformTo] == true then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
        end
    
    end
 
    item:transform(item_id == tiles.unused and tiles.used or tiles.unused)
    return true
end

for k, v in pairs(config) do
    usingTiles:aid(k)
end
usingTiles:register()

function usingTiles.onStepOut(creature, item, position, fromPosition)--(player, item, fromPosition, target, toPosition, isHotkey)
    local item_id = item.itemid
    local index = config[item.actionid]
    local tile = Tile(index[3])
 
    -- add
    if index[2] == "add" and item_id == tiles.unused or index[2] == "remove" and item_id == tiles.used then
        if index[1] == "object" then
            local relocatePosition = Position(index[3].x + relocateDirections[index[5]][1], index[3].y + relocateDirections[index[5]][2], index[3].z)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, true)
            Game.createItem(index[4], 1, index[3])
        elseif index[1] == "floor" then
            Game.createTile(index[3], true)
            Game.createItem(index[4], 1, index[3])
        end
    
    -- remove
    elseif index[2] == "remove" and item_id == tiles.unused or index[2] == "add" and item_id == tiles.used then
        if index[1] == "object" then
            local object = tile:getItemById(index[4])
            object:remove()
        elseif index[1] == "floor" then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
            tile:getGround():remove()
        end
    
    -- replace
    elseif index[2] == "replace" then
        local transformTo = tile:getItemCountById(index[4][1]) > 0 and 2 or 1
        local object = tile:getItemById(transformTo == 2 and index[4][1] or index[4][2])        
        object:transform(index[4][transformTo])
        if index[1] == "floor" and index[5][transformTo] == true then
            local relocatePosition = Position(index[3].x, index[3].y, index[3].z + 1)
            tile:relocateTo(relocatePosition)
            transposeFields(index[3], relocatePosition, false)
        end
    
    end
 
    item:transform(item_id == tiles.unused and tiles.used or tiles.unused)
    return true
end

for k, v in pairs(config) do
    usingTiles:aid(k)
end
usingTiles:register()


usingTiles:register()[/CODE]
and im getting this error in console and the exe get instantly closed after it
Code:
>> ["scripts"]
Failure: [Event::loadCallback] scriptInterface == nullptr. scriptid = 692
i don't know what it means the script only has 164 lines and nothing on it has the number 692. help pls and thanks

EDIT : THE ISSUE WAS SOLVED I FORGET TO ADD
--local usingTiles = Action() l3verActions == usingTiles// data changed
--local usingTiles = Action()
local usingTiles = MoveEvent() BEFORE OF ONSTEPOUT FUNCTION
 
Last edited:
Top