ID:176178
 
mob
Bump(var/atom/O)//when you bumb an obj mob or turf
if(istype(O,/mob))//if its a mob
var/mob/M = O//mob/M=O
if(!M.client)//if its an NPC
if(M.pushold == 1)//if its a pushable old person
usr<< sound('bump.wav')
M.Move(get_step(M,src.dir),src.dir)
usr.Move(get_step(M,src.dir),src.dir)// <----- heres the problem
M.irritated = 1
return 1

else
return 0
this is my bump proc that when you bump and old person they get "pushed" and face the direction your facing, i want it that when you push the old person you occupy the space where the old person was facing the direction of the oldperson. I tried this but instead of moving behind the oldperson i appeared infront of the old person. How can i do this without defining what will happen with each direction.
I dunno if you can use this, as a read over your question quickly i tought you maybe could use it.
___________________________________________________________

Format:
step_away(Ref,Trg,Max=5)

Returns:
1 on success; 0 otherwise.

Args:
Ref: A mob or obj.
Trg: An object on the map.
Max: The maximum distance between Ref and Targ before
movement halts.

Move Ref on a path away from location Trg, taking obstacles into account. If Ref is farther than Max steps from Trg, no action will be taken.
usr.Move(get_step(M,src.dir),src.dir)

heres what i was talking about theres something worng with this, i want to step to the npc(M) and keep my direction... but its not working
In response to Erdrickthegreat2
oh srry, i tought you where just having problems with the puching away thing. I am srry but i can't help u.
Erdrickthegreat2 wrote:
usr.Move(get_step(M,src.dir),src.dir)// <----- heres the problem

Well duh. You put in usr instead of src. usr is wrong in Bump(). src is correct. That's not the problem you're having, but it's a problem all its own. Do not put usr in Bump().

You also need to consider that M.Move() might not work. If it returns 0 or null, then you were unable to push any further and calling Move() again will put you in an infinite loop.

Now, the reason you're ending up ahead of the old person is that you called get_step() the exact same way as before, using M as the point of reference. Since M.loc will have changed if the last Move() worked, you need to usr src as the point of reference.
if(M.Move(get_step(M,dir),dir))
// this should call Move() for you
step(src,dir)

Lummox JR
In response to Lummox JR
heres my current code on it, currently it does the action i wanted it to but theres always something wrong.


mob
Bump(var/atom/O)//when you bumb an obj mob or turf
if(istype(O,/mob))//if its a mob
var/mob/M = O//mob/M=O
if(!M.client)//if its an NPC
if(M.pushold == 1)//if its a pushable old person
if(src.chill == 1)
src<< sound('bump.wav')
M.Move(get_step(M,src.dir),src.dir)//it moves the direction you bump it and faces the direction your facing
src.Move(get_step(src,M.dir),M.dir)

M.irritated = 1//that makes it mad! aka says something different
src.chill = 0
return 1//OK!
if(src.chill == 0)
spawn(1)
sleep(1)
src.chill = 1

return 1//IT WORKS
else//if its not an NPC
return 0// no cookie for you

and i get these errors from this code at runtime

runtime error: Maximum recursion level reached (perhaps there is an infinite loop)

Erdrickthegreat2 (/mob): Bump(Oldman (/mob/Oldman))
Erdrickthegreat2 (/mob): Move(the grass (6,9,1) (/turf/grass), 1)


I know you explained something about the infinite loop lummoxJR but i didnt understand.
In response to Erdrickthegreat2
Just think about it for a second...
X: wall
O: Old guy
@: You


XXXXXXX
...O...
...@...
.......


Now, assuming you're pushing the old guy straight up. He'll run into a wall, Move() will return 0, and he won't go anywhere. Then, you Move() as well. But, the old man is in the way, so you Bump() him. Since he's an old man, you can push him, so he Move()s to the north, fails the movement, doesn't move, and then you Move() as well. You then Bump() into the old man, which Move()s him, which then Move()s you....

Get it? So, instead of both those Move() things...
<code>if(step(M,dir)) ..()</CODE>
In response to Garthor
so id right it

if(step(M,dir)) ..()


wha? call the if statement before you call the movement?

.....
In response to Erdrickthegreat2
Ok so to stop the infinate loop from happening, i need to check whether or not im pushing the NPC into a wall.... Ok, so thats where the

if(step(M,dir)) ..()

comes from... so how would i use that then... I mean If the step goes through, then have the players mob move?
In response to Erdrickthegreat2
That's where ..() comes in. That will call the default movement procedure.
In response to Garthor
....so where would i add it? when i replace the two moves, the player doesnt move..See i want him to follow NPC the way i had it it worked except for the infinite loop, but i have no idea how to fix that.. anyone can help me out? i've tried everything.
In response to Erdrickthegreat2
mob
Bump(var/atom/O)//when you bumb an obj mob or turf
if(ismob(O))//if its a mob
var/mob/M = O//mob/M=O
if(!M.client)//if its an NPC
if(M.pushold == 1)//if its a pushable old person
src<< sound('bump.wav')
if(step(M,dir)) ..()
M.irritated = 1
In response to Garthor
well i did that but my player character doesnt move with the NPC.. i want it to look like the player chacter is pushing the NPC around so that they are always in contact with eachother during the push. The code help you gave me garthor doesnt help me in that sense, your system works fine but the player just doesnt follow the npc.
In response to Erdrickthegreat2
Erdrickthegreat2 wrote:
well i did that but my player character doesnt move with the NPC.. i want it to look like the player chacter is pushing the NPC around so that they are always in contact with eachother during the push. The code help you gave me garthor doesnt help me in that sense, your system works fine but the player just doesnt follow the npc.

This snippet should work..
atom/proc/Bumped()
mob/Bump(atom/A)
..()
A.Bumped(src)
mob/old_person
Bumped(var/mob/M)
if(!ismob(M)) return
if(!src.client && src.pushold)
if(step(src,M.dir)) ..()
step(M,M.dir)
src.irritated = 1


~>Volte
In response to Erdrickthegreat2
Ugh, no wonder. I was thinking that it was inside of a Move() proc, not a Bump() proc. You'd need a <code>step(src,dir)</code> instead of the ..() . I need to get more sleep. =P