• 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 Understanding how doors work

Sortdcz

New Member
Joined
Sep 2, 2013
Messages
14
Reaction score
0
Hello,

I'm interested in making a script where you use a key on a locked door that you can only lock up with that specific door key. In order to do this, do I only need the same actionid on the door and the item? Also, will I have to consider that when you use the item on the door again, it should transform back?

Edit: can I also just do this?

Code:
function onUse(cid, item, frompos, item2, topos)
    if item.actionid == 21591 then
        doTeleportThing(cid, {x = 1, y = 1, z = 1}, {x = 1, y = 1, z = 1})
        doSendMagicEffect(frompos, CONST_ME_TELEPORT, getCreaturePosition(cid), CONST_ME_TELEPORT)
        return true
    end
end

will this simply if you use the key with aid on the door, tp you to the other side of the door?
 
Last edited:
Sorry, I use OTServ SVN 0.6.3

this is my keys.lua:

Code:
function onUse(cid, item, frompos, item2, topos)
    if (item2.actionid == 0 or
      (isInArray(LOCKED_DOORS, item2.itemid) == false and
       isInArray(LOCKED_DOORS, item2.itemid-1) == false and
        isInArray(LOCKED_DOORS, item2.itemid-2) == false)) then
        return false
    end

    local canOpen = (item.actionid == 10000 or item.actionid == item2.actionid)
    if not(canOpen) then
        doPlayerSendCancel(cid, "The key does not match.")
        return true
    end

    -- Verify if you are opening or closing the door
    if(isInArray(LOCKED_DOORS, item2.itemid) ) then -- Opening
        doTransformItem(item2.uid, item2.itemid+2)
    elseif(isInArray(LOCKED_DOORS, item2.itemid-2) ) then -- Closing and Locking
        doTransformItem(item2.uid, item2.itemid-2)
    else                                                   -- Locking an already closed door
        doTransformItem(item2.uid, item2.itemid-1)
    end
    doSetItemActionId(item2.uid, item2.actionid)

    return true
end
and this is my doors_locked.lua (I don't have doors.lua):
Code:
function onUse(cid, item, frompos, item2, topos)
    if(item.actionid == 0) then
        -- This is impossible to happen, but whatever.
        doTransformItem(item.uid, item.itemid+2)
        return true
    end

    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is locked.")
    return true
end
 
This basicly works the same way, use one of the doors of the LOCKED_DOORS table (or add one) and use same actionid in the door as in the key item and add the key item to actions.xml.
 
Back
Top