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

Rook switch error

Morcega Negra

Banned User
Joined
Aug 4, 2015
Messages
102
Solutions
1
Reaction score
8
rook.jpg

I have a bug in rats Bridge in Rookgaard,
the lever moves, however each time it is used it generates this error,
and if a player is in the middle of the bridge and pull someone to leverage the player is on the water

SCRIPT:
Code:
-- rook lever by QuaS~
local posi3 = {x=301, y=287, z=8} --
poss = {
[1] = {x=159, y=108, z=7},
[2] = {x=160, y=108, z=7},
[3] = {x=161, y=108, z=7}
}

local lever = {
[1] = {x=158, y=107, z=7},
[2] = {x=164, y=107, z=7}
}
local itemids = 5770
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == 1945 then
doCreateItem(itemids,poss[2])
if getTileItemById(poss[1],4645).itemid ~= nil then
doTransformItem(getTileItemById(poss[1],4645).uid,itemids)
end
if getTileItemById(poss[3],4647).itemid > 0 then
doTransformItem(getTileItemById(poss[3],4647).uid,itemids)
end
for i=1,#lever do
if lever.x == fromPosition.x then
o = i
end
end
if o == 1 then
b = 2
else
b = 1
end
doTransformItem(item.uid,item.itemid+1)
doTransformItem(getTileItemById(lever,1945).uid,1946)
elseif item.itemid == 1946 then
for p = 1,#poss do
doRelocate(poss[p], posi3)
end
for z =1,#poss do
poss[z].stackpos = 254
if getThingFromPos(poss[z]).itemid > 1000 then
doRemoveItem(getThingFromPos(poss[z]).uid)
end
poss[z].stackpos = 1
if getThingFromPos(poss[z]).itemid > 1000 then
doRemoveItem(getThingFromPos(poss[z]).uid)
end

end
for i=1,#lever do
if lever.x == toPosition.x then
o = i
end
end
if o == 1 then
b = 2
else
b = 1
end
doCreateItem(4616,poss[2])
doCreateItem(351,poss[1])
doCreateItem(351,poss[3])
doCreateItem(4645,poss[1])
doCreateItem(4647,poss[3])
doTransformItem(item.uid,item.itemid-1)
doTransformItem(getTileItemById(lever,1946).uid,1945)
end
return TRUE
end
how to fix?
 
Your error comes from this part on line 2.
Code:
local posi3 = {x=301, y=287, z=8} --
This tile does not exist to relocate players.
Most likely you'll just need to edit this position to one beside the bridge in order for it to all work correctly.

In case your interested, I've re-created the script for you below.. to be much smaller.
I don't understand why the script is so long for such a simple lever. o_O :oops: :cool:


Untested.

