ID:261437
 
Sup Its me Green Limey again :)
I have a door but I wanted 2 doors one u need a key to open the other u can just open. I have no Idea how to do this I was thinking maybe somthing with the isobj(usr.contents) proc but I probley am not even close.

My key type is obj/key and my door is obj/lockdoor.
Could U please post me somthing. thanks
Green Lime wrote:
Sup Its me Green Limey again :)
I have a door but I wanted 2 doors one u need a key to open the other u can just open. I have no Idea how to do this I was thinking maybe somthing with the isobj(usr.contents) proc but I probley am not even close.

My key type is obj/key and my door is obj/lockdoor.
Could U please post me somthing. thanks

obj/lockdoor
Enter()
if(/obj/key in usr.contents)
..()
else
usr << "its locked"

obj/lockdoor2
Enter()
usr << "its locked"


-Sariat
In response to Sariat
Thanks Sariat I will add u to the helpers list if u want?
In response to Green Lime
Sure, just don't keep telling me and others that you taught me to code >=)

I owe that mainly to Shadowdarke :)
In response to Sariat
hmmmm
lock()
set src in oview(1)
if(/obj/key in usr.contents)
src:locked=1
view() << "[usr.name] locks the door."
else
usr << "You dont have the key."
Thats my code well When ever I have the key and I try and lock a door it always says You dont have the key. Any ideas?
In response to Green Lime
Thats my code well When ever I have the key and I try and lock a door it always says You dont have the key. Any ideas?

That's because Sariat was blindingly wrong with "if(/obj/key in usr.contents)". =)

You have to actually search for the key in usr.contents and assign the first one found to a variable. If that variable is null, then they don't have a key -- otherwise, they contain the key.

Here's a sample:

obj/key
var/unlocks = "Door001"

turf/door
var/doorname = "Door001"

Click()
var/obj/key/key
for(key in usr.contents)
if(key.unlocks == src.doorname)
break //sticks this object into the key variable

if(key)
//He has a key for this door!
else
//He doesn't have a key for this door!


That should help.