• 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 script [need support]

ond

Veteran OT User
Joined
Mar 24, 2008
Messages
2,782
Solutions
25
Reaction score
491
Location
Sweden
I wonder if, first if it's possible, and if someone could help me fix my key-door script. I want it to get locked again if someone uses the key on it after opening it up ;)

For dumb people:
When you unlock door with key -> close the door -> it's still open -> it should only get locked if you use the key on it again

Here is my scripts:

LUA:
--keys--

function onUse(cid, item, frompos, item2, topos)

	if item.actionid > 0 and item.actionid == item2.actionid then
		match = 1
	else
		match = 0
	end

	if item2.itemid == 1210 or  
		item2.itemid == 1213 or
		item2.itemid == 1219 or
		item2.itemid == 1221 or
		item2.itemid == 1223 or
		item2.itemid == 1225 or
		item2.itemid == 1227 or
		item2.itemid == 1229 or
		item2.itemid == 1232 or
		item2.itemid == 1235 or
		item2.itemid == 1237 or
		item2.itemid == 1239 or
		item2.itemid == 1241 or
		item2.itemid == 1243 or
		item2.itemid == 1245 or
		item2.itemid == 1247 or
		item2.itemid == 1250 or
		item2.itemid == 1253 or
		item2.itemid == 1255 or
		item2.itemid == 1257 or
		item2.itemid == 1249 or
		item2.itemid == 1261 then

		if match == 1 then
			doTransformItem(item2.uid,item2.itemid+1)
		else
			doPlayerSendCancel(cid,"The key does not match.")
		end
	elseif item2.itemid == 1209 or
		item2.itemid == 1212 or
		item2.itemid == 1231 or
		item2.itemid == 1234 or
		item2.itemid == 1249 or
		item2.itemid == 1252 then

		if match == 1 then
			doTransformItem(item2.uid,item2.itemid+2)
		else
			doPlayerSendCancel(cid,"The key does not match.")
		end
	else
		return 0
	end
end

LUA:
function onUse(cid, item, frompos, item2, topos)
	if(item.actionid == 0) then
		-- This is impossible to happen, but whatever.
		doTransformItem(item.uid, item.itemid+2)
		return TRUE
	end

	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is locked.")
	return TRUE
end

LUA:
function onUse(cid, item, frompos, item2, topos)
	-- Are we on pz?
	local isPz = (getTilePzInfo(frompos) == 1)

	-- Get the tile to move the things on the door to
	local nextTile = {x=frompos.x, y=frompos.y+1, z=frompos.z}
	if(isPz and getTilePzInfo(nextTile) == 0) then
		nextTile.y = frompos.y-1
	end

	-- Move all moveable things to the next tile
	doRelocate(frompos, nextTile)

	-- Transform the door
	doTransformItem(item.uid, item.itemid-1)
	return TRUE
end

LUA:
function onUse(cid, item, frompos, item2, topos)
	-- Are we on pz?
	local isPz = (getTilePzInfo(frompos) == 1)

	-- Get the tile to move the things on the door to
	local nextTile = {x=frompos.x+1, y=frompos.y, z=frompos.z}
	if(isPz and getTilePzInfo(nextTile) == 0) then
		nextTile.x = frompos.x-1
	end

	-- Move all moveable things to the next tile
	doRelocate(frompos, nextTile)

	-- Transform the door
	doTransformItem(item.uid, item.itemid-1)
	return TRUE
end

LUA:
-- ActionIDs:
-- 1001~1999: Level doors(level is actionID-1000)
-- 2001~2008: Vocation doors(voc is ActionID-2000. 1:Sorcerer, 2:Druid, 3:Paladin, 4:Knight, 5:MS, 6:ED, 7:RP, 8:EK)

