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

I'm Looking for help with Rookgaard katana room quest script

olje

New Member
Joined
Dec 26, 2016
Messages
38
Reaction score
1
Hi guys
I have problems with katana room quest script
pNxAIFA.jpg

closed door's id is 5107 and when you pull lever to the left the door opens and door id is 5109 then when pull lever to the right the door closes and lock so is needed doSetItemActionId(uid, actionid) I think
and I created something like this
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == 1946 then
doRemoveItem(getTileItemById({x=32177, y=32148, z=11}, 5107).uid)
doCreateItem(5109, 1, {x=32177, y=32148, z=11})
doTransformItem(item.uid,item.itemid-1)
elseif item.itemid == 1945 then
doRemoveItem(getTileItemById({x=32177, y=32148, z=11}, 5109).uid)
doCreateItem(5107, 1, {x=32177, y=32148, z=11})
doTransformItem(item.uid,item.itemid+1)
but sometimes it's messed up look:
JZB32VF.jpg


I need your help thanks!
 
Solution
pull to the left good door is open but to the right luadoremove item not found ;p
Woot? How you can get error luadoremove... if there's no such function at all. Are you using 0.4? If yes, keep in mind that 0.4 is bugged.

Try again then:
Code:
local doorPosition = {x=32177, y=32148, z=11}
local locked = 5107
local nonlocked = {5108, 5109}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local doorlocked = getTileItemById(doorPosition, locked).uid
    local doornonlocked1 = getTileItemById(doorPosition, nonlocked[1]).uid
    local doornonlocked2 = getTileItemById(doorPosition, nonlocked[2]).uid

    if doorlocked > 0 then
        doTransformItem(doorlocked, nonlocked[2])
    elseif doornonlocked1 > 0 then...
I think your just confused on how this door is actually supposed to work.

If you pull the lever and the door is locked, it should open the door, and the door should remain unlocked.
If you pull the lever and the door is unlocked, it is supposed to close and lock the door, remain locked.
 
I think your just confused on how this door is actually supposed to work.

If you pull the lever and the door is locked, it should open the door, and the door should remain unlocked.
If you pull the lever and the door is unlocked, it is supposed to close and lock the door, remain locked.
yes you are right with this
but I'm on my rookstayer on real tibia now so I tested it
If you pull the lever and the door is locked, it should open the door, and the door should remain unlocked and on rl I can close door manually and door don't lock I can open and close door all the time using right mouse button
 
And if you click lever a second time? Or it is impossible to click lever a second time?
yes you are right with this
but I'm on my rookstayer on real tibia now so I tested it
If you pull the lever and the door is locked, it should open the door, and the door should remain unlocked and on rl I can close door manually and door don't lock I can open and close door all the time using right mouse button
Ugh, actually can I just teamviewer and fix this issue instead of coming back and posting every 3 hours? xD

It's driving me nuts.
I'm available to teamviewer, from 8:40pm - 10:00pm.
PM me your details, if this is a good option for you.
 
on real tibia is:
when you close the door manually (the lever is on the left) and when I pull the lever to the right nothing happens the door just lock and from now I can't clsoe and open door manually until I pull the lever to the left
 
Keep in mind that ALL open tibia's scripts for doors are broken. ALL. They have bad logic etc.
In Tibia you have 3 doors:
6JrEaQm.png

1209: First door is a closed and locked door
1210: Second is only closed, but not locked
1211: Third is a open door

Such situation is for all other doors. Even your 5108.

Your data/actions/scripts/other/door.lua is using only 2 of them, instead of 3. This is a logic issue made in 2006, and this logic is copied again and again for over 10 years. Script for doors evolved during these 10 years, but noone fixed it's poor logic from 2006.

All TFS, OTX, Yurotses, Deathtouches etc have the same issue in door.lua. Also devs instead of fixing door.lua logic decided to insert in-sources function to handle key system. This is like building raft to pass trought river instead of passing it via already built bridge only becouse you don't know for what bridge is.

I'm sad to say, but one of solutions is fixing that 2006 poor logic in door.lua which was copied and copied for years.

This chart may help you solve the problem:

4jIM78R.png
 
