ID:266720
 
i tryed amking it so that when u get a key a var is activated for only u but i cant get that to work. how can i get it to work or is there another way to make a door only open if u have a key?..... or if u cant show me the code or u r just mean then maybe u could at least tell me a demo on this
Magnus VI wrote:
i tryed amking it so that when u get a key a var is activated for only u but i cant get that to work. how can i get it to work or is there another way to make a door only open if u have a key?.....

That there is. You can use the locate() proc to check if the player has a key in his inventory. Here's an example.
obj/key

turf/door
verb/use()
var/obj/key/K = locate() in usr.contents
if(K)
//open
else
usr << "It's locked."

Of course, there are several other ways to do this, but that's how I do it ;). You'll also want to check for seeing if the door is locked, too, or else a lot of people are going to need keys for unlocked doors ;)

=V
In response to Vortezz
//is this right?
obj/jaildoor
icon = 'jail.dmi'
icon_state = "closed"
density = 1

Click()
var/obj/K = locate() in usr.contents
if(K)
src.icon_state = "open"
src.density = 0
icon = 'cobble16.dmi'
sleep(50)
src.icon_state = "closed"
src.density = 1
icon = 'jail.dmi'
else
usr << "Its Locked"
//it looks correc t to me, but it sez that else is inconsistently indented/.... can u help?
ps if and else are on the same row as are usr<< its locked and src.iconstateetc..
You may want to consider associating the key with the door. What I mean, is something like this:
key
parent_type=/obj/ // so we dont have to use the path /obj/key

var

WoodenDoor_Opener

MagicDoor_Opener
DoorFive


door
parent_type=/obj/

var
KeyType=/key/ // path for the key needed

Enter(O)
if(!istype(O,/mob/)) ..() // only for mobs
var/mob/M=O
var/key/K = locate(KeyType) in M.contents
if(K) ..() // they have the key, so let them through.


WoodenDoor
KeyType=/key/WoodenDoor_Opener/
MagicDoor
KeyType=/key/MagicDoor_Opener/
DoorFive
KeyType=/key/MagicDoor_Opener/DoorFive/



This allows you to have a 'mastery key' for doors, and keys that only work for specific doors(Look up locate(). It searches the current path, and all its children.).

Try and think of it like this:
           Master Key
!
!
!!!!!!!
! !
! !
DoorFive DoorSix


The Master Key will open both DoorFive and DoorSix. But DoorFive will only open DoorFive.
In response to Alathon
wuts Parnet_type or wutever and can u fix my poorly indented code
In response to Magnus VI
the else part needs to be indented more. Also, inconsistant indentation means you're using different indentation throughout your code. Like a single tab here, two space there, etc.