• 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:
Oh so you're all grown up and mature? Okey! ;)

AND who buys script? I haven't seen too many!

AND Worked 100% for me :D

Let's stop this forum fights now?:)
 
this Key Id:
PHP:
5135

Actions.xml
PHP:
<action itemid="2091" script="keyttaquest.lua" />

This is Door and Key script:
PHP:
function onUse(cid, item, frompos, item2, topos)

local pausa = 1000

local door = {x=812, y=1202, z=7, stackpos=1}
local ddoor = getThingfromPos(door)

local open_door = 5136

local itemU = 2091

local verify = 0 

if item2.uid == itemU then
if ddoor.itemid ~= verify then
doTransformItem(ddoor.uid,open_door)
addEvent(close,pausa,door)
end
else
doPlayerSendCancel(cid,"This key can not be used here")
end
return 1
end

function close(door)

local to_close_door = 5135

local the_close_door = getThingfromPos(door)
doTransformItem(the_close_door.uid,to_close_door)
end

This is door id:
PHP:
2091
End , hope you like it !
 
Back
Top