Results 1 to 6 of 6
  1. #1
    BurgerLoverMx's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Québec
    Posts
    411
    Reputation
    23
    Thanks
    843
    My Mood
    Relaxed

    [AS3] Custom Client-Sided Dynamic Music

    Custom Client-Sided Dynamic Music
    I know someone will mention it, yes, the music is stored in the server. If that really hurts that much than you can just as easily store it in the client.
     
    1. Music.as
    Replace your Music.as file with this one:
    Code:
    package com.company.assembleegameclient.sound {
    import com.company.assembleegameclient.parameters.Parameters;
    
    public class Music {
    
        private static var originalMusic:String;
        private static var music_:SwitchMusic;
    
        public static function load():void {
        }
    
        public static function chooseMusic(music:String):void {
            if (originalMusic == music) return;
            originalMusic = music;
            if (music_) {
                music_.fadeOut();
            }
            music_ = new SwitchMusic();
            music_.switchMusic(music);
            music_.fadeIn();
        }
    
        public static function setPlayMusic(_arg_1:Boolean):void {
            Parameters.data_.playMusic = _arg_1;
            Parameters.save();
    
        }
    
        public static function setMusicVolume(_arg_1:Number):void {
            Parameters.data_.musicVolume = _arg_1;
            Parameters.save();
            if (!Parameters.data_.playMusic) {
                return;
            }
            music_.changeVolume(_arg_1);
        }
    
    
    }
    }//package com.company.assembleegameclient.sound
    You can also remove the load function and all places that it gets called from if you wish (and know how to).

    2. SwitchMusic.as
    Create a new file in the sound folder (same folder as your Music.as file) called SwitchMusic.
     

    Replace the code in the newly created file with this one:
    Code:
    package com.company.assembleegameclient.sound {
    import com.company.assembleegameclient.parameters.Parameters;
    import com.gskinner.motion.GTween;
    
    import flash.events****ErrorEvent;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundTransform;
    import flash.net.URLRequest;
    
    import kabam****tmg.application.api.ApplicationSetup;
    import kabam****tmg.core.StaticInjectorContext;
    
    public class SwitchMusic {
    
        private var music:Sound;
        private var musicChannel:SoundChannel;
        private var musicTransform:SoundTransform;
        private var gT:GTween;
    
        public function switchMusic(musicName:String):void {
            var appSetup:ApplicationSetup = StaticInjectorContext.getInjector().getInstance(ApplicationSetup);
            var musicPath:String = appSetup.getAppEngineUrl(true) + "/music/";
            music = new Sound();
            music.addEventListener(IOErrorEvent****_ERROR, defaultMusic);
            musicTransform = new SoundTransform(0);
            gT = new GTween(musicTransform);
            gT.onChange = updateVolume;
            music.load(new URLRequest(musicPath + musicName + ".mp3"));
        }
    
        public function fadeIn():void {
            gT.duration = 3;
            gT.setValue("volume", Parameters.data_.musicVolume);
            musicChannel = music.play(0, int.MAX_VALUE, musicTransform)
        }
    
        public function fadeOut():void {
            gT.onComplete = stopChannel;
            gT.setValue("volume", 0)
        }
    
        public function changeVolume(volume:Number):void {
            musicTransform.volume = volume;
            musicChannel.soundTransform = musicTransform;
        }
    
        private function updateVolume(gtween:GTween):void {
            musicChannel.soundTransform = musicTransform;
        }
    
        private function stopChannel(gtween:GTween):void {
            musicChannel.stop();
        }
    
        private static function defaultMusic(_arg_1:IOErrorEvent):void {
            Music.chooseMusic("default");
        }
    
    
    }
    }
    Follow this image to fix the '****' symbols.
     

    You now have all your basic functions to switch your music! If you wish to change the fade in / fade out time then go in the fadeIn function and change the gT.duration number to equal whatever number you'd like. You should also change the defaultMusic function and change the "default" text to whatever name your default music has (basicly the music you want to use in case a dungeon doesn't have a music). In my case, my default music is named to 'default' and so I put in the name "default".

    3. Use new functions
    Go to the onMapLoaded function in MapLoadingMediator.as and change it to this:
    Code:
        private function onMapLoaded(_arg_1:MapInfo):void {
            this.view.showMap(_arg_1.displayName_, _arg_1.difficulty_);
            Music.chooseMusic(_arg_1.displayName_);
        }
    You will also need to import Music.as
    (go to the imports at the top and add this line:
    Code:
    import com.company.assembleegameclient.sound.Music;
    )

    Next go in TitleView.as and at the very beginning of the TitleView function add this line:
    Code:
            Music.chooseMusic("menu");
    Be sure to put in your actual menu music's name (mine is called 'menu' so I put in 'menu').
    Import Music.as again aswell.

    Next go in CharacterSelectionAndNewsScreen.as and in the CharacterSelectionAndNewsScreen function add the same line (with the same music aswell unless you want a different one).

    Lastly go in GameServerConnectionConcrete.as and in the onDeath function add the same line but change the music to your death screen music.

    4. Add music!
    You are now at the step in which you need to find music. Go in your server and find the music folder (server>sfx>music). Now properly add music to the music folder!
     

     

     

    Be sure to add a song named 'menu' (or whatever you put your menu music's name as), one name 'death' (or whatever you put your death music's name as) and one named 'default' (or whatever you put your default music's name as).
    Whenever you want to add music for a dungeon, add the music you want. Next go to wServer>realm>worlds and find the dungeon you want specific music for. Open the file and find the line which says: ClientWorldName = "dungeonname". Copy that name and rename your music file to that name.
    If your dungeon name has '{}' surrounding it just remove them and copy that name over.

    I'll try to help as much people as possible, be sure to leave a reply if you have a problem / if you don't understand a step.
    Last edited by BurgerLoverMx; 07-10-2017 at 03:26 PM.

  2. The Following 4 Users Say Thank You to BurgerLoverMx For This Useful Post:

    AmonPro (07-15-2017),backpack-o (07-15-2017),Breezattak (07-28-2017),[b]ong (07-10-2017)

  3. #2
    NigrKiller's Avatar
    Join Date
    Nov 2016
    Gender
    male
    Location
    Willy's Realm
    Posts
    85
    Reputation
    10
    Thanks
    52
    Looks nice, good job. Might use, will bookmark.

  4. The Following User Says Thank You to NigrKiller For This Useful Post:

    BurgerLoverMx (07-10-2017)

  5. #3
    ZeusAlmighty's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Posts
    689
    Reputation
    27
    Thanks
    2,198
    My Mood
    Buzzed
    Nice work, but I prefer the one made by Travoos simply because I can change the music played at any time through my ******. This does have the benefit of the music always being available even if the person is not on the internet but then again they wont need to hear music then as they wont need to load in.

  6. #4
    BurgerLoverMx's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Québec
    Posts
    411
    Reputation
    23
    Thanks
    843
    My Mood
    Relaxed
    Quote Originally Posted by ZeusAlmighty View Post
    Nice work, but I prefer the one made by Travoos simply because I can change the music played at any time through my ******. This does have the benefit of the music always being available even if the person is not on the internet but then again they wont need to hear music then as they wont need to load in.
    Point is you can with this too though, just instead of linking back to your server folder / to your music inside the client you link back to ******. This is just as easy to make a command to switch the music aswell. Rn I just havn't found one thing which mine doesn't cover that Travs does. Trying to optimize as much as possible if people have problems.

  7. #5
    TheRealLawFTW's Avatar
    Join Date
    Jun 2017
    Gender
    male
    Posts
    39
    Reputation
    10
    Thanks
    9
    -.- this is what made my server somewhat special....*cough* *cough* dynamic music....

  8. #6
    lkdjnfoskjednfblksjdfn's Avatar
    Join Date
    Apr 2014
    Gender
    male
    Location
    127.0.0.1
    Posts
    1,340
    Reputation
    198
    Thanks
    841
    My Mood
    Inspired
    Quote Originally Posted by TheRealLawFTW View Post
    -.- this is what made my server somewhat special....*cough* *cough* dynamic music....
    Like, no servers other than yours used it b4 you.

  9. The Following 2 Users Say Thank You to lkdjnfoskjednfblksjdfn For This Useful Post:

    BurgerLoverMx (07-26-2017),DevilRotMG (06-29-2018)

Similar Threads

  1. [Solved] [AS3] Dynamic Music - setProps
    By EHaehthsthethetheh in forum Realm of the Mad God Private Servers Help
    Replies: 4
    Last Post: 03-31-2017, 04:30 PM
  2. [Solved] [Fsod/AS3] Rotmg how to add new music to realm at dynamic music?
    By Wojtasowy1234 in forum Realm of the Mad God Private Servers Help
    Replies: 0
    Last Post: 02-27-2017, 10:25 PM
  3. [Solved] [Fsod/AS3] Rotmg my own website for dynamic music
    By Wojtasowy1234 in forum Realm of the Mad God Private Servers Help
    Replies: 2
    Last Post: 02-26-2017, 09:25 AM
  4. [Solved] Fsod [AS3] Dynamic music error
    By Wojtasowy1234 in forum Realm of the Mad God Private Servers Help
    Replies: 6
    Last Post: 02-24-2017, 03:59 AM
  5. [TUT] Adding dynamic music to the AS3 client/server
    By Travoos in forum Realm of the Mad God Private Servers Tutorials/Source Code
    Replies: 10
    Last Post: 02-25-2015, 08:07 AM