Felipe93
Ghost Member
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:
and this
the script used to be like this
And now it looks like this. But im having an errors in console that have no idea how to fix. Please help
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
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()