ID:1385178
 
(See the best response by FIREking.)
Code:


Problem description:
How would i go about and make a turf/obj/atom that can only be entered from one direction? I am trying to make single tile houses that can only be entered from one direction, one way would be by checking wether the house is in the correct direction relative to the player, but that is hard since i dont know how to check what is adjacent to something.

Help!
Use Enter().

In the Enter() proc, you can check what direction the mob that is trying to enter is facing. If it is the right direction, let them in.

Enter(atom/o)
// you can only enter from the south, so you would be facing NORTH to go into it
if(o.dir == NORTH)
..()
return FALSE
In response to Albro1
return ..() would be best here, since you want it to return what the parent does.
You could make a parent proc to handle all atoms and just have it refer to a list or bitflags of an atom. I was actually thinking about doing this myself- I'll post what I come up with later.
Best response
Here's something I use a lot for tile based games

turf
var
moves = NORTH | SOUTH | EAST | WEST

Enter(atom/movable/a)
if(!a.loc) return ..()
var/move = get_dir(src, a)
if((src.moves & move) != move)
return 0
return ..()

Exit(atom/movable/a)
if((src.moves & a.dir) != a.dir)
return 0
return ..()

proc/get_density()
if(density) return 1
for(var/atom/a in src)
if(a.density)
return 1
return 0

proc/check_enter_move(atom/movable/a)
var/move = get_dir(src, a)
if((src.moves & move) != move)
return 0
return 1

proc/check_exit_move(atom/movable/a)
if((src.moves & a.dir) != a.dir)
return 0
return 1


Set the moves var to handle which directions you want to allow

Example:

turf/NS_tunnel //north south tunnel
moves = NORTH | SOUTH
yoink
In response to Kitsueki
If you have an atom that isn't dense though, that would not work.
In response to Albro1
Regardless, Enter() does no movement. The movement system reads its return value in Move(). You're only returning FALSE.
Enter returns 1 or 0, either let them in or don't. Returning FALSE in Enter means "don't let them in". Or am I wrong?
In response to Albro1
That's right. The code you provided is wrong.
In response to Albro1
Albro1 wrote:
Enter returns 1 or 0, either let them in or don't. Returning FALSE in Enter means "don't let them in". Or am I wrong?

TRUE is just a compile-time constant that equates to 1, while FALSE is a compile-time constant that equates to 0.
In response to FIREking
Would this allow me to change the directions you can enter from on the fly? As if in a guy were to lock the door?
Yes. Bit-shifting is pretty simple:

Turn a bit on: (or)

mask |= bit

Turn a bit off: (and inverse)

mask &= ~bit

toggle a bit: (xor)

maks ^= bit

If you are confused about how it works, a bit of light reading on binary math would probably do you some good.
In response to Ter13
Um...I know?
In response to Albro1
Albro1 wrote:
Um...I know?

Oh wait... Rhetorical questions at 3:30 in the morning... You'd have thought that would have occurred to me.
Please forgive me, and may any potential deities have mercy upon my soul for doing this, but I HAVE to make this joke...

turf
OnlyEnterFromOneDirection
Enter(mob/M)
if(M.name in list("Zayn","Niall","Liam","Harry","Louis")
return ..()
return 0


Again, please forgive me. I'm not even sure that I can ever forgive myself, but the compulsion was too great. (in my defense, I had to look their names up!)
In response to SuperSaiyanGokuX
You have sinned, Brother.
Huh... And here I thought boy bands were something only my generation was blighted with...
In response to Albro1
To clarify, the statement "..()" is not a return statement. It doesn't cause anything to be returned at that line, so your code follows through to the "return FALSE" line (which isn't even necessary), regardless of what happens at the ..() line, which effectively does nothing.

The reason we want to return ..() instead of TRUE is so we bump into other dense objects that may be on the turf already.
Oh, the boy band tradition has carried on throughout the years. Pop culture is never short of at least one omnipresent (yet horrendously awful) boy band. When one breaks up (usually due to the only member with any semblance of real talent breaking off to do his own thing, and/or puberty setting in and ruining their voices past the point that auto-tune can help), there are always a few more waiting in the wings.

Thankfully, I'm far enough removed from the current music scene that I only know of this one thanks to constant media bombardment (as per usual with every boy band; plus this one even comes with its own feature film!) and my brain's (sometimes unfortunate) ability to absorb virtually every piece of data that floats through it, welcome or not.

Anyway, now that I've gotten the joke out of my system, we can all go back to pretending boy bands don't exist.
Page: 1 2