ID:270692
 
I am just wondering how I would go about checking the density of a turf two tiles away from a mob.

§atans§pawn
It depends. Do you want to check all of the turfs two tiles away from the mob?

-Exophus
In response to Exophus
No, I just meant the square two tiles ahead of the mob.

§atans§pawn
In response to Satans Spawn
There's probably an easier reason, but I am tired.. It's 5:02 AM and I didn't sleep yet. :(
for(var/turf/T in world)
if(T.x==src.x&&get_dist(src,T)==2)
//do everything here...
//If it were anything but an area or turf you should add a break here in case there are multiple objects or mobs in that tile.
In response to Satans Spawn
Think something along the lines of:

  // Alright, let's cut to the chase:
// We want to get the turf two in front of us.
// Here are the things we need to do:
// NORTH: Y + 2
// SOUTH: Y - 2
// WEST: X - 2
// EAST: X + 2
// NORTHEAST: X + 1, Y + 1
// SOUTHEAST: X + 1, Y - 1
// NORTHWEST: X - 1, Y + 1
// SOUTHWEST: X - 1, Y - 1

var/turf/T = locate( ( dir == EAST ? x + 2 : ( dir == WEST ? x - 2 : ( dir == NORTHEAST || dir == SOUTHEAST ? x + 1 : ( dir == NORTHWEST || dir == SOUTHWEST ? x - 1 : x ) ) ) ), ( dir == NORTH ? y + 2 : ( dir == SOUTH ? y - 2 : ( dir == NORTHEAST || dir == NORTHWEST ? y + 1 : ( dir == SOUTHEAST || dir == SOUTHWEST ? y - 1 : y ) ) ) ), z )


It's one massive line, but I'm fairly certain it might get what you want done. Uh, it's highly unreadable, but I sort of explained what I did up above it. You might want to go over it again and make sure I did it all correctly, as it's 5 AM and I'm somewhat tired. ~_~
In response to Satans Spawn
The problem with both of your codes (as far as I know) is that turfs do not have an x value to compare with mine, otherwise this crisis would have been averted... :( but thatnks anywho :D

§atans§pawn
In response to Satans Spawn
Where are you placing this stuff? Mine should work nicely as long as it can access a mob's x, y, and z.
In response to Satans Spawn
I just realized mine wouldn't have worked for what you wanted anyways. X_x I misunderstood.. Like I said.. Tired. I could've done that method a lot better, too. Dunno what I was thinking.

-Exophus
In response to Audeuro
Audeuro wrote:
Where are you placing this stuff? Mine should work nicely as long as it can access a mob's x, y, and z.

turf
Outside
Fence
name="Fence"
icon='Fence.dmi'
icon_state="1"
density=1
Click()
if(get_dist(src,usr)==1)
switch(get_dir(usr,src))
if(NORTH)
usr.dir=NORTH
usr.loc=locate(usr.x,usr.y+1,usr.z)
spawn(3)
usr.loc=locate(usr.x,usr.y+1,usr.z)
if(SOUTH)
usr.dir=SOUTH
usr.loc=locate(usr.x,usr.y-1,usr.z)
spawn(3)
usr.loc=locate(usr.x,usr.y-1,usr.z)
if(EAST)
usr.dir=EAST
usr.loc=locate(usr.x+1,usr.y,usr.z)
spawn(3)
usr.loc=locate(usr.x+1,usr.y,usr.z)
if(WEST)
usr.dir=WEST
usr.loc=locate(usr.x-1,usr.y,usr.z)
spawn(3)
usr.loc=locate(usr.x-1,usr.y,usr.z)


Basically, I want to check to see if the player is able to hop over a fence or not... This is still the very early stages of the game, so I plan on making it better, but for now this is just to find out how to do it and then elaborate it.

§atans§pawn
In response to Satans Spawn
So are you trying to check the space on the other side of the fence, or what?
In response to Audeuro
get_step(get_step(somemob,somemob.dir),somemob.dir)?
In response to Jp
I managed to sesolve my issue, I will post my code later on today so that I can get it critiqued, and possibly optimized as well, thanks :D

§atans§pawn
In response to Satans Spawn
Here is my current code. I didn't write an optimized code, obviously, I just went with something that would work, and this does just that. However, I am now looking for ways that this can be optimized. Any suggestions are welcome.

turf
Outside
Fence
name="Fence"
icon='Fence.dmi'
icon_state="1"
density=1
Click()
if(get_dist(src,usr)==1)
switch(get_dir(usr,src))
if(NORTH)
var/fail=0
for(var/atom/t in block(locate(usr.x,usr.y+2,usr.z),locate(usr.x,usr.y+2,usr.z)))
if(t.density)
fail=1
for(var/mob/m in locate(usr.x,usr.y+2,usr.z))
if(m.density)
fail=1
if(!fail)
usr.dir=NORTH
usr.loc=locate(usr.x,usr.y+1,usr.z)
spawn(3)
usr.loc=locate(usr.x,usr.y+1,usr.z)
if(SOUTH)
var/fail=0
for(var/turf/t in block(locate(usr.x,usr.y-2,usr.z),locate(usr.x,usr.y-2,usr.z)))
if(t.density)
fail=1
for(var/mob/m in locate(usr.x,usr.y-2,usr.z))
if(m.density)
fail=1
if(!fail)
usr.dir=SOUTH
usr.loc=locate(usr.x,usr.y-1,usr.z)
spawn(3)
usr.loc=locate(usr.x,usr.y-1,usr.z)
if(EAST)
var/fail=0
for(var/turf/t in block(locate(usr.x+2,usr.y,usr.z),locate(usr.x+2,usr.y,usr.z)))
if(t.density)
fail=1
for(var/mob/m in locate(usr.x+2,usr.y,usr.z))
if(m.density)
fail=1
if(!fail)
usr.dir=EAST
usr.loc=locate(usr.x+1,usr.y,usr.z)
spawn(3)
usr.loc=locate(usr.x+1,usr.y,usr.z)
if(WEST)
var/fail=0
for(var/turf/t in block(locate(usr.x-2,usr.y,usr.z),locate(usr.x-2,usr.y,usr.z)))
if(t.density)
fail=1
for(var/mob/m in locate(usr.x-2,usr.y,usr.z))
if(m.density)
fail=1
if(!fail)
usr.dir=WEST
usr.loc=locate(usr.x-1,usr.y,usr.z)
spawn(3)
usr.loc=locate(usr.x-1,usr.y,usr.z)


§atans§pawn
In response to Satans Spawn
First of all, get rid of all of the direction checks. You should be able to use get_step() to get the turf in a certain direction instead of using locate(). Also, block() returns turfs, so you your failure check will not always be correct.

turf/outside/fence
Click()
if(src == get_step(usr, usr.dir))
var/turf/check = get_step(src, usr.dir)
if(check.density) return // is the destination dense?
for(var/atom/A in check)
if(A.density) return // are there any dense objects in the destination?
usr.loc = src // set the player's loc onto the fense
spawn(3)
usr.loc = check // then set them to the destination


~~> Unknown Person
In response to Unknown Person
I replaced my stuff with yours, but it doesn't seem to be working. I will continue playing with it, but from what I can figure out is it won't get past "if(src in get_step(usr, usr.dir))". I put in a check of world<<src under that line and indented properly, but there is no output.

§atans§pawn
In response to Satans Spawn
Sorry, I forgot that src was a turf. Since get_step() returns a turf, you have to compare src with the get_step(). I modified my original post.

~~> Unknown Person
In response to Unknown Person
Awsome, that seems to have done it. Thank you muchly.

§atans§pawn