ID:1500685
 
(See the best response by Magnum2k.)
Code:
mob/player
Bump(atom/movable/O)


Problem description:

I can't figure out past this line of code on how to make players push each other around by bumping into them and sort of make them bounce-back.

It's a survival type game where you can't fall into the lava and this is sort of an added "competitive" concept to it.

You can use the step() function to push O in the direction src is stepping in.
LordAndrew is right. 'step()' is an excellent built-in proc to use.

I'll write down in basic codes what he is talking about.

mob/player
Bump(atom/movable/O)
if(src.dir==NORTH)//opposite direction of O.
step(O,SOUTH)//opposite direction of src.
return 0
if(src.dir==SOUTH)//opposite direction of O.
step(O,NORTH)//opposite direction of src.
return 0//then repeat the rule.
if(src.dir==EAST)
step(O,WEST)
return 0
if(src.dir==WEST)
step(O,EAST)
return 0


Seem about right to you LordAndrew?

You don't need those if statements at all, though. For the opposite direction, use turn().
mob/player
Bump(atom/movable/O)
if(src.dir==NORTH)//opposite direction of O.
step(O,SOUTH)//opposite direction of src.
O.dir=NORTH
return 0
if(src.dir==SOUTH)//opposite direction of O.
step(O,NORTH)//opposite direction of src.
O.dir=SOUTH
return 0//then repeat the rule.
if(src.dir==EAST)
step(O,WEST)
O.dir=EAST
return 0
if(src.dir==WEST)
step(O,EAST)
O.dir=WEST
return 0

If you want them to look like they've stepped backwards...
Notice the pattern between each-other's direction.
@FKI, you do need if functions. Even with turn(), you'll need it. It needs to go to the opposite direction of the src, not wrong direction which is what we don't want to have.
In response to Audio freak XD
Then why is the code giving me 13 inconsistent indentations? It makes no sense as I'm positive everything is formatted correctly.

mob/player
Bump(atom/movable/O)
if(src.dir==NORTH)//opposite direction of O.
step(O,SOUTH)//opposite direction of src.
O.dir=NORTH
return 0
if(src.dir==SOUTH)//opposite direction of O.
step(O,NORTH)//opposite direction of src.
O.dir=SOUTH
return 0//then repeat the rule.
if(src.dir==EAST)
step(O,WEST)
O.dir=EAST
return 0
if(src.dir==WEST)
step(O,EAST)
O.dir=WEST
return 0
Go back and re-tab them.
In response to Audio freak XD
There we go. Thank you!
Your code is quite extensive. Now, I know I'm one of the incompetent "coders" for not having the next big MMO on BYOND under my belt and thus I shouldn't be giving out advice, especially since I'm not making a six figure salary from game design, but, I'd listen to FKI and remove those if statements. If you really want to use an if statement, you should just check if you're bumping a mob via and then make use of turn().
Best response
mob/player
Bump(mob/player)
player.dir = turn(src.dir, 180)
step(player, src.dir)
Oh, maybe you can do it without if statements.
One uppers, pfffttt! jk
In response to Audio freak XD
Not only that, but my code only moves players. ;)
@Lige,

You CAN use if statements, but I guess it's less excessive in the work to use turn(). What I thought turn() did was move to src.dir and turn around the player to the degree.

But, he wanted the player to face the same direction, and move the opposite direction. Like stepping backwards, I think.
In response to Magnum2k
Magnum2k wrote:
Not only that, but my code only moves players. ;)

You, my friend, are not correct on this statement. If BYOND accepting type overloading, then this would be correct, but it doesn't.