I have Cykotitan's script I think that is good:
Code:
local locked = {
[1209] = 2, [1212] = 2,
[1231] = 2, [1234] = 2,
[1249] = 2, [1252] = 2,
[3536] = 1, [3545] = 1,
[4914] = 1, [4917] = 1,
[5099] = 1, [5108] = 1,
[5117] = 1, [5126] = 1,
[5135] = 1, [5144] = 1,
[5138] = 1, [5141] = 1,
[5279] = 1, [5282] = 1,
[5733] = 1, [5736] = 1,
[6193] = 1, [6196] = 1,
[6249] = 2, [6252] = 2,
[6892] = 1, [6901] = 1,
[7034] = 1, [7043] = 1,
[8541] = 2, [8544] = 2,
[9165] = 2, [9168] = 2,
[9267] = 2, [9270] = 2,
[10268] = 2, [10271] = 2,
[5107] = 2,
[10469] = 1, [10478] = 1
}
local unlocked = {
[1210] = 1, [1213] = 1,
[1232] = 1, [1235] = 1,
[1250] = 1, [1253] = 1,
[1539] = 1, [1541] = 1,
[1634] = 1, [1636] = 1,
[3535] = 2, [3544] = 2,
[4913] = 2, [4916] = 2,
[5098] = 2,
[5116] = 2, [5125] = 2,
[5134] = 2, [5143] = 2,
[5137] = 2, [5140] = 2,
[5278] = 2, [5281] = 2,
[5732] = 2, [5735] = 2,
[6192] = 2, [6195] = 2,
[6250] = 1, [6253] = 1,
[6891] = 2, [6900] = 2,
[7033] = 2, [7042] = 2,
[8542] = 1, [8545] = 1,
[9166] = 1, [9169] = 1,
[9268] = 1, [9271] = 1,
[10269] = 1, [10272] = 1,
[10468] = 2, [10477] = 2
}
local openVertical = {
[1211] = -1,
[1233] = -1,
[1251] = -1,
[1540] = -1,
[1635] = -1,
[3546] = -2,
[4915] = -2,
[5109] = -2z,
[5127] = -2,
[5142] = -2,
[5145] = -2,
[5283] = -2,
[5737] = -2,
[6194] = -2,
[6251] = -1,
[6902] = -2,
[7044] = -2,
[8543] = -1,
[9167] = -1,
[9269] = -1,
[10270] = -1,
[10479] = -2
}
local openHorizontal = {
[1214] = -1,
[1236] = -1,
[1254] = -1,
[1542] = -1,
[1637] = -1,
[3537] = -2,
[4918] = -2,
[5100] = -2,
[5118] = -2,
[5136] = -2,
[5139] = -2,
[5280] = -2,
[5734] = -2,
[6197] = -2,
[6254] = -1,
[6893] = -2,
[7035] = -2,
[8546] = -1,
[9170] = -1,
[9272] = -1,
[10273] = -1,
[10470] = -1
}
local verticalOpenHouse = {1220, 1238, 1639, 3548, 5083, 5111, 5129, 5285, 5516, 6199, 6256, 6802, 6904, 7046, 7055, 8548, 9172, 9274, 10275, 10481}
local horizontalOpenHouse = {1222, 1240, 1641, 3539, 5085, 5102, 5120, 5287, 5518, 6201, 6258, 6800, 6895, 7037, 7057, 8550, 9174, 9276, 10277, 10472}
local closedHouse = {1219, 1221, 1237, 1239, 1638, 1640, 3538, 3547, 5082, 5084, 5101, 5110, 5119, 5128, 5284, 5286, 5515, 5517, 6198, 6200, 6255, 6257, 6799, 6801, 6894, 6903, 7036, 7045, 7054, 7056, 8547, 8549, 9171, 9173, 9273, 9275, 10274, 10276, 10471, 10480}
local closedQuest = {1223, 1225, 1241, 1243, 1255, 1257, 3542, 3551, 5105, 5114, 5123, 5132, 5288, 5290, 5745, 5748, 6202, 6204, 6259, 6261, 6898, 6907, 7040, 7049, 8551, 8553, 9175, 9177, 9277, 9279, 10278, 10280, 10475, 10484}
local closedLevel = {1227, 1229, 1245, 1247, 1259, 1261, 3540, 3549, 5103, 5112, 5121, 5130, 5292, 5294, 6206, 6208, 6263, 6265, 6896, 6905, 7038, 7047, 8555, 8557, 9179, 9181, 9281, 9283, 10282, 10284, 10473, 10482}
local keys = {2086, 2087, 2088, 2089, 2090, 2091, 2092}

