ID:169496
 
i need to make a turf that allows a player to go one direction but not the other, so i no it'd be like...
turf
oneway
Entered()

but i dont the the commands, would it be like usr.dir? or how do i do it?

In Enter() (and you want Enter() instead of Entered() because you're deciding if it should enter) the object entering is the argument, so you use it's dir variable.

turf
cant_enter_from_the_north
Enter(mob/M)
if(istype(M) && M.dir == NORTH) // If it's a mob and it's facing north...
return 0 // don't let it in.
return ..()


Since I'm making sure only mobs can't enter from the north, /objs will be able to move through the turf normally.
In response to YMIHere
ok thnx, but im kinda making a sidscrolling game, and i changed the line to make it so i cannot go west, but my guy kinda falls thru the ground now O.o, what do i do?
In response to Bladeshifter
turf
Cantgodown
Exit(mob/M)
if(istype(M) && M.dir == South) // If it's a mob and it's facing South
return 0 // don't let it leave.
else
return ..()

try that it should work for what want
In response to Deathstar175
Deathstar175 wrote:
turf
> Cantgodown
> Exit(mob/M)
> if(istype(M) && M.dir == South) // If it's a mob and it's facing South
> return 0 // don't let it leave.
> else
> return ..()
>

try that it should work for what want

Well, no. You're checking for "if(M.dir == South)", which is completely invalid. See, the ten directions (eight cardinals plus UP and DOWN) are defined like so (taken from [link]):

//directions
var/const
NORTH = 1
SOUTH = 2
EAST = 4
WEST = 8
NORTHEAST = 5
NORTHWEST = 9
SOUTHEAST = 6
SOUTHWEST = 10
UP = 16
DOWN = 32


All of them are in caps, as you can see. Since DM, like most languages, is case-sensitive, your snippet actually wouldn't compile.

This one would work:

//don't allow mob entry from the north
turf/no_fall/Enter(mob/M)
if(istype(M) && M.dir == SOUTH) return 0
return ..()
In response to Wizkidd0123
Out of interest, would this work too?

turf/no_fall/Enter(mob/M)
if(istype(M) && M.dir == 2) return 0
return ..()
In response to DeathAwaitsU
Yes -- that would work!

For more details about directions, see EightDirections (bwicki page).
In response to Wizkidd0123
Ah well that simplifies my life a lot.
In response to DeathAwaitsU
DeathAwaitsU wrote:
Ah well that simplifies my life a lot.

Remember though -- just because numbers can be used instead of the constants doesn't mean that you should. Doing so would make your code a lot harder to read.

There's no reason, however, that the bitwise operators shouldn't make everything a whole lot simpler, if that's what you meant! =)
Or, a way Garthor displayed it before:
var/list/nodirs=list(/turf/nonorth=NORTH,/turf/nosouthwest=list(SOU\
TH,WEST,SOUTHWEST))
turf
Enter(mob/m)
if(!(ismob(m))||!m.client)return
if(m.dir in nodirs[src])return 0
return ..()
nonorth
nosouthwest


I think that's how he did it, I can't remember.
[edit]Bleh, I had to fix something, I forgot to put /turf/ in the beginning!