Hello! I would probably do something like this:
let player = $gamePlayer;
let x = player.x;
let y = player.y;
let d = player.direction();
let frontX = x + (d === 6 ? 1 : d === 4 ? -1 : 0);
let frontY = y + (d === 2 ? 1 : d === 8 ? -1 : 0);
front X takes player x location and adds 1 if direction is 6 (facing right) or adds -1 (subtracts 1, if player is facing left) or it adds 0 if neither (player is facing up or down)
frontY takes player y location and adds 1 if the direction is 2 (facing down) or adds -1 (subtracts 1, if the player is facing up) or it adds 0 if neither (player is facing left or right)
This code should give you the x,y coordinates for the tile in front of the player. There are countless other conditions you can set as well, as this doesn't factor in if the tile in front of the player is passable or not. So once you have the frontX and frontY you can then handle whatever other conditions, if any are necessary, before spawning an event.