Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Custom Music PS Edition
- // @namespace http://www.smogon.com/forums/members/pikachuun.171701/
- // @version why did i have to update this again
- // @description Adds your own custom music for PS by replacing the preloadBGM script.
- // Note that the music selection is entirely up to you; I provided examples so you get the jist of it.
- // @author Based Choon
- // @match https://play.pokemonshowdown.com/*
- // you will probably want to replace that with whatever servers you're using it on
- // @grant none
- // ==/UserScript==
- window.eval(`
- BattleScene.prototype.preloadBgm = function (bgmNum) {
- 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).
- this.bgmNum = bgmNum;
- let ext = window.nodewebkit ? '.ogg' : '.mp3';
- switch (bgmNum) {
- ////////////////////////
- //Special easter egg cases you shouldn't tamper with anyway (you can still use its format if you wish)
- /////////////////////////////////////
- case -1:
- BattleSound.loadBgm('audio/bw2-homika-dogars' + ext, 1661, 68131);
- this.bgm = 'audio/bw2-homika-dogars' + ext;
- break;
- case -2:
- BattleSound.loadBgm('audio/xd-miror-b' + ext, 9000, 57815);
- this.bgm = 'audio/xd-miror-b' + ext;
- break;
- case -3:
- BattleSound.loadBgm('audio/colosseum-miror-b' + ext, 896, 47462);
- this.bgm = 'audio/colosseum-miror-b' + ext;
- break;
- ////////////////////////
- //Cases that you should actually be able to have input on
- /////////////////////////////////////
- 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).
- BattleSound.loadBgm('https://audio.ngfiles.com/504000/504114_Flirt-Flirt-Oh-It-Hurts.mp3', 0, 205749);
- this.bgm = 'https://audio.ngfiles.com/504000/504114_Flirt-Flirt-Oh-It-Hurts.mp3';
- break;
- //Start adding cases here in the same format as above, increasing the number by 1 each time.
- default: //This is your last case. Always have "default:" as your last case, regardless of what you set for n.
- BattleSound.loadBgm('https://audio.ngfiles.com/272000/272755_Elite_Airflow__NG_.mp3', 0, 278152);
- this.bgm = 'https://audio.ngfiles.com/272000/272755_Elite_Airflow__NG_.mp3';
- break;
- }
- };`);
- //The above code can be edited. Go nuts.
- //A note for all of you people who are like "wtf is this code":
- //BattleSound.loadBgm('url', loopstart, loopend):
- // url is the url of your music. NOTE THAT THIS IS THE URL OF THE FILE ITSELF, NOT THE WEBSITE THAT HOSTS IT.
- // 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.
- // loopend is the end point of your loop (same units as loopstart). In my case I calculated the end's time in milliseconds.
- //this.bgm = 'url':
- // url is still the url of your music. ONCE AGAIN NOTE THAT THIS IS THE URL OF THE FILE ITSELF.
- //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).
- ////THE BELOW CODE, HOWEVER, CANNOT BE EDITED. PLEASE KEEP THIS EXACTLY AS IS.
- window.eval(`BattleSound.loadBgm = function (url, loopstart, loopend) {
- if (this.bgmCache[url]) {
- if (this.bgmCache[url] !== this.soundPlaceholder || loopstart === undefined) {
- return this.bgmCache[url];
- }
- }
- try {
- this.bgmCache[url] = soundManager.createSound({
- id: url,
- url: url,
- volume: this.bgmVolume
- });
- } catch (e) {}
- if (!this.bgmCache[url]) {
- // couldn't load
- // suppress crash
- return (this.bgmCache[url] = this.soundPlaceholder);
- }
- this.bgmCache[url].onposition(loopend, function (t, evP) {
- this.setPosition(this.position - (loopend - loopstart));
- });
- return this.bgmCache[url];
- };`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement