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

Door that closes automatically when using Key. Unique Key.

juansanchez

Intermediate OT User
Joined
Apr 2, 2015
Messages
217
Reaction score
129
Hey everyone, i need a little help with a door that opens with a key.
I know how to make a chest give a key with actionid on it. I know how to open a door with a key and all that good stuff. However, i don't know how to make it when someone uses a Key on a Door, the characters automatically walks inside the door, and afterwards the character walks out, the door closes.
Simplifying:

1) Player uses key on door.
2) Player automatically walks inside the door.
3) Players walks out the door.
4) Door closes.


The door basically works like a gate of expertise. I need this so people that doesn't have the key won't be able to go inside the hunt, only those with the key will.

I'm using TFS 0.3.6.
Much appreciated if anyone could help me.
 
try a StepIn action on the square just after the door?

player uses key, opens door, steps through, and an action script shuts the door, and resets the the I'd to only work with the key again?

it seems like it should work, but I don't have the knowledge to script it
 
Why not just make it that when you use the key on the door it tps player through?
 
Why not just make it that when you use the key on the door it tps player through?
Because this is not what he wants I guess?

I won't write it for you, since I prefer to help people who put some initial effort into solving the problem themselves. I will do even better thing (from long-term perspective) and give you a hint. You need onUse method for the door just like you have with gate of expertise, but instead of checking player's level, you need to check for itemEx actionId. So when you have something like this:

Lua:
function onUse(cid, item, fromPos, itemEx, toPos)

you should check if itemEx (the item that was used with "use with") is the key you need (by checking action ID). You can check script responsible for gate of expertise as an example of how to push player through the door and script for fluids to check how you can do stuff with itemEx argument.

For closing the door, you can again check how gate of expertise work (onStepOut assigned to these items) and do the same thing for your door.
 
Because this is not what he wants I guess?

I won't write it for you, since I prefer to help people who put some initial effort into solving the problem themselves. I will do even better thing (from long-term perspective) and give you a hint. You need onUse method for the door just like you have with gate of expertise, but instead of checking player's level, you need to check for itemEx actionId. So when you have something like this:

Lua:
function onUse(cid, item, fromPos, itemEx, toPos)

you should check if itemEx (the item that was used with "use with") is the key you need (by checking action ID). You can check script responsible for gate of expertise as an example of how to push player through the door and script for fluids to check how you can do stuff with itemEx argument.

For closing the door, you can again check how gate of expertise work (onStepOut assigned to these items) and do the same thing for your door.


So, i tried messing around with the door ID on the movements.xml where all the gates of expertise are located, however it didn't work. And i tried messing around with the script but it's not something i know how to do very well. So yeah.. I'm not sure how to do it.
 
So, i tried messing around with the door ID on the movements.xml where all the gates of expertise are located, however it didn't work. And i tried messing around with the script but it's not something i know how to do very well. So yeah.. I'm not sure how to do it.

Then you should post in requests board instead: Requests. Since it is a request to create a script, rather than help with errors / issues in what you are trying to accomplish.
 
Go to your actions/doors.lua script and swap this part:
Lua:
if(isInArray(keys, item.itemid)) then
        if(itemEx.actionid > 0) then
            if(item.actionid == itemEx.actionid and doors[itemEx.itemid] ~= nil) then
                doTransformItem(itemEx.uid, doors[itemEx.itemid])
                doTeleportThing(cid, toPosition)
                return true
            end

Then if it's in the closingdoor.lua script in your movements, it suppose to close after stepping out.
 
Then you should post in requests board instead: Requests. Since it is a request to create a script, rather than help with errors / issues in what you are trying to accomplish.

yeah, i wasn't sure where to post but i think i'll post it there. Thanks anyways.

Go to your actions/doors.lua script and swap this part:
Lua:
if(isInArray(keys, item.itemid)) then
        if(itemEx.actionid > 0) then
            if(item.actionid == itemEx.actionid and doors[itemEx.itemid] ~= nil) then
                doTransformItem(itemEx.uid, doors[itemEx.itemid])
                doTeleportThing(cid, toPosition)
                return true
            end

