ID:146164
 
Code:
mob
verb
Repulsion()
var/mob/M
for(M in oview(1))
step(M,usr.dir)


Problem description:

The problem is there not getting pushed the right direction. I want it so if there diagonal of me they move diagonally away and if there to the right of me they move away right. If that makes sense.The problem is usr.dir i think but i have no idea what to replace it with. Thanks in advance if anyone can help me.
Turles9000 wrote:
Code:
> mob
> verb
> Repulsion()
> var/mob/M
> for(M in oview(1))
> step(M,usr.dir)
>

Problem description:

The problem is there not getting pushed the right direction. I want it so if there diagonal of me they move diagonally away and if there to the right of me they move away right. If that makes sense.The problem is usr.dir i think but i have no idea what to replace it with. Thanks in advance if anyone can help me.

Obviously using usr.dir makes them step in the player's direction.

WHY is everybody using usr ? Use src!

I think you could look up the step_away proc for this one, so basically something like:

mob
verb
Repulsion()
for(var/mob/M in oview(1,src))
step_away(M,src,2)


Although I am unsure if the 3rd arg in step_away should be 1 or 2, because I never really use it. Just know that it's there.

Hiead
In response to Hiead
Well, that 3rd argument could be used to set a maximum for how far away someone can be repulsed.

P_S
In response to Prodigal Squirrel
Prodigal Squirrel wrote:
Well, that 3rd argument could be used to set a maximum for how far away someone can be repulsed.

Yes, I know that, but I don't know if it should be set to 1 or 2 to have them step away once. I think it's 2, though.

Hiead
In response to Hiead
Thanks it works but i have a new problem. If there's a wall for example in the way of where they would be repulsed they would move the wrong direction. I wanted it so if there's something there that they wont move at all. I was thinking i could use get_step_away but it doesnt seem to work, here's my code.(I may have a totally wrong idea of how get_step_away works)

mob
verb
Repulsion()
for(var/mob/M in oview(1,src))
var/turf/a = get_step_away(M,src,2)
if(a.density)
..()
else
step_away(M,src,2)
In response to Hiead
Hiead wrote:
WHY is everybody using usr ? Use src!

Because it's a verb. usr is completely fine within a verb.
In response to Turles9000
Bump, Can anyone help?
In response to Turles9000
Turles9000 wrote:
Thanks it works but i have a new problem. If there's a wall for example in the way of where they would be repulsed they would move the wrong direction. I wanted it so if there's something there that they wont move at all. I was thinking i could use get_step_away but it doesnt seem to work, here's my code.(I may have a totally wrong idea of how get_step_away works)

The best thing I could think of immediately is to check each direction manually.

mob
verb
Repulsion()
var/list/dirs = list(NORTHWEST,NORTH,NORTHEAST,EAST,SOUTHEAST,SOUTH,SOUTHWEST,WEST)
for(var/direction in dirs)
for(var/mob/M in get_step(src,direction))
step(M,direction)


Although I think somebody (Dantom? Deadron?) has a library that contains a proc to find the direction from A to B.

Hiead