In this case "this event" is the parallel common event, which doesn't move: it has no location because it's a common event. Also note that your setup uses two variables to store two values (x & y), but that will only suffice for one event.
😅
I believe this would be much simpler as a plugin, e.g. (untested):
Spoiler: Suggested plugin code
JavaScript:
(alias => {
Game_CharacterBase.prototype.increaseSteps = function() {
alias.apply(this, arguments); // invoke original method
const se = { name: 'step', volume: 20, pitch: 100 };
AudioManager.playSe(se); // footstep sound stuff
};
})(Game_CharacterBase.prototype.increaseSteps);
This is a basic example: play a fixed sound every time any character moves. You could add features in there, e.g. random pitch/volume, change volume based on player proximity, reference event notetags or terrain tags for footstep sounds, etc.
😴
If, for whatever reason, you're set on doing this with Script commands, I can't think of a better approach than your current idea. It'll need some adjustments, though:
- Some means of storing x & y coordinates for each relevant character. You could do this by turning your current variables into arrays, e.g. Control Variables > Set > Script:
[], then assigning values via Script command, e.g.
JavaScript:
const ev = $gameMap.event(1); $gameVariables.value(5)[ev.eventId()] = { x: ev.x, y: ev.y };
- A loop for relevant characters? Otherwise you'd have to do this for each character individually. E.g. instead of referencing "this event", loop through a list of events and check/update their positions every few frames, e.g.
Spoiler: Event position check loop
JavaScript:
$gameMap.events().forEach(ev => {
const loc = $gameVariables.value(5)[ev.eventId()];
// check: stored position exists and event is not there?
if (loc && !ev.pos(loc.x, loc.y)) {
// if so, do the stuff
}
});
While this could be done with a for loop or Array.forEach (as above), it'd be best to set up a for loop structure using event commands (Loop/Break Loop/Conditional Branch + loop counter variable). Otherwise I think you can actually script less and end up with better performance by making it a plugin. 😅
- Maybe also consider increasing the wait time between checks. For reference, default frames per tile of movement is
2 ** (8 - moveSpeed) (not counting stop time due to move frequency). E.g. at move speed 4 a character takes 2 ** 4 = 16 frames to move from one tile to the next. 🙂
[Edit: changed "all map events" to "relevant characters".]