local function doorEnter(cid, item, toPosition)
doTransformItem(item.uid, item.itemid + 1)
doTeleportThing(cid, toPosition)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
if(fromPosition.x ~= CONTAINER_POSITION and isPlayerPzLocked(cid) and getTileInfo(fromPosition).protection) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
elseif isInArray(closedQuest, item.itemid) then
if getPlayerStorageValue(cid, item.actionid) ~= -1 then
doorEnter(cid, item, toPosition)
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'The door seems to be sealed against unwanted intruders.')
end
elseif isInArray(closedLevel, item.itemid) then
if item.actionid > 0 and getPlayerLevel(cid) >= item.actionid - 1000 then
doorEnter(cid, item, toPosition)
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Only the worthy may pass.')
end
elseif isInArray(keys, item.itemid) then
if not isCreature(itemEx.uid) then
if locked[itemEx.itemid] or unlocked[itemEx.itemid] or openHorizontal[itemEx.itemid] or openVertical[itemEx.itemid] then
if itemEx.actionid > 0 and item.actionid == itemEx.actionid then
if locked[itemEx.itemid] then
doTransformItem(itemEx.uid, itemEx.itemid + (locked[itemEx.itemid] == 2 and 2 or 1))
elseif unlocked[itemEx.itemid] then
doTransformItem(itemEx.uid, itemEx.itemid + (unlocked[itemEx.itemid] == 1 and -1 or 1))
elseif openHorizontal[itemEx.itemid] then
doTransformItem(itemEx.uid, itemEx.itemid + (openHorizontal[itemEx.itemid] == -1 and -2 or -1))
elseif openVertical[itemEx.itemid] then
doTransformItem(itemEx.uid, itemEx.itemid + (openVertical[itemEx.itemid] == -1 and -2 or -1))
end
else
doPlayerSendCancel(cid, 'The key does not match.')
end
else
return false
end
else
return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
end
elseif openHorizontal[item.itemid] or isInArray(horizontalOpenHouse, item.itemid) then
local v = getTopCreature(fromPosition).uid
if isCreature(v) then
local k = {x=fromPosition.x,y=queryTileAddThing(v, {x=fromPosition.x,y=fromPosition.y+1,z=fromPosition.z}) == 1 and fromPosition.y+1 or fromPosition.y-1,z=fromPosition.z}
if v ~= cid and getTilePzInfo(fromPosition) and not getTilePzInfo(k) then
return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
end
doTeleportThing(v, k, true)
end
doTransformItem(item.uid, isInArray(horizontalOpenHouse, item.itemid) and item.itemid - 1 or item.itemid + openHorizontal[item.itemid])
elseif openVertical[item.itemid] or isInArray(verticalOpenHouse, item.itemid) then
local v = getTopCreature(fromPosition).uid
if isCreature(v) then
local k = {x=queryTileAddThing(v, {x=fromPosition.x+1,y=fromPosition.y,z=fromPosition.z}) == 1 and fromPosition.x+1 or fromPosition.x-1,y=fromPosition.y,z=fromPosition.z}
if v ~= cid and getTilePzInfo(fromPosition) and not getTilePzInfo(k) then
return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
end
doTeleportThing(v, k, true)
end
doTransformItem(item.uid, isInArray(verticalOpenHouse, item.itemid) and item.itemid - 1 or item.itemid + openVertical[item.itemid])
elseif locked[item.itemid] then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is locked.')
elseif unlocked[item.itemid] then
if item.actionid == 100 then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It is locked.')
else
doTransformItem(item.uid, item.itemid + unlocked[item.itemid])
end
elseif isInArray(closedHouse, item.itemid) then
doTransformItem(item.uid, item.itemid + 1)
else
return false
end
return true
end
 
Then use this katana_lever.lua, in RME put only unique id on lever and the same unique id to your actions.xml.
Code:
<action uniqueid="xxxxx" event="script" value="quests/katana_lever.lua"/>
Code:
local doorPosition = {x=32177, y=32148, z=11}
local locked = 5107
local nonlocked = {5108, 5109}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local doorlocked = getTileItemById(doorPosition, locked)
    local doornonlocked1 = getTileItemById(doorPosition, nonlocked[1])
    local doornonlocked2 = getTileItemById(doorPosition, nonlocked[2])
 
    if doorlocked then
        doTransformItem(doorlocked.uid, nonlocked[2])
    elseif doornonlocked1 then
        doTransformItem(doornonlocked1.uid, locked)
    elseif doornonlocked2 then
        local top = getTopCreature(doorPosition).uid
        if isCreature(top) then
            local tos = getCreaturePosition(top)
            doTeleportThing(top, {x = tos.x + 1, y = tos.y, z = tos.z}, true)
        end
        doTransformItem(doornonlocked2.uid, locked)
    end
    doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
    return true
end
 
Last edited:
Then use this katana_lever.lua, in RME put only unique id on lever and the same unique id to your actions.xml.
Code:
<action uniqueid="xxxxx" event="script" value="quests/katana_lever.lua"/>
Code:
local doorPosition = {x=32177, y=32148, z=11}
local locked = 5107
local nonlocked = {5108, 5109}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local doorlocked = getTileItemById(doorPosition, locked)
    local doornonlocked1 = getTileItemById(doorPosition, nonlocked[1])
    local doornonlocked2 = getTileItemById(doorPosition, nonlocked[2])
 
    if doorlocked then
        doTransformItem(doorlocked.uid, nonlocked[2])
    elseif doornonlocked1 then
        doTransformItem(doornonlocked1.uid, locked)
    elseif doornonlocked2 then
        local top = getTopCreature(doorPosition).uid
        if isCreature(top) then
            local tos = getCreaturePosition(top)
            doTeleportThing(top, {x = tos.x + 1, y = tos.y, z = tos.z}, true)
        end
        doTransformItem(doornonlocked2.uid, locked)
    end
    doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
    return true
