Hey there,
I was trying to create a plugin that plays a sound everytime a character dies but I just can't get the sound to actually play. Maybe someone can figure out what went wrong.
Here is the code:
I was trying to create a plugin that plays a sound everytime a character dies but I just can't get the sound to actually play. Maybe someone can figure out what went wrong.
Here is the code:
JavaScript:
(() => {
const pluginName = 'DeathSoundsPlugin';
// Plugin Commands
PluginManager.registerCommand(pluginName, 'PlayDeathSound', args => {
const characterId = Number(args.characterId);
const soundFile = getDeathSound(characterId);
if (soundFile) {
AudioManager.playSe({ name: soundFile, volume: 90, pitch: 100, pan: 0 });
}
});
PluginManager.registerCommand(pluginName, 'SetDeathSound', args => {
const characterId = Number(args.characterId);
const soundFile = args.soundFile;
setDeathSound(characterId, soundFile);
});
// Battle Manager
BattleManager.playDeathSound = characterId => {
PluginManager.callCommand('DeathSoundsPlugin', 'PlayDeathSound', { characterId: characterId });
};
// Game Actor
const _Game_Actor_performCollapse = Game_Actor.prototype.performCollapse;
Game_Actor.prototype.performCollapse = function () {
_Game_Actor_performCollapse.call(this);
BattleManager.playDeathSound(this.actorId());
};
// Helper Functions
const getDeathSound = characterId => {
const actor = $gameActors.actor(characterId);
if (actor && actor.meta) {
return actor.meta.deathSound || '';
}
return '';
};
const setDeathSound = (characterId, soundFile) => {
const actor = $gameActors.actor(characterId);
if (actor && actor.meta) {
actor.meta.deathSound = soundFile;
}
};
})();