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

CreatureEvent Set Passwords to Doors

Limos

Senator
Premium User
Joined
Jun 7, 2010
Messages
10,013
Solutions
8
Reaction score
3,055
Location
Netherlands
Tested with TFS 0.3.6pl1 8.54

creaturescripts.xml
XML:
<event type="textedit" name="Password" event="script" value="passdoors.lua"/>

Add this to login.lua
Lua:
	registerCreatureEvent(cid, "Password")

passdoors.lua
Lua:
-- Passwords to doors by Limos
local uniqueids = {8049, 8050}

local passwords = {
	["hell"] = {doorpos = {x = 1000, y = 1000, z = 7}, doorid = 6253, blackboardpos = {x = 1000, y = 1000, z = 7}, blackboardid = 1811, uniqueid = 8049, doorclosetime = 10}, 	
	["stars"] = {doorpos = {x = 1000, y = 1000, z = 7}, doorid = 1213, blackboardpos = {x = 1000, y = 1000, z = 7}, blackboardid = 1811, uniqueid = 8050, doorclosetime = 10} 
}
 
function onTextEdit(cid, item, newText)

	local x = passwords[newText]

	local function onCloseDoor()
		if(getTileItemById(x.doorpos,x.doorid+1).uid) > 0 then
			doTransformItem(getTileItemById(x.doorpos,x.doorid+1).uid, x.doorid)
			doSendMagicEffect(x.doorpos, CONST_ME_MAGIC_RED)
		end
	end

	for _, check in pairs(uniqueids) do
		if item.uid == check then
			if x and item.uid == x.uniqueid then
				if(getTileItemById(x.doorpos,x.doorid).uid) > 0 then
					doTransformItem(getTileItemById(x.doorpos,x.doorid).uid, x.doorid + 1)
					doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Your password "'..newText..'" is correct, you can now enter.')
    					addEvent(onCloseDoor,x.doorclosetime*1000)
					doRemoveItem(item.uid, 1)
					local blackboard = doCreateItem(x.blackboardid,1,x.blackboardpos)
					doItemSetAttribute(blackboard, "uid", x.uniqueid)
				else
					doRemoveItem(item.uid, 1)
					local blackboard = doCreateItem(x.blackboardid,1,x.blackboardpos)
					doItemSetAttribute(blackboard, "uid", x.uniqueid)
					doPlayerSendCancel(cid, 'The door is already open, be quick or wait till it is closed.')
				end
			else
				doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)    
				doPlayerSendCancel(cid, 'Your password "'..newText..'" is not correct.')
			end
		end
	end
	return true
end

How does it work:

1. Add an unique id to the blackboard. The unique id in the blackboard must be the same as the uniqueid in the password line.
Also add an action id to the door (for example 101) to make it locked, so people can't enter on the normal way.
Fllm88.png


2. If the ids and positions in the script are correct, you can type the password in the blackboard.
VWZFDZ.png


3. If the password is correct, the password will be removed from the blackboard, the door goes open and will automaticly close after 10 seconds if no one closed it.
IOBtCN.png


4. If the password isn't correct, you will get a cancel message that it isn't correct.
5. You can add a tp inside for people to go back.


If you want to add more passwords for other doors, you can just add a new line. Don't forget to also add the new unique ids in the local uniqueids then.
Questions or bugs? Let me know.
 
Last edited:
Damn that's really cool i will use this for sure!
 
Instead of using a TP to get out, you could also use a form of "key card" system. Once the player enters, they are provided with an item that allows them to exit (and enter if you wish) as much as they please, or once. ;)

Good release, I like it.
 
waw! It's amazing!
Thanks for this relase 0.0!
 
Thanks for the comments.

Instead of using a TP to get out, you could also use a form of "key card" system. Once the player enters, they are provided with an item that allows them to exit (and enter if you wish) as much as they please, or once. ;)

Good release, I like it.

Thought of something similar too, only thing is, it's possible for others to enter too before the door gets closed if they stand next to the person who enters the password, so those people will get stuck then.
 
Last edited:
Thought of something similar too, only thing is, it's possible for others to enter too before the door gets closed if they stand next to the person who enters the password, so those people will get stuck then.