end
pull to the left good door is open but to the right luadoremove item not found ;p
 
pull to the left good door is open but to the right luadoremove item not found ;p
Woot? How you can get error luadoremove... if there's no such function at all. Are you using 0.4? If yes, keep in mind that 0.4 is bugged.

Try again then:
Code:
local doorPosition = {x=32177, y=32148, z=11}
local locked = 5107
local nonlocked = {5108, 5109}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local doorlocked = getTileItemById(doorPosition, locked).uid
    local doornonlocked1 = getTileItemById(doorPosition, nonlocked[1]).uid
    local doornonlocked2 = getTileItemById(doorPosition, nonlocked[2]).uid

    if doorlocked > 0 then
        doTransformItem(doorlocked, nonlocked[2])
    elseif doornonlocked1 > 0 then
        doTransformItem(doornonlocked1, locked)
    elseif doornonlocked2 > 0 then
        local top = getTopCreature(doorPosition).uid
        if isCreature(top) then
            local tos = getCreaturePosition(top)
            doTeleportThing(top, {x = tos.x + 1, y = tos.y, z = tos.z}, true)
        end
        doTransformItem(doornonlocked2, locked)
    end
    doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
    return true
end
 
Solution
I forgot about one thing that on rl tibia there are nice features that when door is open and on this tile is blood it cleans this tile and when item it relocate that item one tile to the right I don't know how to implement this functions
when I use this doCleanTile({x=32177, y=32148, z=11}) it removes blood but also door ;/
 
Code:
local doorPosition = {x=32177, y=32148, z=11}
local locked = 5107
local nonlocked = {5108, 5109}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local doorlocked = getTileItemById(doorPosition, locked).uid
    local doornonlocked1 = getTileItemById(doorPosition, nonlocked[1]).uid
    local doornonlocked2 = getTileItemById(doorPosition, nonlocked[2]).uid

    if doorlocked > 0 then
        doTransformItem(doorlocked, nonlocked[2])
    elseif doornonlocked1 > 0 then
        doTransformItem(doornonlocked1, locked)
    elseif doornonlocked2 > 0 then
        local top = getTopCreature(doorPosition).uid
        if isCreature(top) then
            local tos = getCreaturePosition(top)
            doTeleportThing(top, {x = tos.x + 1, y = tos.y, z = tos.z}, true)
        end
        for i = 1, 255 do
            local thing = getThingFromPos({x = doorPosition.x, y = doorPosition.y, z = doorPosition.z, stackPos = i})
            if not thing.itemid == nonlocked[2] then
                if isItemMovable(thing.uid) then
                    doCreateItem(thing.itemid, thing.type, {x = tos.x + 1, y = tos.y, z = tos.z})
                end
                doRemoveItem(thing.uid)
            end
        end
        doTransformItem(doornonlocked2, locked)
    end
    doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
    return true
end
 
Code:
local doorPosition = {x=32177, y=32148, z=11}
local locked = 5107
local nonlocked = {5108, 5109}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local doorlocked = getTileItemById(doorPosition, locked).uid
    local doornonlocked1 = getTileItemById(doorPosition, nonlocked[1]).uid
    local doornonlocked2 = getTileItemById(doorPosition, nonlocked[2]).uid

    if doorlocked > 0 then
        doTransformItem(doorlocked, nonlocked[2])
    elseif doornonlocked1 > 0 then
        doTransformItem(doornonlocked1, locked)
    elseif doornonlocked2 > 0 then
        local top = getTopCreature(doorPosition).uid
        if isCreature(top) then
            local tos = getCreaturePosition(top)
            doTeleportThing(top, {x = tos.x + 1, y = tos.y, z = tos.z}, true)
        end
        for i = 1, 255 do
            local thing = getThingFromPos({x = doorPosition.x, y = doorPosition.y, z = doorPosition.z, stackPos = i})
            if not thing.itemid == nonlocked[2] then
                if isItemMovable(thing.uid) then
                    doCreateItem(thing.itemid, thing.type, {x = tos.x + 1, y = tos.y, z = tos.z})
                end
                doRemoveItem(thing.uid)
            end
        end
        doTransformItem(doornonlocked2, locked)
    end
    doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
    return true
end
heh, I was going to do it the lazy way, relocate, clean, create door.
 
Back
Top