Then if it's in the closingdoor.lua script in your movements, it suppose to close after stepping out.

Tried that, not sure if i did it wrong, but it didn't work :/
 
Don't do it this way. Messing with the door's file is never a good way to do it. The best way would be an onStepIn script that reads where the player walked into the door from. This code can be used to push the player through depending on which side he walked from.

Code:
local positions1 = { --If the player enters the door from these positions it will push him through and close the door.--
[1] = {x = 1000, y = 1000, z = 7},
[2] = {x = 1000, y = 1000, z = 7},
[3] = {x = 1000, y = 1000, z = 7}
}

local push_position1 = {x = 1000, y = 1000, z = 7} --Where the player will be pushed.

local positions2 = { --If the player enters the door from these positions it will push him the other way.--
[1] = {x = 1000, y = 1000, z = 7},
[2] = {x = 1000, y = 1000, z = 7},
[3] = {x = 1000, y = 1000, z = 7}
}

local push_position2 = {x = 1000, y = 1000, z = 7} --Where the player will be pushed.

local door_closed = 1111 -- itemId of the closed door --

function onStepIn(cid, item, fromPosition, itemEx, toPosition)
    for i = 1, #positions1 do
        if fromPosition == positions1[i] then
            doTeleportThing(cid, push_position1, true)
            door = getThingFromPos(toPosition).uid
            doTransformItem(door, door_closed)
        end
    end
 
    for i = 1, #positions2 do
        if fromPosition == positions2[i] then
            doTeleportThing(cid, push_position2, true)
            door = getThingFromPos(toPosition).uid
            doTransformItem(door, door_closed)
        end
    end
return true
end

I could set this code up a lot better if I knew anything about how your map is set up for the door.
 
Don't do it this way. Messing with the door's file is never a good way to do it. The best way would be an onStepIn script that reads where the player walked into the door from. This code can be used to push the player through depending on which side he walked from.

Code:
local positions1 = { --If the player enters the door from these positions it will push him through and close the door.--
[1] = {x = 1000, y = 1000, z = 7},
[2] = {x = 1000, y = 1000, z = 7},
[3] = {x = 1000, y = 1000, z = 7}
}

local push_position1 = {x = 1000, y = 1000, z = 7} --Where the player will be pushed.

local positions2 = { --If the player enters the door from these positions it will push him the other way.--
[1] = {x = 1000, y = 1000, z = 7},
[2] = {x = 1000, y = 1000, z = 7},
[3] = {x = 1000, y = 1000, z = 7}
}

local push_position2 = {x = 1000, y = 1000, z = 7} --Where the player will be pushed.

local door_closed = 1111 -- itemId of the closed door --

function onStepIn(cid, item, fromPosition, itemEx, toPosition)
    for i = 1, #positions1 do
        if fromPosition == positions1[i] then
            doTeleportThing(cid, push_position1, true)
            door = getThingFromPos(toPosition).uid
            doTransformItem(door, door_closed)
        end
    end
 
    for i = 1, #positions2 do
        if fromPosition == positions2[i] then
            doTeleportThing(cid, push_position2, true)
            door = getThingFromPos(toPosition).uid
            doTransformItem(door, door_closed)
        end
    end
return true
end

I could set this code up a lot better if I knew anything about how your map is set up for the door.
he's asking for a key, not a movement script
the key should push the player into the door and the door should only respond to that key
which is of course an action script
after which the door should close behind the player once the player walks out of the doorway
@juansanchez
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if (item.actionid == itemEx.actionid) and (item.itemid ~= itemEx.itemid) then
        doTeleportThing(cid, toPosition, true)
        doTransformItem(itemEx.uid, itemEx.itemid + 1)
    elseif isPlayer(itemEx.uid) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You must use this on a locked door.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is locked.")
    end
    return true
