Check In Front Of Player

I'm fiddling with the base scripts and seeing what I can come up with,

Just curious how you guys would check the position directly in front of the player?

Let's say I was looking to figure out the region right in front, and print it to msgbox.

Code:
 f_x = $game_map.x_with_direction($game_player.x, $game_player.direction)
    f_y = $game_map.y_with_direction($game_player.y, $game_player.direction)
    msgbox_p($game_map.region_id(f_x, f_y))

I saw this 'x_with_direction' and also 'round_x_with_direction'.

Just the tiniest script would be cool, so I can fiddle some more.
Using "round_x_with_direction" is recommended, especially if you want to preserve a compatibility for public script you share. You don't know when your script user start to use looping map. Using "round" method fixes the coordinate check, i.e, if player on the edge of map, and check a position in front of player, it will be wrapped to other side, since there will be nothing to check if it's in the edge of the map.
Using "round_x_with_direction" is recommended, especially if you want to preserve a compatibility for public script you share. You don't know when your script user start to use looping map. Using "round" method fixes the coordinate check, i.e, if player on the edge of map, and check a position in front of player, it will be wrapped to other side, since there will be nothing to check if it's in the edge of the map.


Hey, sweet, that's good to know. I'm still having trouble printing it to msgbox but I think that's because I forget how to properly call a method I guess. I mean if I put msgbox_p("test") in the class not the method it prints, but when I call ciop.new nothing happens. Been to long since I tried to script lol. I'll figure it out, thanks for your help
I can confirm you that _with_direction and region_id(x, y), as you wrote them, works.
I use that same structure to direct NPCs,.........
*dynamic* NPCs, who don't exist at the start of the game.
they seem to have no issue walking around.
Yeah wicked, thanks you two, I got it to work just fine 🙂

Original thread: https://forums.rpgmakerweb.com/threads/check-in-front-of-player.92105/