Set an event for the tile under the door to only allow those with access (who have written the password) to enter by using a storage value. You could also simply use the tile event to shut the door behind the player and push them out of the way (into the room). :thumbup:
 
I did it like this so the people who know the password can choose if they let other people in, or for things like quests that the group can enter without having to add the password one by one.

If people want to only let the person who wrote the password to enter they can use a gate of expertise and add:
Lua:
doTeleportThing(cid, x.doorpos)
I could add something like the key card for that, but it depense on how people want it what to add.
 
Last edited:
Tested with TFS 0.3.6pl1 8.54

creaturescripts.xml
XML:
<event type="textedit" name="Password" event="script" value="passdoors.lua"/>

Add this to login.lua
Lua:
    registerCreatureEvent(cid, "Password")

passdoors.lua
Lua:
-- Passwords to doors by Limos
local uniqueids = {8049, 8050}
 
local passwords = {
    ["hell"] = {doorpos = {x = 1000, y = 1000, z = 7}, doorid = 6253, blackboardpos = {x = 1000, y = 1000, z = 7}, blackboardid = 1811, uniqueid = 8049, doorclosetime = 10},    
    ["stars"] = {doorpos = {x = 1000, y = 1000, z = 7}, doorid = 1213, blackboardpos = {x = 1000, y = 1000, z = 7}, blackboardid = 1811, uniqueid = 8050, doorclosetime = 10}
}
 
function onTextEdit(cid, item, newText)
 
    local x = passwords[newText]
 
    local function onCloseDoor()
        if(getTileItemById(x.doorpos,x.doorid+1).uid) > 0 then
            doTransformItem(getTileItemById(x.doorpos,x.doorid+1).uid, x.doorid)
            doSendMagicEffect(x.doorpos, CONST_ME_MAGIC_RED)
        end
    end
 
    for _, check in pairs(uniqueids) do
        if item.uid == check then
            if x and item.uid == x.uniqueid then
                if(getTileItemById(x.doorpos,x.doorid).uid) > 0 then
                    doTransformItem(getTileItemById(x.doorpos,x.doorid).uid, x.doorid + 1)
                    doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_GREEN)
                    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Your password "'..newText..'" is correct, you can now enter.')
                        addEvent(onCloseDoor,x.doorclosetime*1000)
                    doRemoveItem(item.uid, 1)
                    local blackboard = doCreateItem(x.blackboardid,1,x.blackboardpos)
                    doItemSetAttribute(blackboard, "uid", x.uniqueid)
                else
                    doRemoveItem(item.uid, 1)
                    local blackboard = doCreateItem(x.blackboardid,1,x.blackboardpos)
                    doItemSetAttribute(blackboard, "uid", x.uniqueid)
                    doPlayerSendCancel(cid, 'The door is already open, be quick or wait till it is closed.')
                end
            else
                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)   
                doPlayerSendCancel(cid, 'Your password "'..newText..'" is not correct.')
            end
        end
    end
    return true
end

How does it work:

1. Add an unique id to the blackboard. The unique id in the blackboard must be the same as the uniqueid in the password line.
Also add an action id to the door (for example 101) to make it locked, so people can't enter on the normal way.
Fllm88.png


2. If the ids and positions in the script are correct, you can type the password in the blackboard.
VWZFDZ.png


3. If the password is correct, the password will be removed from the blackboard, the door goes open and will automaticly close after 10 seconds if no one closed it.
IOBtCN.png


4. If the password isn't correct, you will get a cancel message that it isn't correct.
5. You can add a tp inside for people to go back.


If you want to add more passwords for other doors, you can just add a new line. Don't forget to also add the new unique ids in the local uniqueids then.
Questions or bugs? Let me know.


I know my question is very late :D
but if I want player to add his password ??
can it be
 
If the passwords are with numbers you can let people set an actionid to the door, then if the door has an actionid check if it's the password they type in the blackbord.
 
Posible 1.0 distro?
Yes it's possible but you would have to use doSetItemActionId instead of doItemSetAttribute :p

Cool script, Limos. ;)
 
Nice Script I will see what I can Use it from my server :)


Best Regards
mlody.1039
 
So, where would I put that line in the code so only the person who got the password right could go in? This could be really cool for future quests.
 
That doesn't matter, you can add it anywhere after the password is correct.
 
Back
Top