data/actions/actions.xml [make both levers have the same actionID in map]
Code:
<action actionid="45001" event="script" value="rook_sewer_grate_lever.lua"/>
data/actions/scripts/rook_sewer_grate_lever.lua
Code:
local bridge = {
     [1] = {x = 159, y = 108, z = 7}, -- left
     [2] = {x = 160, y = 108, z = 7}, -- middle
     [3] = {x = 161, y = 108, z = 7}  -- right
}
local tiles = {
     bridge_tile = 5770,
     dirt_tile = 103,
     L_water_tile = 4645,
     M_water_tile = 4616,
     R_water_tile = 4647
}
local random_relocate = true -- true or false
local relocate_pos = {
     [1] = {x = 158, y = 108, z = 7}, -- left left
     [2] = {x = 162, y = 108, z = 7}  -- right right
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

     if item.itemid == 1946 then
         doTransformItem(item.uid, item.itemid - 1)
     else
         doTransformItem(item.uid, item.itemid + 1)
     end
 
     if getThingFromPos(bridge[2]).itemid ~= tiles.bridge_tile then
         doTransformItem(getThingfromPos({x = bridge[1].x, y = bridge[1].y, z = bridge[1].z, stackpos = 1}).uid, tiles.bridge_tile)
         doCreateItem(tiles.bridge_tile, 1, bridge[2])
         doTransformItem(getThingfromPos({x = bridge[3].x, y = bridge[3].y, z = bridge[3].z, stackpos = 1}).uid, tiles.bridge_tile)
     else
         for i = 1, #bridge do
             if random_relocate == true then
                 doRelocate(bridge[i], relocate_pos[math.random(2)])
             else
                 doRelocate(bridge[i], relocate_pos[2])
             end
             doCleanTile(bridge[i], false)
         end
         doTransformItem(getThingfromPos({x = bridge[1].x, y = bridge[1].y, z = bridge[1].z, stackpos = 0}).uid, tiles.L_water_tile)
         doTransformItem(getThingfromPos({x = bridge[3].x, y = bridge[3].y, z = bridge[3].z, stackpos = 0}).uid, tiles.R_water_tile)
         doCreateItem(tiles.dirt_tile, 1, bridge[1])
         doCreateItem(tiles.M_water_tile, 1, bridge[2])
         doCreateItem(tiles.dirt_tile, 1, bridge[3])
     end
 
     return true
end
 
Last edited:
Your error comes from this part on line 2.
Code:
local posi3 = {x=301, y=287, z=8} --
This tile does not exist to relocate players.
Most likely you'll just need to edit this position to one beside the bridge in order for it to all work correctly.

In case your interested, I've re-created the script for you below.. to be much smaller.
I don't understand why the script is so long for such a simple lever. o_O :oops: :cool:


Untested.

data/actions/actions.xml [make both levers have the same actionID in map]
Code:
<action actionid="45001" event="script" value="rook_sewer_grate_lever.lua"/>
data/actions/scripts/rook_sewer_grate_lever.lua
Code:
local bridge = {
   [1] = { pos = {x = 159, y = 108, z = 7, stackpos = 0}, tile = 4645 }, -- left
   [2] = { pos = {x = 160, y = 108, z = 7, stackpos = 0}, tile = 4616 }, -- middle
   [3] = { pos = {x = 161, y = 108, z = 7, stackpos = 0}, tile = 4647 }  -- right
}
local relocate_pos = {x = 162, y = 108, z = 7}
local bridge_tile = 5770

function onUse(cid, item, fromPosition, itemEx, toPosition)

   -- transform lever
   if item.itemid == 1946 then
     doTransformItem(item.uid, item.itemid - 1)
   else
     doTransformItem(item.uid, item.itemid + 1)
   end

   -- check if drawbridge up or down
   if getThingFromPos(bridge[1].pos).itemid ~= bridge_tile then
     -- if down, then create
     for i = 1, #bridge do
       doTransformItem((getThingFromPos(bridge[i].pos).uid), bridge_tile)
     end
   else
     -- if up, relocate and clean, then remove bridge
     for i = 1, #bridge do
       doRelocate(bridge[i].pos, relocate_pos)
       doCleanTile(bridge[i].pos, false)
       doTransformItem((getThingFromPos(bridge[i].pos).uid), bridge[i].tile)
     end
   end

   return true
end
dont work =/
 
dont work =/

Well I kinda wish you posted some errors for me..
I've edited the above script to be more precise in what it's doing.
I've also added in a random relocate feature.. to stop people from abusing the switch.
I added a simple way to disable the feature though
Post any error's you receive.. if you receive any at all.

Hope all goes well.
 
Last edited:
Well I kinda wish you posted some errors for me..
I've edited the above script to be more precise in what it's doing.
I've also added in a random relocate feature.. to stop people from abusing the switch.
I added a simple way to disable the feature though
Post any error's you receive.. if you receive any at all.

Hope all goes well.
my mistake that the script works, but his did not work,
but wanted my script had no error message on the console

script dont work =/
 
I tested the script myself on 0.3.7. It is definitely working 100% on my end. Maybe we can team viewer to get it working? Can PM me if you want to try that.
 
Back
Top