ID:140459
 
Code:
mob/proc

TELEPORT(mob/M)
if(prob(50))
Move(locate(M.x-rand(2, 8), M.y-rand(2, 8), M.z))
else
Move(locate(M.x+rand(2, 8), M.y+rand(2, 8), M.z))

M.Move(get_step(usr, usr.dir))
flick('Zanzo.dmi', M)
flick('Zanzo.dmi', src)


M.dir=get_dir(M, src)


Problem description:
Basically, everything works fine until the usr teleports and is facing a dense tile, or a map boundry. When that happens, the M just doesn't teleport to infront of the player. How would I go about solving this problem?

hmm, if u want teleport the M to the user use something like this:

mob/verb/Teleport(mob/M as mob in world)
M.x=usr.x-1
M.y=usr.y
M.<=usr.z
In response to Revolution Gohan
Or just M.loc = get_step(src, dir).
In response to Kaiochao
mob/proc

TELEPORT(mob/M)
if(prob(50))
Move(locate(M.x-rand(2, 8), M.y-rand(2, 8), M.z))
else
Move(locate(M.x+rand(2, 8), M.y+rand(2, 8), M.z))

M.Move(get_step(usr, usr.dir))
flick('Zanzo.dmi', M)
flick('Zanzo.dmi', src)


M.dir=get_dir(M, src)

As you can see, I have M.Move(get_step(usr, usr.dir)). This will make the mob move, as long as the move proc permits it.
But they can't move onto a dense tile or out of bounds, due to the Move() proc.

But, when the usr is FACING a dense tile, the Move() proc will be canceled. How do I make the usr change to a different direction upon detecting the dense tile or map boundry? This way, he will change dir, and the M will be able to teleport.
In response to Strong123488
I guess you could use a loop. Remember that Move() returns 0 when it fails, and 1 when it succeeds.
mob/verb
TELEPORT(mob/m)
while(!Move(locate( //while you can't move(loop breaks when successful)
m.x + rand(2,8) * pick(1,-1), //split up for readability
m.y + rand(2,8) * pick(1,-1), m.z))) //math helps!
continue //not really doing much in the loop itself

//if you like diagonal directions
for(var/d in 0 to 7) //8 directions, not including current direction
//basically checks all dirs, and goes to the next clockwise direction
if(M.Move(get_step(src, turn(dir, 45 * d))))
break //break loop when it works

//or if you don't like diagonal directions
for(var/d in 0 to 3)
if(M.Move(get_step(src, turn(dir, 90 * d)))
break

flick('Zanzo.dmi', M)
flick('Zanzo.dmi', src)

M.dir = get_dir(M, src)

I haven't tested it, and it's likely it won't work (due to my half-guessing with math stuff), but that's basically how I'd do it.

Of course, this code assumes you're not completely surrounded by dense tiles. Won't break or anything, just won't work as intended.