ID:179584
 
How could i make it so when you go through a door that you need a key for and you have it,How could i make the key get deleted from the usr inventory once you use it
Thanx
Greg wrote:
How could i make it so when you go through a door that you need a key for and you have it,How could i make the key get deleted from the usr inventory once you use it
Thanx

Find the key in the inventory (read back on how to find an item in the inventory), delete it, and let them in.
Greg wrote:
How could i make it so when you go through a door that you need a key for and you have it,How could i make the key get deleted from the usr inventory once you use it

Try this:
turf/keydoor
var/keycolor

Enter(M)
for(var/obj/key in M)
if(key.keycolor==src.keycolor) return ..()
return 0

Entered(M)
for(var/obj/key in M)
if(key.keycolor==src.keycolor)
del(key)
break
// replace the door with a blank turf
var/turf/keydoor/door=src
src=new /turf/floor(src)
M.loc=src
del(door)
src.Entered(M)

obj/key
var/keycolor

This uses keys of various colors, so you could have a red door with a red key, etc. It's actually easier to check for a specific key, but this way is more common to lots of games.

The above code is untested; I've never messed with modifying turfs at runtime before, so you might want to try it and tweak it as necessary.

Lummox JR
In response to Lummox JR
Enter(M)
for(var/obj/key in M)
if(key.keycolor==src.keycolor) return ..()

I got a question, when your defining the mob/M and using it as Enter (M), where are you defining this?
Is it a global path?
or something like mob/M, obj/O, turf/T, area/A???

LJR
In response to LordJR
LordJR wrote:
Enter(M)
for(var/obj/key in M)
if(key.keycolor==src.keycolor) return ..()

I got a question, when your defining the mob/M and using it as Enter (M), where are you defining this?

He didn't define it as mob, but it was a quick snippet to demonstrate the concept. You would probably want to make sure it's a mob, but since the only other thing that could ever trigger Enter() is an obj it wouldn't be much of a problem. Unless of course some clever adventurer stuffs the key in a bag and throws the bag through the doorway to open it from a distance. ;)

Is it a global path?
or something like mob/M, obj/O, turf/T, area/A?

No, these aren't global defaults, but they have become an unofficial tradition in BYOND snippets. :)