ID:166218
 
Well im working on a game called Gauntlet and i cant seem to figure out how to have it so that when you walk over the key you pick it up then its added to your inv. then walking up to a door and unlocking it. if u can help please reply.
-Thanks Gumiebear
Well, one method would be making both the key and door dense, thus when the mob walks into it, call the Bump() proc to verify if it's a door/key. If it's a key, move it to the mob's inventory or if it's a door, check if the key is in the mob's contents, and if it is, open the door...


Procs needed to be looked up in this method:
Bump()
locate()
Move()

- GhostAnime
In response to GhostAnime
ugh i dont know how =( ill have to try some mores
In response to Gumiebear
Here is an EXAMPLE... read, learn, ask questions ;) Like any eample, this may not be an efficient one but the point of examples is to convey the meaning, rather than the result...wellm most of the times anyways... I think...
item/keys
icon='key.dmi'
density=1//item is dense.. meaning people can't walk pass it... important for Bump() to work
var/unlock//eh some var I made for keys to unlock

key2
name="Steel door key"
unlock="steel" //lets say this unlocks only steel doors

Door
var/locked//lets say to unlock this door, you need the same key as the locked one
Steel
icon='steel door.dmi'
density=1
dir=NORTH//Lets say that its blocking the way from continuing NORTHwards
locked="steel"

mob/Bump(atom/O)//lets say if you did mob/M, you MUST do safetychecks to make sure it is a mob.. such as using ismob()
if(istype(O,/item)) O.Move(src) //if it's an item, it'll go into the usr's contents
else if(istype(O,/Door))
var/Door/D=O//so we don't get any annoying errors (note that locked is only in /Door and unlock is only in item/key)
if(D.locked)//if the door is "locked" (TRUE)
for(var/item/keys/K in src)//checks usr's contents for any keys
if(K.unlock==D.locked)//if the key unlocks this door
D.locked=null//door is unlocked
del(K)//item is deleted
break //stops the loop from continuing, as we already openned the door
else src.Move(step(D,D.dir))//Moves the usr 1 step north from the unlocked door


- GhostAnime
Gumiebear wrote:
Well im working on a game called Gauntlet

Incidentally, so am I.

and i cant seem to figure out how to have it so that when you walk over the key you pick it up then its added to your inv. then walking up to a door and unlocking it. if u can help please reply.
-Thanks Gumiebear

These procs are especially helpful:

turf/Entered(A)
..()
for(var/atom/O in src.contents)
O.Trigger(A)

atom/proc/Trigger(atom/movable/A)
return

atom/movable/Bump(atom/A)
A.Bumped(src)
return

atom/proc/Bumped(atom/movable/A)
return


Then just have it so when you move over a key, it calls key.Trigger(), and when the key is triggered, it moves to the player's contents.

When unlocking a door, you can use door.Bumped(player), then just search for the proper key in their inventory. If they have it, then set the door to its unlocked state.