end
XML:
<action actionid="9056" event="script" value="doorkey.lua"/>
then go into your movements xml and look for closingdoor.lua
add the item id your door is if it isn't already there
for example i had to add door id 1222
XML:
<movevent type="StepOut" itemid="1222" event="script" value="closingdoor.lua"/>
you should already have closingdoor.lua since it's default but if you dont:
Lua:
function onStepOut(cid, item, position, fromPosition)
    local newPosition = {x = position.x, y = position.y, z = position.z}
    if(isInArray(verticalOpenDoors, item.itemid)) then
        newPosition.x = newPosition.x + 1
    else
        newPosition.y = newPosition.y + 1
    end

    doRelocate(position, newPosition)
    local tmpPos = {x = position.x, y = position.y, z = position.z, stackpos = -1}
    local tileCount = getTileThingByPos(tmpPos)

    local i = 1
    local tmpItem = {uid = 1}
    while(tmpItem.uid ~= 0 and i < tileCount) do
        tmpPos.stackpos = i
        tmpItem = getTileThingByPos(tmpPos)
        if(tmpItem.uid ~= item.uid and tmpItem.uid ~= 0 and isMoveable(tmpItem.uid)) then
            doRemoveItem(tmpItem.uid)
        else
            i = i + 1
        end
    end

    doTransformItem(item.uid, item.itemid - 1)
    return true
end
you have to set the door and key to the same action id, in my example i used 9056
 
he's asking for a key, not a movement script
the key should push the player into the door and the door should only respond to that key
which is of course an action script
after which the door should close behind the player once the player walks out of the doorway
@juansanchez
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if (item.actionid == itemEx.actionid) and (item.itemid ~= itemEx.itemid) then
        doTeleportThing(cid, toPosition, true)
        doTransformItem(itemEx.uid, itemEx.itemid + 1)
    elseif isPlayer(itemEx.uid) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You must use this on a locked door.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is locked.")
    end
    return true
end
XML:
<action actionid="9056" event="script" value="doorkey.lua"/>
then go into your movements xml and look for closingdoor.lua
add the item id your door is if it isn't already there
for example i had to add door id 1222
XML:
<movevent type="StepOut" itemid="1222" event="script" value="closingdoor.lua"/>
you should already have closingdoor.lua since it's default but if you dont:
Lua:
function onStepOut(cid, item, position, fromPosition)
    local newPosition = {x = position.x, y = position.y, z = position.z}
    if(isInArray(verticalOpenDoors, item.itemid)) then
        newPosition.x = newPosition.x + 1
    else
        newPosition.y = newPosition.y + 1
    end

    doRelocate(position, newPosition)
    local tmpPos = {x = position.x, y = position.y, z = position.z, stackpos = -1}
    local tileCount = getTileThingByPos(tmpPos)

    local i = 1
    local tmpItem = {uid = 1}
    while(tmpItem.uid ~= 0 and i < tileCount) do
        tmpPos.stackpos = i
        tmpItem = getTileThingByPos(tmpPos)
        if(tmpItem.uid ~= item.uid and tmpItem.uid ~= 0 and isMoveable(tmpItem.uid)) then
            doRemoveItem(tmpItem.uid)
        else
            i = i + 1
        end
    end

    doTransformItem(item.uid, item.itemid - 1)
    return true
end
you have to set the door and key to the same action id, in my example i used 9056

Sorry i didn't post my door script when u asked, not sure you need it still.
Regarding the script u sent, it kind of works, only problem is, when you use the key on the door it Adds +1 on the item id, however it doesn't go back to the previous id once you go out. It keeps on adding +1 to the id everytime you use the key on the door.
 
Sorry i didn't post my door script when u asked, not sure you need it still.
Regarding the script u sent, it kind of works, only problem is, when you use the key on the door it Adds +1 on the item id, however it doesn't go back to the previous id once you go out. It keeps on adding +1 to the id everytime you use the key on the door.
that's why i told you to add the movement script.
i tested it and it works fine
 
that's why i told you to add the movement script.
i tested it and it works fine

I did add the door on moveevents.xml, and my closingdoor.lua is the exact same as yours. Not sure if i did something wrong, i'm going to check again.


Edit:

I checked everything, it is all ok, but the problem that i said is still happening.
 
I did add the door on moveevents.xml, and my closingdoor.lua is the exact same as yours. Not sure if i did something wrong, i'm going to check again.


Edit:

I checked everything, it is all ok, but the problem that i said is still happening.
did you register the OPEN door id to the movements.xml?
 
Back
Top