• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Open sesame door

tiddpd

PHP Scripter
Joined
Apr 16, 2008
Messages
331
Reaction score
0
When you say "opensesame" the door will open. To keep it locked and only able to open with "opensesame" give the door an action id which will lock it. (This is for TFS 0.3)

Add this to talkactions.xml:
Code:
	<talkaction words="opensesame" script="open.lua"/>

In scripts put this and name it open.lua:
Code:
function onSay(cid, param)
local standPos = {x=459,y=199,z=7}
local doorPos = {x = 459, y = 198, z = 7, stackpos=1}
local door = getThingFromPos(doorPos)

    if comparePos(getPlayerPosition(cid), standPos) then
        if door.itemid == 5138 then
            doTransformItem(door.uid, door.itemid + 1)
        elseif comparePos(getPlayerPosition(cid), standPos) then
            doCreatureAddHealth(cid, -500, force)
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
        end
    end 
end

You should also add this to lib/functions.lua
Code:
function comparePos(pos1, pos2)
return (pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z)
end

If you want it to close, put an action id on the floor below the door, and use this script (you have to change locations and door ids to the ones you use)

Code:
function onStepIn(cid, item, position, fromPosition)
	local doorPos = {x = 459, y = 198, z = 7, stackpos=1}
	local door = getThingFromPos(doorPos)
	
	if door.itemid == 5139 then
		doTransformItem(door.uid, door.itemid - 1)
		doPlayerSendTextMessage(cid,25,"The door has shut behind you!")
else
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
	end
end

Updated as of Fed 16th, added in the teleport player function. (you will walk to the door when opensesame is said)
 
Last edited:
This one should work.

PHP:
function onSay(cid, param)
local standPos 	= {x=457,y=199,z=7} --where you have to be standing to open--
local doorPos 	= {x = 457, y = 198, z = 7, stackpos=1} --position of door--
local door 		= getThingFromPos(doorPos)
local timer 	= 5 -- time to make the door close/reappear in seconds--

	if comparePos(getPlayerPosition(cid), standPos) then
		if door.itemid == 5138 then --i used 5138 as the door, you can use whatever door you want.--
			doTransformItem(door.uid, door.itemid + 1)
			addEvent(reappear, timer*1000)
		else
			doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
        end
	end 
end

function reappear()
local doorPos = {x = 457, y = 198, z = 7, stackpos=1}
local door = getThingFromPos(doorPos)

	if door.itemid == 5139 then
		doTransformItem(door.uid, door.itemid - 1)
		return 1
	else
		return 1
	end
end
 
Did you correctly change all the item ids and set the right coordinates. It's a common mistake. I've had it happen a few times too, wondering why the script didn't work when I just made a typo with an item id. ^^

I have not tested my version, but it should work. o.o
 
No, it doesn't. It's a function that is just supposed to work with this script so there's no need to put it into the global functions.
 
console give me this
[13/02/2009 13:57:10] Lua Script Error: [TalkAction Interface]
[13/02/2009 13:57:10] data/talkactions/scripts/quest/doorquest.lua:onSay

[13/02/2009 13:57:10] data/talkactions/scripts/quest/doorquest.lua:7: attempt to call global 'comparePos' (a nil value)
[13/02/2009 13:57:10] stack traceback:
[13/02/2009 13:57:10] data/talkactions/scripts/quest/doorquest.lua:7: in function <data/talkactions/scripts/quest/doorquest.lua:1>
 
console give me this
[13/02/2009 13:57:10] Lua Script Error: [TalkAction Interface]
[13/02/2009 13:57:10] data/talkactions/scripts/quest/doorquest.lua:onSay

[13/02/2009 13:57:10] data/talkactions/scripts/quest/doorquest.lua:7: attempt to call global 'comparePos' (a nil value)
[13/02/2009 13:57:10] stack traceback:
[13/02/2009 13:57:10] data/talkactions/scripts/quest/doorquest.lua:7: in function <data/talkactions/scripts/quest/doorquest.lua:1>
That basically means you do not have the comparePos function.

PHP:
local config = {
    tilePosition = { x = 100 , y = 100 , z = 7 } -- Position where the player has to stand for the function to execute.
    doorPosition = { x = 200 , y = 200 , z = 7 , stackpos = 1 } -- Position of the door.
    reappearTime = 5 -- The time (in seconds) for the door to reappear.
    doorItemID    = 5138 -- The item id of the door.
}

function onSay(cid, words, param)
    local tmp = getPlayerPosition(cid)
    local door = getThingfromPos(config.doorPosition)
    if tmp.x == config.tilePosition.x and tmp.y == config.tilePosition.y and tmp.z == config.tilePosition.z then
        if door.itemid == config.doorItemID then
            doTransformItem(door.uid, door.itemid + 1)
            addEvent(reappear, config.reappearTime * 1000)
            doSendMagicEffect(tmp, 12)
        else
            doSendMagicEffect(tmp, 2)
        end
    end
    return TRUE
end

function reappear()
    local door = getThingfromPos(config.doorPosition)
    if door.itemid == config.doorItemID + 1 then
        doTransformItem(door.uid, config.doorItemID)
    end
    return TRUE
end
 
a little fix now no problems in console
but still not work the script the door dont open


PHP:
local config = {
    tilePosition = { x = 374 , y = 2273 , z = 7 }, -- Position where the player has to stand for the function to execute.
    doorPosition = { x = 372 , y = 2272 , z = 7 , stackpos = 1 }, -- Position of the door.
    reappearTime = { 5 },-- The time (in seconds) for the door to reappear.
    doorItemID   = { 5139 } -- The item id of the door.
}
 
function onSay(cid, words, param)
    local tmp = getPlayerPosition(cid)
    local door = getThingfromPos(config.doorPosition)
    if tmp.x == config.tilePosition.x and tmp.y == config.tilePosition.y and tmp.z == config.tilePosition.z then
        if door.itemid == config.doorItemID then
            doTransformItem(door.uid, door.itemid + 1)
            addEvent(reappear, config.reappearTime * 1000)
            doSendMagicEffect(tmp, 12)
        else
            doSendMagicEffect(tmp, 2)
        end
    end
    return TRUE
end

function reappear()
    local door = getThingfromPos(config.doorPosition)
    if door.itemid == config.doorItemID + 1 then
        doTransformItem(door.uid, config.doorItemID)
    end
    return TRUE
end
 
yeah the script works fine, its just a little touchy, you have to have all the positions correct, and you have to make sure you also added comparePos to functions.lua or global.lua

and for the door to close i just had a tile that you step on ahead of the door that closes it
 
Last edited:
I wanted a script like this... But i want it to remove a wall... And then after like 5 seconds replace the wall..... I tried editing myself but it doesnt work... Also i am using TFS 0.2.10
 
Back
Top