Advertisement
Pikachuun

Custom Moosic

Jan 20th, 2015
1,240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Custom Music PS Edition
  3. // @namespace http://www.smogon.com/forums/members/pikachuun.171701/
  4. // @version why did i have to update this again
  5. // @description Adds your own custom music for PS by replacing the preloadBGM script.
  6. // Note that the music selection is entirely up to you; I provided examples so you get the jist of it.
  7. // @author Based Choon
  8. // @match https://play.pokemonshowdown.com/*
  9. // you will probably want to replace that with whatever servers you're using it on
  10. // @grant none
  11. // ==/UserScript==
  12. window.eval(`
  13. BattleScene.prototype.preloadBgm = function (bgmNum) {
  14. if (!bgmNum) bgmNum = Math.floor(Math.random() * ( 2 )); //The number I put in parentheses for emphasis is the number of audio files you'll be replacing (I'll call it n).
  15. this.bgmNum = bgmNum;
  16. let ext = window.nodewebkit ? '.ogg' : '.mp3';
  17. switch (bgmNum) {
  18. ////////////////////////
  19. //Special easter egg cases you shouldn't tamper with anyway (you can still use its format if you wish)
  20. /////////////////////////////////////
  21. case -1:
  22. BattleSound.loadBgm('audio/bw2-homika-dogars' + ext, 1661, 68131);
  23. this.bgm = 'audio/bw2-homika-dogars' + ext;
  24. break;
  25. case -2:
  26. BattleSound.loadBgm('audio/xd-miror-b' + ext, 9000, 57815);
  27. this.bgm = 'audio/xd-miror-b' + ext;
  28. break;
  29. case -3:
  30. BattleSound.loadBgm('audio/colosseum-miror-b' + ext, 896, 47462);
  31. this.bgm = 'audio/colosseum-miror-b' + ext;
  32. break;
  33.  
  34. ////////////////////////
  35. //Cases that you should actually be able to have input on
  36. /////////////////////////////////////
  37. case 0: //Due to how Math.random() works, your possible numbers for bgmNum are 0 to (n-1). Therefore, your case numbers should be 0 to (n-2).
  38. BattleSound.loadBgm('https://audio.ngfiles.com/504000/504114_Flirt-Flirt-Oh-It-Hurts.mp3', 0, 205749);
  39. this.bgm = 'https://audio.ngfiles.com/504000/504114_Flirt-Flirt-Oh-It-Hurts.mp3';
  40. break;
  41. //Start adding cases here in the same format as above, increasing the number by 1 each time.
  42. default: //This is your last case. Always have "default:" as your last case, regardless of what you set for n.
  43. BattleSound.loadBgm('https://audio.ngfiles.com/272000/272755_Elite_Airflow__NG_.mp3', 0, 278152);
  44. this.bgm = 'https://audio.ngfiles.com/272000/272755_Elite_Airflow__NG_.mp3';
  45. break;
  46. }
  47. };`);
  48.  
  49. //The above code can be edited. Go nuts.
  50. //A note for all of you people who are like "wtf is this code":
  51. //BattleSound.loadBgm('url', loopstart, loopend):
  52. // url is the url of your music. NOTE THAT THIS IS THE URL OF THE FILE ITSELF, NOT THE WEBSITE THAT HOSTS IT.
  53. // loopstart is the start point of your loop (If I'm not mistaken this is in milliseconds). In my case I just put 0 which is the beginning.
  54. // loopend is the end point of your loop (same units as loopstart). In my case I calculated the end's time in milliseconds.
  55. //this.bgm = 'url':
  56. // url is still the url of your music. ONCE AGAIN NOTE THAT THIS IS THE URL OF THE FILE ITSELF.
  57. //If your music doesn't load, you probably put in the wrong site. Try finding the raw audio file (probably can be found through source code of the website).
  58.  
  59.  
  60. ////THE BELOW CODE, HOWEVER, CANNOT BE EDITED. PLEASE KEEP THIS EXACTLY AS IS.
  61. window.eval(`BattleSound.loadBgm = function (url, loopstart, loopend) {
  62. if (this.bgmCache[url]) {
  63. if (this.bgmCache[url] !== this.soundPlaceholder || loopstart === undefined) {
  64. return this.bgmCache[url];
  65. }
  66. }
  67. try {
  68. this.bgmCache[url] = soundManager.createSound({
  69. id: url,
  70. url: url,
  71. volume: this.bgmVolume
  72. });
  73. } catch (e) {}
  74. if (!this.bgmCache[url]) {
  75. // couldn't load
  76. // suppress crash
  77. return (this.bgmCache[url] = this.soundPlaceholder);
  78. }
  79. this.bgmCache[url].onposition(loopend, function (t, evP) {
  80. this.setPosition(this.position - (loopend - loopstart));
  81. });
  82. return this.bgmCache[url];
  83. };`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement