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

Locked Door that requires a key

poopsiedoodle

Gibe moni plos
Joined
Nov 23, 2011
Messages
2,452
Reaction score
580
Location
Georgia
no specific key ID here, but, could someone maybe give me an example of a script for a locked door that you need a key for?
 
Set an actionId to the key and the same actionId to the door. The default door script in TFS should work.

Or you can try this script I found by searching:

Lua:
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,
	[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, [5107] = 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] = -2,
	[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
 
Back
Top