function onUse(cid, item, frompos, item2, topos)
	local isLevelDoor = (item.actionid >= 1001 and item.actionid <= 1999)
	local isVocationDoor = (item.actionid >= 2001 and item.actionid <= 2008)

	if not(isLevelDoor or isVocationDoor) then
		-- Make it a normal door
		doTransformItem(item.uid, item.itemid+1)
		return TRUE
	end

	local canEnter = true
	if(isLevelDoor and getPlayerLevel(cid) < (item.actionid-1000)) then
		canEnter = false
	end

	if(isVocationDoor) then
		local doorVoc = item.actionid-2000
		if (doorVoc == 1 and not(isSorcerer(cid))) or
		   (doorVoc == 2 and not(isDruid(cid)))    or
		   (doorVoc == 3 and not(isPaladin(cid)))  or
		   (doorVoc == 4 and not(isKnight(cid)))   or
		   (doorVoc ~= getPlayerVocation(cid))     then
			canEnter = false
		end
	end

	if not(canEnter or getPlayerAccess(cid) == 0) then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Only the worthy may pass.")
		return TRUE
	end

	doTransformItem(item.uid, item.itemid+1)
	local canGo = (queryTileAddThing(cid, frompos, bit.bor(2, 4)) == RETURNVALUE_NOERROR) --Veryfies if the player can go, ignoring blocking things
	if not(canGo) then
		return FALSE
	end

	local dir = getDirectionTo(getPlayerPosition(cid), frompos)
	doMoveCreature(cid, dir)
	return TRUE
end

LUA:
	<!-- Doors -->
	<action itemid="1209" script="doors/door_locked.lua"/>
	<action itemid="1210" script="increment.lua"/>
	<action itemid="1211" script="doors/door_open_horizontal.lua"/>
	<action itemid="1212" script="doors/door_locked.lua"/>
	<action itemid="1213" script="increment.lua"/>
	<action itemid="1214" script="doors/door_open_vertical.lua"/>

	<action itemid="1219" script="increment.lua"/>
	<action itemid="1220" script="doors/door_open_horizontal.lua"/> 
	<action itemid="1221" script="increment.lua"/>
	<action itemid="1222" script="doors/door_open_vertical.lua"/>

	<action itemid="1227" script="doors/gateofexp_closed.lua"/>
	<action itemid="1228" script="doors/door_open_horizontal.lua"/>
	<action itemid="1229" script="doors/gateofexp_closed.lua"/>
	<action itemid="1230" script="doors/door_open_vertical.lua"/>

	<action itemid="1231" script="doors/door_locked.lua"/>
	<action itemid="1232" script="increment.lua"/>
	<action itemid="1233" script="doors/door_open_horizontal.lua"/>
	<action itemid="1234" script="doors/door_locked.lua"/>
	<action itemid="1235" script="increment.lua"/>
	<action itemid="1236" script="doors/door_open_vertical.lua"/>

	<action itemid="1237" script="increment.lua"/>
	<action itemid="1238" script="doors/door_open_horizontal.lua"/> 
	<action itemid="1239" script="increment.lua"/>
	<action itemid="1240" script="doors/door_open_vertical.lua"/>

	<action itemid="1241" script="doors/questdoor_closed.lua"/>
	<action itemid="1242" script="doors/door_open_horizontal.lua"/>
	<action itemid="1243" script="doors/questdoor_closed.lua"/>
	<action itemid="1244" script="doors/door_open_vertical.lua"/>

	<action itemid="1245" script="doors/gateofexp_closed.lua"/>
	<action itemid="1246" script="doors/door_open_horizontal.lua"/>
	<action itemid="1247" script="doors/gateofexp_closed.lua"/>
	<action itemid="1248" script="doors/door_open_vertical.lua"/>	

	<action itemid="1249" script="doors/door_locked.lua"/>
	<action itemid="1250" script="increment.lua"/>
	<action itemid="1251" script="doors/door_open_horizontal.lua"/>
	<action itemid="1252" script="doors/door_locked.lua"/>
	<action itemid="1253" script="increment.lua"/>
	<action itemid="1254" script="doors/door_open_vertical.lua"/>

	<action itemid="1255" script="doors/questdoor_closed.lua"/>
	<action itemid="1256" script="doors/door_open_horizontal.lua"/>
	<action itemid="1257" script="doors/questdoor_closed.lua"/>
	<action itemid="1258" script="doors/door_open_vertical.lua"/>

	<action itemid="1259" script="doors/gateofexp_closed.lua"/>
	<action itemid="1260" script="doors/door_open_horizontal.lua"/>
	<action itemid="1261" script="doors/gateofexp_closed.lua"/>
	<action itemid="1262" script="doors/door_open_vertical.lua"/>


	<action itemid="1539" script="increment.lua"/>
	<action itemid="1540" script="doors/door_open_horizontal.lua"/> 
	<action itemid="1541" script="increment.lua"/>
	<action itemid="1542" script="doors/door_open_vertical.lua"/>

	<action itemid="1223" script="doors/questdoor_closed.lua"/>
	<action itemid="1224" script="doors/door_open_horizontal.lua"/>
	<action itemid="1225" script="doors/questdoor_closed.lua"/>
	<action itemid="1226" script="doors/door_open_vertical.lua"/>
