Advertisement
Maliki79

MalCritBGMBGSChanger

Jul 29th, 2016 (edited)
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Critical BGM/BGS Changer
  3. // MalCritBGMBGSChanger.js
  4. // version 1.0b
  5. //=============================================================================
  6. /*:  
  7.  * @plugindesc ver1.0 - Allows you to set different music and music effects to play when the Party/troupe is in crit condition.
  8.  * @author Maliki79
  9.  *
  10.  * @param Party Critical BGM
  11.  * @desc BGM to start playing when party is in critical state.
  12.  *
  13.  * @param Enemy Critical BGM
  14.  * @desc BGM to start playing when enemy troupe is in critical state.
  15.  *
  16.  * @param Critical BGM volume
  17.  * @desc Volume level of BGM.  (number must be between 0 and 100)
  18.  * @default 100
  19.  *
  20.  * @param Critical BGM pitch
  21.  * @desc Pitch level of BGM.  (number must be between 1 and 300)
  22.  * @default 100
  23.  *
  24.  * @param Critical BGM pan
  25.  * @desc Pan level of BGM.  (number must be between -100 and 100)
  26.  * @default 0
  27.  *
  28.  * @param Party Critical BGS
  29.  * @desc BGS to start playing when party is in critical state.
  30.  *
  31.  * @param Enemy Critical BGS
  32.  * @desc BGS to start playing when enemy troupe is in critical state.
  33.  *
  34.  * @param Critical BGS volume
  35.  * @desc Volume level of BGS.  (number must be between 0 and 100)
  36.  * @default 60
  37.  *
  38.  * @param Critical BGS pitch
  39.  * @desc Pitch level of BGS.  (number must be between 1 and 300)
  40.  * @default 100
  41.  *
  42.  * @param Critical BGS pan
  43.  * @desc Pan level of BGS.  (number must be between -100 and 100)
  44.  * @default 0
  45.  *
  46.  * @param Critical percentage
  47.  * @desc Percentage of total HP the party/troupe has when BGM/BGS starts/stops.
  48.  * @default 25
  49.  *
  50.  *
  51.  * @help In order to use this plugin, you must first decide which BGM and BGS you want
  52.  * to apply to players' parties or enemy troupes.
  53.  * Pick the name of the BGM or BGS and put it's file name
  54.  * in the parameters section.
  55.  * (No need for " marks here.)
  56.  * You can then adjust the volume, pitch and pan levels to your liking.
  57.  * Finally, you can set the percentage of HP that will be considered
  58.  * critical for your game.
  59.  * It defaults to 25%.  This means that once the party or troupe's total hp
  60.  * reaches 25% of it's total Max HP, the music/sounds will begin.
  61.  * (If the hp goes above the critical point, the music/sounds will revert
  62.  * to what they were before.)
  63.  *
  64.  * Note that you must keep the PLugin's file name set as MalCritBGMBGSChanger.js
  65.  *
  66.  * Script Calls:
  67.  * There are several Script calls that can be used with this plugin.
  68.  * Note that these calls make TEMPORARY changes to the plugin and will reset to
  69.  * default upon loading up a new save.
  70.  *
  71.  * $gameSystem.changePartyCritBGM(name);
  72.  * This call will change the BGM used when the party becomes critical.
  73.  * (Use quote marks " around the name.)
  74.  *
  75.  * $gameSystem.changeEnemyCritBGM(name);
  76.  * This call will change the BGM used when the enemy troupe becomes critical.
  77.  * (Use quote marks " around the name.)
  78.  *
  79.  * $gameSystem.changePartyCritBGS(name);
  80.  * This call will change the BGS used when the party becomes critical.
  81.  * (Use quote marks " around the name.)
  82.  *
  83.  * $gameSystem.changeEnemyCritBGS(name);
  84.  * This call will change the BGS used when the enemy troupe becomes critical.
  85.  * (Use quote marks " around the name.)
  86.  *
  87.  * $gameSystem.changeCritBGMVol(number);
  88.  * This call will change the volume of all BGM changes, party or enemy, when
  89.  * they become critical.
  90.  * (Keep the number within the range given for the parameter section.)
  91.  *
  92.  * $gameSystem.changeCritBGMPitch(number);
  93.  * This call will change the pitch of all BGM changes, party or enemy, when
  94.  * they become critical.
  95.  * (Keep the number within the range given for the parameter section.)
  96.  *
  97.  * $gameSystem.changeCritBGMPan(number);
  98.  * This call will change the pan level of all BGM changes, party or enemy, when
  99.  * they become critical.
  100.  * (Keep the number within the range given for the parameter section.)
  101.  *
  102.  * $gameSystem.changeCritBGSVol(number);
  103.  * This call will change the volume of all BGS changes, party or enemy, when
  104.  * they become critical.
  105.  * (Keep the number within the range given for the parameter section.)
  106.  *
  107.  * $gameSystem.changeCritBGSPitch(number);
  108.  * This call will change the pitch of all BGS changes, party or enemy, when
  109.  * they become critical.
  110.  * (Keep the number within the range given for the parameter section.)
  111.  *
  112.  * $gameSystem.changeCritBGSPan(number);
  113.  * This call will change the pan level of all BGS changes, party or enemy,
  114.  * when they become critical.
  115.  * (Keep the number within the range given for the parameter section.)
  116.  * *
  117.  * $gameSystem.disableCritSounds();
  118.  * This call will disable ALL crit BGM and BGS for both party and troupe.
  119.  *
  120.  * $gameSystem.enableCritSounds();
  121.  * This call turns the BGM and BGS changes back on.
  122.  *
  123.  */
  124.  
  125. var MalCriticalMusic = PluginManager.parameters('MalCritBGMBGSChanger');
  126.  
  127. MalCriticalMusic.PartyCritBGM = String(MalCriticalMusic['Party Critical BGM']) || '';
  128. MalCriticalMusic.EnemyCritBGM = String(MalCriticalMusic['Enemy Critical BGM']) || '';
  129. MalCriticalMusic.CritBGMVol   = Number(MalCriticalMusic['Critical BGM volume']);
  130. MalCriticalMusic.CritBGMPitch = Number(MalCriticalMusic['Critical BGM pitch']);
  131. MalCriticalMusic.CritBGMPan   = Number(MalCriticalMusic['Critical BGM pan']);
  132. MalCriticalMusic.PartyCritBGS = String(MalCriticalMusic['Party Critical BGS']) || '';
  133. MalCriticalMusic.EnemyCritBGS = String(MalCriticalMusic['Enemy Critical BGS']) || '';
  134. MalCriticalMusic.CritBGSVol   = Number(MalCriticalMusic['Critical BGS volume']);
  135. MalCriticalMusic.CritBGSPitch = Number(MalCriticalMusic['Critical BGS pitch']);
  136. MalCriticalMusic.CritBGSPan   = Number(MalCriticalMusic['Critical BGS pan']);
  137. MalCriticalMusic.CritPoint    = Number(MalCriticalMusic['Critical percentage']);
  138.  
  139. Game_System.prototype.enableCritSounds = function() {
  140. MalCriticalMusic.PartyCritBGM = String(MalCriticalMusic['Party Critical BGM']) || '';
  141. MalCriticalMusic.EnemyCritBGM = String(MalCriticalMusic['Enemy Critical BGM']) || '';
  142. MalCriticalMusic.PartyCritBGS = String(MalCriticalMusic['Party Critical BGS']) || '';
  143. MalCriticalMusic.EnemyCritBGS = String(MalCriticalMusic['Enemy Critical BGS']) || '';
  144. }
  145.  
  146. Game_System.prototype.disableCritSounds = function() {
  147. MalCriticalMusic.PartyCritBGM = null;
  148. MalCriticalMusic.EnemyCritBGM = null;
  149. MalCriticalMusic.PartyCritBGS = null;
  150. MalCriticalMusic.EnemyCritBGS = null;
  151. }
  152.  
  153. Game_System.prototype.changePartyCritBGM = function(name) {
  154. MalCriticalMusic.PartyCritBGM = name;
  155. }
  156.  
  157. Game_System.prototype.changeEnemyCritBGM = function(name) {
  158. MalCriticalMusic.EnemyCritBGM = name;
  159. }
  160.  
  161. Game_System.prototype.changePartyCritBGS = function(name) {
  162. MalCriticalMusic.PartyCritBGS = name;
  163. }
  164.  
  165. Game_System.prototype.changeEnemyCritBGS = function(name) {
  166. MalCriticalMusic.EnemyCritBGS = name;
  167. }
  168.  
  169. Game_System.prototype.changeCritBGMVol = function(num) {
  170. MalCriticalMusic.CritBGMVol = Number(num) || MalCriticalMusic.CritBGMVol;
  171. }
  172.  
  173. Game_System.prototype.changeCritBGMPitch = function(num) {
  174. MalCriticalMusic.CritBGMPitch = Number(num) || MalCriticalMusic.CritBGMPitch;
  175. }
  176.  
  177. Game_System.prototype.changeCritBGMPan = function(num) {
  178. MalCriticalMusic.CritBGMPan = Number(num) || MalCriticalMusic.CritBGMPan;
  179. }
  180.  
  181. Game_System.prototype.changeCritBGSVol = function(num) {
  182. MalCriticalMusic.CritBGSVol = Number(num) || MalCriticalMusic.CritBGSVol;
  183. }
  184.  
  185. Game_System.prototype.changeCritBGSPitch = function(num) {
  186. MalCriticalMusic.CritBGSPitch = Number(num) || MalCriticalMusic.CritBGSPitch;
  187. }
  188.  
  189. Game_System.prototype.changeCritBGSPan = function(num) {
  190. MalCriticalMusic.CritBGSPan = Number(num) || MalCriticalMusic.CritBGSPan;
  191. }
  192.  
  193. var MalCritBattleSetup = BattleManager.setup;
  194. BattleManager.setup = function(troopId, canEscape, canLose) {
  195. MalCritBattleSetup.call(this, troopId, canEscape, canLose);
  196. this.oldBgs = null;
  197. this.oldBgm = null;
  198. this.oldBgmPos = null;
  199. this.partycrit = false;
  200. this.troupecrit = false;
  201. }
  202.  
  203. var MalCritApply = Game_Action.prototype.apply;
  204. Game_Action.prototype.apply = function(target) {
  205. MalCritApply.call(this, target);
  206. this.CritMusicCheck();
  207. }
  208.  
  209.  Game_Action.prototype.CritMusicCheck = function() {
  210.  var Sound1 = this.buildSound('M');
  211.  var Sound2 = this.buildSound('S');
  212.  var Sound3 = this.buildSound('E');
  213.  var Sound4 = this.buildSound('T');
  214.  
  215.  if (this.ActorsCritical() && BattleManager.troupecrit == false) {
  216.     if (AudioManager._currentBgm != null && Sound1 != null && BattleManager.partycrit == false) {
  217.         BattleManager.oldBgm = AudioManager._currentBgm;
  218.         BattleManager.oldBgmPos = AudioManager._bgmBuffer.seek();
  219.     }
  220.     if (Sound1 != null) AudioManager.playBgm(Sound1);
  221.     if (Sound2 != null && BattleManager.partycrit == false) {
  222.     BattleManager.oldBgs = AudioManager._currentBgs;
  223.     AudioManager.playBgs(Sound2);
  224.     }
  225.     BattleManager.criticalBGMPLaying = true;
  226.     BattleManager.partycrit = true;
  227.  }
  228.  if (!this.ActorsCritical() && BattleManager.partycrit == true && BattleManager.troupecrit == false) {
  229.     if (BattleManager.oldBgm) AudioManager.playBgm(BattleManager.oldBgm, BattleManager.oldBgmPos);
  230.     if(BattleManager.oldBgs){
  231.         AudioManager.playBgs(BattleManager.oldBgs);
  232.     } else {
  233.         AudioManager.stopBgs();
  234.     }
  235.     BattleManager.criticalBGMPLaying = false;
  236.     BattleManager.partycrit = false;
  237.  }
  238.  
  239.  
  240.  if (this.EnemyCritical() && BattleManager.partycrit == false) {
  241.     if (AudioManager._currentBgm != null && Sound3 != null && BattleManager.troupecrit == false) {
  242.         BattleManager.oldBgm = AudioManager._currentBgm;
  243.         BattleManager.oldBgmPos = AudioManager._bgmBuffer.seek();
  244.     }
  245.     if (Sound3 != null) AudioManager.playBgm(Sound3);
  246.     if (Sound4 != null && BattleManager.troupecrit == false) {
  247.         BattleManager.oldBgs = AudioManager._currentBgs;
  248.         AudioManager.playBgs(Sound4);
  249.     }
  250.     BattleManager.criticalBGMPLaying = true;
  251.     BattleManager.troupecrit = true;
  252.  }
  253.  if (!this.EnemyCritical() && BattleManager.troupecrit == true && BattleManager.partycrit == false) {
  254.     if (BattleManager.oldBgm) AudioManager.playBgm(BattleManager.oldBgm, BattleManager.oldBgmPos);
  255.     if(BattleManager.oldBgs){
  256.         AudioManager.playBgs(BattleManager.oldBgs);
  257.     } else {
  258.         AudioManager.stopBgs();
  259.     }
  260.     BattleManager.criticalBGMPLaying = false;
  261.     BattleManager.troupecrit = false;
  262.  }
  263.  }
  264.  
  265.  Game_Action.prototype.buildSound = function(key) {
  266. var key = key;
  267. if (key == 'M'){
  268.     if (MalCriticalMusic.PartyCritBGM){
  269.         var sound = {
  270.             name:   MalCriticalMusic.PartyCritBGM,
  271.             volume: MalCriticalMusic.CritBGMVol,
  272.             pitch:  MalCriticalMusic.CritBGMPitch,
  273.             pan:    MalCriticalMusic.CritBGMPan
  274.         };
  275.     } else return null;
  276. }
  277.  
  278. if (key == 'S') {
  279.     if (MalCriticalMusic.PartyCritBGS){
  280.         var sound = {
  281.             name:   MalCriticalMusic.PartyCritBGS,
  282.             volume: MalCriticalMusic.CritBGSVol,
  283.             pitch:  MalCriticalMusic.CritBGSPitch,
  284.             pan:    MalCriticalMusic.CritBGSPan
  285.     };
  286.     } else return null;
  287. }
  288.    
  289. if (key == 'E'){
  290.     if (MalCriticalMusic.EnemyCritBGM){
  291.     var sound = {
  292.             name:   MalCriticalMusic.EnemyCritBGM,
  293.             volume: MalCriticalMusic.CritBGMVol,
  294.             pitch:  MalCriticalMusic.CritBGMPitch,
  295.             pan:    MalCriticalMusic.CritBGMPan
  296.     };
  297.     }else return null;
  298. }
  299.  
  300. if (key == 'T') {
  301.     if (MalCriticalMusic.EnemyCritBGS){
  302.     var sound = {
  303.             name:   MalCriticalMusic.EnemyCritBGS,
  304.             volume: MalCriticalMusic.CritBGSVol,
  305.             pitch:  MalCriticalMusic.CritBGSPitch,
  306.             pan:    MalCriticalMusic.CritBGSPan
  307.     };
  308.     } else return null;
  309. }
  310.    
  311. return sound;
  312. }
  313.  
  314.  Game_Action.prototype.ActorsCritical = function() {
  315.  var mhp = 0;
  316.  var hp = 0;
  317.  for (var i = 0; i < $gameParty.battleMembers().length; i++) {
  318.     hp += $gameParty.battleMembers()[i].hp;
  319.     mhp += $gameParty.battleMembers()[i].mhp;
  320.  }
  321.  return hp < mhp * (MalCriticalMusic.CritPoint / 100);
  322.  }
  323.  
  324.   Game_Action.prototype.EnemyCritical = function() {
  325.  var mhp = 0;
  326.  var hp = 0;
  327.  for (var i = 0; i < $gameTroop.members().length; i++) {
  328.     hp += $gameTroop.members()[i].hp;
  329.     mhp += $gameTroop.members()[i].mhp;
  330.  }
  331.  return hp < mhp * (MalCriticalMusic.CritPoint / 100);
  332.  
  333.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement