• 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 Help with Door SRIPT [REP+++]

arturhaddad

Member
Joined
Aug 14, 2010
Messages
217
Reaction score
8
1 - A locked door
2 - I use a key on it
3 - It opens
4 - I try to lock it with the key
5 - Receive Key does not match message
6 - I close the door
7 - Door is locked again
8 - I look for help on otland

now, enough joke :]

Does somebody have the correct door script of locking/unlocking it? Like, I gotta use the key on it again to lock it, not just close it...

Thanks a LOT!

My doors.lua

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])
				return true
			end

			doPlayerSendCancel(cid, "The key does not match.")
			return true
		end

		return false
	end
 
Last edited:
ok take man
f(isInArray(keys, item.itemid)) then
if(itemEx.actionid > 0) then
(Why so weakly? > 0) then
if(item.actionid == itemEx.actionid and doors[itemEx.itemid] ~= nil) then
doTransformItem(itemEx.uid, doors[itemEx.itemid])
return true
end

doPlayerSendCancel(cid, "The key does not match.")
return true
end

return false
end
 
And how adding this line would help?

(Why so weakly? > 0) then

Don't joke please, this is serious business... I help ppl in support, one hand washes the other, and I don't make fun of the ppl I try to help
 
Don't joke please, this is serious business...

internet-serious-business-cat.jpg



perhaps posting your entire doors.lua would help? ;)
 
Lua:
local function checkStackpos(item, position)
	position.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
	local thing = getThingFromPos(position)

	position.stackpos = STACKPOS_TOP_FIELD
	local field = getThingFromPos(position)

	return (item.uid == thing.uid or thing.itemid < 100 or field.itemid == 0)
end

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)
		return true
	end

	if(getItemLevelDoor(item.itemid) > 0) then
		if(item.actionid == 189) then
			if(not isPremium(cid)) then
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Only the worthy may pass.")
				return true
			end

			doorEnter(cid, item, toPosition)
			return true
		end

		local gender = item.actionid - 186
		if(isInArray({PLAYERSEX_FEMALE,  PLAYERSEX_MALE, PLAYERSEX_GAMEMASTER}, gender)) then
			if(gender ~= getPlayerSex(cid)) then
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Only the worthy may pass.")
				return true
			end

			doorEnter(cid, item, toPosition)
			return true
		end

		local skull = item.actionid - 180
		if(skull >= SKULL_NONE and skull <= SKULL_BLACK) then
			if(skull ~= getCreatureSkullType(cid)) then
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Only the worthy may pass.")
				return true
			end

			doorEnter(cid, item, toPosition)
			return true
		end

		local group = item.actionid - 150
		if(group >= 0 and group < 30) then
			if(group > getPlayerGroupId(cid)) then
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Only the worthy may pass.")
				return true
			end

			doorEnter(cid, item, toPosition)
			return true
		end

		local vocation = item.actionid - 100
		if(vocation >= 0 and vocation < 50) then
			local playerVocationInfo = getVocationInfo(getPlayerVocation(cid))
			if(playerVocationInfo.id ~= vocation and playerVocationInfo.fromVocation ~= vocation) then
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Only the worthy may pass.")
				return true
			end

			doorEnter(cid, item, toPosition)
			return true
		end

		if(item.actionid == 190 or (item.actionid ~= 0 and getPlayerLevel(cid) >= (item.actionid - getItemLevelDoor(item.itemid)))) then
			doorEnter(cid, item, toPosition)
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Only the worthy may pass.")
		end

		return true
	end

	if(isInArray(specialDoors, item.itemid)) then
		if(item.actionid == 100 or (item.actionid ~= 0 and getPlayerStorageValue(cid, item.actionid) > 0)) then
			doorEnter(cid, item, toPosition)
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
		end

		return true
	end

	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])
				return true
			end

			doPlayerSendCancel(cid, "The key does not match.")
			return true
		end

		return false
	end

	if(isInArray(horizontalOpenDoors, item.itemid) and checkStackpos(item, fromPosition)) then
		local newPosition = toPosition
		newPosition.y = newPosition.y + 1
		local doorPosition = fromPosition
		doorPosition.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
		local doorCreature = getThingfromPos(doorPosition)
		if(doorCreature.itemid ~= 0) then
			local pzDoorPosition = getTileInfo(doorPosition).protection
			local pzNewPosition = getTileInfo(newPosition).protection
			if((pzDoorPosition and not pzNewPosition and doorCreature.uid ~= cid) or
				(not pzDoorPosition and pzNewPosition and doorCreature.uid == cid and isPlayerPzLocked(cid))) then
				doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
			else
				doTeleportThing(doorCreature.uid, newPosition)
				if(not isInArray(closingDoors, item.itemid)) then
					doTransformItem(item.uid, item.itemid - 1)
				end
			end

			return true
		end

		doTransformItem(item.uid, item.itemid - 1)
		return true
	end

	if(isInArray(verticalOpenDoors, item.itemid) and checkStackpos(item, fromPosition)) then
		local newPosition = toPosition
		newPosition.x = newPosition.x + 1
		local doorPosition = fromPosition
		doorPosition.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
		local doorCreature = getThingfromPos(doorPosition)
		if(doorCreature.itemid ~= 0) then
			if(getTileInfo(doorPosition).protection and not getTileInfo(newPosition).protection and doorCreature.uid ~= cid) then
				doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
			else
				doTeleportThing(doorCreature.uid, newPosition)
				if(not isInArray(closingDoors, item.itemid)) then
					doTransformItem(item.uid, item.itemid - 1)
				end
			end

			return true
		end

		doTransformItem(item.uid, item.itemid - 1)
		return true
	end

	if(doors[item.itemid] ~= nil and checkStackpos(item, fromPosition)) then
		if(item.actionid == 0) then
			doTransformItem(item.uid, doors[item.itemid])
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is locked.")
		end

		return true
	end

	return false
end
 
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
 
Cykotitan, the living myth.

There are times where the "add rep" button simply isnt't enough :]

thank you!
 
Last edited:
Cyk, I have a problem with this script

I've found a door that does not work, ID: 10782

I've tried really really hard here to make it work, but it always turn into 10781, and the correct it for it is 10783!

10780 turns into a mushroom and stuff

My items.xml

Lua:
	<item fromid="10765" toid="10774" name="stone floor" />
	<item id="10775" article="a" name="closed door">
		<attribute key="type" value="door" />
		<attribute key="blockprojectile" value="1" />
		<attribute key="description" value="It is locked." />
	</item>
	<item id="10776" article="a" name="closed door">
		<attribute key="type" value="door" />
		<attribute key="blockprojectile" value="1" />
	</item>
	<item id="10777" article="an" name="open door">
		<attribute key="type" value="door" />
	</item>
	<item id="10780" article="a" name="gate of expertise">
		<attribute key="type" value="door" />
		<attribute key="levelDoor" value="1000" />
		<attribute key="blockprojectile" value="1" />
	</item>
	<item id="10781" article="a" name="gate of expertise">
		<attribute key="type" value="door" />
	</item>
	<item id="10782" article="a" name="closed door">
		<attribute key="type" value="door" />
		<attribute key="blockprojectile" value="1" />
	</item>
	<item id="10783" article="an" name="open door">
		<attribute key="type" value="door" />
	</item>
	<item id="10784" article="a" name="closed door">
		<attribute key="type" value="door" />
		<attribute key="blockprojectile" value="1" />
		<attribute key="description" value="It is locked." />
	</item>
	<item id="10785" article="a" name="closed door">
		<attribute key="type" value="door" />
		<attribute key="blockprojectile" value="1" />
	</item>
	<item id="10786" article="an" name="open door">
		<attribute key="type" value="door" />
	</item>
	<item id="10789" article="a" name="gate of expertise">
		<attribute key="type" value="door" />
		<attribute key="levelDoor" value="1000" />
		<attribute key="blockprojectile" value="1" />
	</item>
	<item id="10790" article="a" name="gate of expertise">
		<attribute key="type" value="door" />
	</item>
	<item id="10791" article="a" name="closed door">
		<attribute key="type" value="door" />
		<attribute key="blockprojectile" value="1" />
	</item>
	<item id="10792" article="an" name="open door">
		<attribute key="type" value="door" />
	</item>

Any of those items works

my actions.xml

Lua:
	<action fromid="10775" toid="10777" event="script" value="other/doors.lua"/>
	<action fromid="10780" toid="10786" event="script" value="other/doors.lua"/>
	<action fromid="10789" toid="10792" event="script" value="other/doors.lua"/>
 
yeah I'm feeling retarded, but I couldn't do it lol

the doors I'm trying to add, they increase an ID, instead of decrease, and I swear I tried really hard and couldn't make it, I've tried for like 25 min, I'm noob at scripting but I can visualize and read the code, modify etc, and I couldn't add these fuc*** doors, i'm feeling retarded
 
I know it sounds lazy, but I really tried to add this, I spent 20~30 min trying and always got wrong ID and stuff

hippo_bump.jpg
 
Back
Top