Looking to add a little UI element to my game where, when the player is equipped with certain tools (If Tool ID = 1 or Tool ID = 2, etc.), then I want to display a little square around the tile that is directly in front of the player indicating that if the player uses that tool, that's the tile that will be affected. That way the player will know exactly what they're about to swing their axe at or what ground tile they're about to till with their hoe. My initial thought that it would be a simple common event that would get the player's x and y coordinates and then alter the x and/or y based on which direction the player is facing to place it in front of the player, but couldn't think of the best way of displaying that square. Show picture depends on the coordinates of the display and not the map, so unless there's another way, I don't think that would work. I could use Visustella's events and movement plugin to spawn an event template of the square directly in front of the player and just move it whenever the player moves but that almost seems like it could cause slowdowns. Any one know the best way?
Making UI element that is always one tile in front of player as long as condition is met.
RPG Maker MZ SupportHmmm, can you swap the player sprite to something that has that square drawn on the sheet?
You can do it with a parallel event
Edit: You don't even need the first two variables for this so I deleted them.
Code:
switch($gamePlayer.direction()){
case 2: $gameVariables.setValue(4, $gamePlayer.y+1);break;
case 4: $gameVariables.setValue(3, $gamePlayer.x-1);break;
case 6: $gameVariables.setValue(3, $gamePlayer.x+1);break;
case 8: $gameVariables.setValue(4, $gamePlayer.y-1);break;
}
Edit: You don't even need the first two variables for this so I deleted them.
That's absolutely perfect! Thank you!
Here is a script call alternative for an event if you need something that is smoother in its movement and becomes transparent if it is a tile where the player cannot pass (basically, somewhere you don't want the player to be able to dig or swing their axe at).
Set the event to parallel, through/below characters, and use this script call:
You could use a wait time but it will affect how the event is moving. Shouldn't be too taxing, though.
Set the event to parallel, through/below characters, and use this script call:
JavaScript:
const m = $gameMap, p = $gamePlayer, x = p._realX, y = p._realY,
dir = p.direction(), c = this.character(0);
if (p.isMoving() || Input.dir4)
c.locate(m.xWithDirection(x, dir), m.yWithDirection(y, dir));
if (p.canPass(p.x, p.y, dir)) c.setOpacity(255);
else c.setOpacity(128);
Original thread: https://forums.rpgmakerweb.com/threads/making-ui-element-that-is-always-one-tile-in-front-of-player-as-long-as-condition-is-met.169152/