Kind of simpile. I think these are the scripts for it. Help me!
 
Last edited:
you must edit the door script too.

do_it_faggot_2.jpg
 
I could sell ya the script :)

it's working for all doors :)

This video confirm that I got the script, and it's made by me of course =)

YouTube - clip0001.avi

Edit:
Very easy to set up/change. :)

Edit2: with this offer I can include how to fix keys without C++ ;)

[old] 15:00 You see a key. it weight 0.1 oz.
[new] 15:00 You see a key. (key 3501) it weight 0.1 oz.

:)
 
Last edited:
I see you are some how, more or less, retarded, dear RealSoft :D

not at all.. nice of you to go on the "insult" side..

I asked you a question.. by the way, if you call me retard, then what are you that can't solve a simple door script for yourself?

but sure. don't count with me helping with anything in your threads if you call me retard without any reason.
you end up as KingDanny, I dunno how many times those idiots have been begging for help after they have been calling me stupid things over the forums ;)
 
PHP:
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
 
WTF realsoft hahahah!!!!!! Are you trying to sell some simple door scripts? wtf is wrong with you?
Cheap tard.

why would I give away a door script that is working like real tibia without any buggs or failure ids in it?
like all scripts I've seen here is having crap scripts and most of them are NOT like real tibia..

and how can you say "try sell" and how can you call me retard without know the price? ;)

I've sold many scripts.. and I will sell many more.. I'm not doing everything for free...
 
I got one like real tibia :) just because you're so nice, I will post it here for ya!

LUA:
function onUse(cid, item, frompos, item2, topos)
	if (item2.actionid == 0 or
	   (isInArray(LOCKED_DOORS, item2.itemid) == FALSE and
	    isInArray(LOCKED_DOORS, item2.itemid-1) == FALSE and
		isInArray(LOCKED_DOORS, item2.itemid-2) == FALSE)) then
		return FALSE
	end

	local canOpen = (item.actionid == 10000 or item.actionid == item2.actionid)
	if not(canOpen) then
		doPlayerSendCancel(cid, "The key does not match.")
		return TRUE
	end

	-- Verify if you are opening or closing the door
	if(isInArray(LOCKED_DOORS, item2.itemid) == TRUE) then -- Opening
		doTransformItem(item2.uid, item2.itemid+2)
	elseif(isInArray(LOCKED_DOORS, item2.itemid-2) == TRUE) then -- Closing and Locking
		doTransformItem(item2.uid, item2.itemid-2)
	else                                                   -- Locking an already closed door
		doTransformItem(item2.uid, item2.itemid-1)
	end
	return TRUE
end
 
not at all.. nice of you to go on the "insult" side..

I asked you a question.. by the way, if you call me retard, then what are you that can't solve a simple door script for yourself?

but sure. don't count with me helping with anything in your threads if you call me retard without any reason.
you end up as KingDanny, I dunno how many times those idiots have been begging for help after they have been calling me stupid things over the forums ;)

Your question was kind of dumb!;)
 
Back
Top