ID:272880
 
I am making a technique in my game that repulses a person away from the user, how would i code that? I know it is a simple peice of code, i have done it before, but i cant remember how...
var/original_dir = X.dir
if(step(X, turn(original_dir,180)))
X.dir = original_dir
Makes X step back (180 degrees [opposite] of its dir) and, after moving, sets the dir back to what it was prior the move
In response to GhostAnime
ok, im not 100% sure if thats what im looking for.. i mean all i want to do is push them away from the user. Say im a mob, and regaurdless of the targets direction, pushes him back like 3 squares. so not just make him moves opposite his direction, just away from the user
In response to Roxas_KeyBlade
for(var/steps in 1 to 3)
step(M,get_step(src,M)) //Move M away from src 3 times.
sleep(1)
In response to Kaiochao
step(M,get_step(src,M))


step is supposed to take a direction as second argument, while get_step supposedly returns a location.
So, am I missing something here, or shouldn't this be working?
In response to GhostAnime
You can preserve the original dir without extra work by expanding the step() call into a Move() call instead, and using its 2nd argument.
X.Move(get_step(X,turn(X.dir,180)),X.dir)

EDIT: Completed code.
In response to Kaioken
X.Move(turn(X.dir,180),X.dir)


Uhm, either I'm completely dumb now, or this code should not work. Move should take a location as first argument, while turn is supposed to return a direction.
In response to Schnitzelnagler
Yes, I forgot the get_step() part; that's how it is with multiple nested proc calls. Sometimes after you finish one you think you're done. xD
In response to Kaioken
Why not do something like;
walk_away(M,src,1,0)
In response to VolksBlade
I'd say that depends on how pushing into dense objects is supposed to be handled by the original poster.
In response to Schnitzelnagler
Sorry, I meant get_dir().
In response to Kaiochao
In that case, caching the result outside the loop might be a smart move, in order to avoid calling it thrice, since the result shouldn't change ;)
You could even break the loop when step returns 0, avoiding unnecessary calls (especially since the proc sleeps).

Kaiochao wrote with slight edit:
var/d = get_dir(src,M)
for(var/steps in 1 to 3)
if(!step(M,d))
break
sleep(1)


Edit:
Or, the Kaioken way, using Move:
var/d = get_dir(src,M)
for(var/steps in 1 to 3)
if(!M.Move(get_step(M,d),M.dir))
break
sleep(1)

Note, it might be better to use get_dir, than turn, since there is no warranty that the mob you want to push away from the user was facing her before.