• 0

# NPC that pushes away the player

## Question

I'm trying to do a npc that pushes away the player, whatever the direction the player comes from. I know it can work if i put the specific coordinates but i want to replicate it so i need something that will work in any map. I tried this for start.

```prontera,50,50,0	script	push	99,3,3,{
OnTouch:
getmapxy(@mapname\$, @mapx, @mapy, BL_PC);
getmapxy(@mapnamee\$, @x, @y, BL_NPC);

if (@mapx = @x - 3 & @mapy = @y | @mapy = @y + 1 | @mapy = @y +2 | @mapy = @y - 1 | @mapy = @y -2 ) { pushpc DIR_WEST, 2; end; }
if (@mapx = @x - 2 & @mapy = @y - 3 | @mapx = @x - 1 & @mapy = @y - 3 | @mapx = @x & @mapy = @y - 3 | @mapx = @x + 1 & @mapy = @y - 3 | @mapx = @x + 2 & @mapy = @y - 3) { pushpc DIR_SOUTH, 2; end; }

}```

This is supposed to push west if the player approach the npc from the left and push south if the player approach from below.
But only the West push works and the South push is pushing West.

Please correct me what im doing wrong, thanks.

## Recommended Posts

• 0
```guild_vs2,50,50,5	script	#asdf	HIDDEN_WARP_NPC,3,3,{
end;
OnTouch:
getmapxy .@map\$, .@x, .@y, UNITTYPE_PC;
dispbottom .@x +" "+ .@y;
if ( .@x == 47 )
pushpc DIR_WEST, 1;
else if ( .@x == 53 )
pushpc DIR_EAST, 1;
else if ( .@y == 47 )
pushpc DIR_SOUTH, 1;
else if ( .@y == 53 )
pushpc DIR_NORTH, 1;
end;
}```

hercules code, you know how to convert

##### Share on other sites
• 0
1 hour ago, AnnieRuru said:
```guild_vs2,50,50,5	script	#asdf	HIDDEN_WARP_NPC,3,3,{
end;
OnTouch:
getmapxy .@map\$, .@x, .@y, UNITTYPE_PC;
dispbottom .@x +" "+ .@y;
if ( .@x == 47 )
pushpc DIR_WEST, 1;
else if ( .@x == 53 )
pushpc DIR_EAST, 1;
else if ( .@y == 47 )
pushpc DIR_SOUTH, 1;
else if ( .@y == 53 )
pushpc DIR_NORTH, 1;
end;
}```

hercules code, you know how to convert

So clean! with some modifications i made it work at any coordinates, thanks!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.