Dynamic music is something I made a long time ago in phoenix that I expect about every server on here has. However, if you started messing with the recently released AS3 client source, you may have noticed that it isn't there. No need to worry, as I already have the AS3 code for all of it in Seraphs' Dominion.
Note that you must be using the same AS3 client AS WELL AS the same server source uploaded by Kithio. If you don't want to use that server source, I'm not helping you.
PART ONE: THE CLIENT
Before I say anything, it's important to know that you can change the URL to your sfx folder which contains your music folder in
com/company/assembleegameclient/parameters/Parameters.as.
Step 1 You want to open up the AS3 client and navigate to
_vf/_gs.as. You'll want to replace the entire file with this code:
Code:
// Decompiled by AS3 Sorcerer 1.99
// http://www.as3sorcerer.com/
//_vf._gs
package _vf {
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import com.company.assembleegameclient.parameters.Parameters;
import flash.media.SoundTransform;
public class _gs {
public static const menuMusic:Vector.<String> = new <String>["sorc", "Menu", "Menu2"];
public static var fadeIn:Number = 0.65;
public static var fadeOut:Number = 0;
public static var music_:String = "Menu";
private static var currentSoundChannel:SoundChannel = null;
private static var currentSoundTransform:SoundTransform = null;
private static var newSound:Sound = null;
private static var newSoundChannel:SoundChannel = null;
private static var newSoundTransform:SoundTransform = null;
public static function load():void {
var currentSound:Sound = new Sound();
currentSound.load(new URLRequest((("http://" + Parameters.musicUrl_) + "/sfx/music/" + randomMenu() + ".mp3")));
currentSoundTransform = new SoundTransform(Parameters.data_.playMusic ? 0.65 : 0);
currentSoundChannel = currentSound.play(0, int.MAX_VALUE, currentSoundTransform);
}
public static function _continue(_arg1:Boolean):void {
Parameters.data_.playMusic = _arg1;
Parameters.save();
currentSoundChannel.soundTransform = new SoundTransform(((Parameters.data_.playMusic) ? 0.65 : 0));
}
public static function randomMenu():String {
return menuMusic[Math(dot)round(Math.random() * (menuMusic.length - 1))];
}
public static function reload(name:String):void {
if (music_ == name) return;
music_ = name;
try {
if (fadeIn < 0.65 && newSoundChannel != null) {
endFade();
}
newSound = new Sound();
newSound.load(new URLRequest("http://" + Parameters.musicUrl_ + "/sfx/music/" + (name == "Menu" ? randomMenu() : name) + ".mp3"));
newSoundTransform = new SoundTransform(Parameters.data_.playMusic ? 0.65 : 0);
newSoundChannel = newSound.play(0, int.MAX_VALUE, newSoundTransform);
} catch (e:Error) {
trace(e);
}
//if (fadeIn < 0.65) endFade();
fadeIn = 0;
fadeOut = 0.65;
}
public static function endFade():void {
try {
currentSoundChannel.stop();
} catch (er:Error)
{
trace(er);
}
currentSoundChannel = newSoundChannel;
currentSoundTransform = newSoundTransform;
currentSoundTransform.volume = Parameters.data_.playMusic ? 0.65 : 0;
fadeIn = 0.65;
fadeOut = 0;
}
public static function updateFade():void {
if (fadeIn >= 0.65) return;
if (!Parameters.data_.playMusic) {
endFade();
return;
}
try {
fadeIn += 0.0065;
fadeOut -= 0.0065;
if(fadeOut < 0) {
fadeOut = 0;
}
currentSoundTransform.volume = fadeOut;
newSoundTransform.volume = fadeIn;
currentSoundChannel.soundTransform = currentSoundTransform;
newSoundChannel.soundTransform = newSoundTransform;
} catch (e:Error) {
trace(e);
}
if (fadeIn >= 0.65) endFade();
}
}
}//package _vf
Then you replace the (dot) with a period because MPGH is retarded and censors Math(dot)round
I should also note that this line of the code:
Code:
public static const menuMusic:Vector.<String> = new <String>["sorc", "Menu", "Menu2"];
is the random array of menu music that can play. You can change that to whatever you have.
Step 2 Navigate to
_02t/_pM_.as, find the onEnterFrame function, and paste this code at the start of it:
Code:
if (_vf._gs.music_ != "Death" || _vf._gs.music_ != "Menu") _vf._gs.reload("Menu");
_vf._gs.updateFade();
You'll also have to import _vf._gs
Step 3 Navigate to
com/company/assembleegameclient/game/GameSprite.as, find the onEnterFrame function, and paste this code at the start of it:
You'll also have to import _vf._gs
Step 4 Navigate to
com/company/assembleegameclient/net/_1f.as, find the _038 function, and paste this code at the start of it:
Code:
_vf._gs.reload("Death");
You'll also have to import _vf._gs
Step 5 Here's where it gets difficult. Navigate to
com/company/assembleegameclient/map/_X_l.as.
First, you'll want to add a new string variable called music_. It looks like this:
Code:
public var music_:String;
Place it where the other variables are at the top of the class.
Then, you'll want to replace this function:
Code:
public function _ti(_arg1:int, _arg2:int, _arg3:String, _arg4:int, _arg5:Boolean, _arg6:Boolean):void{
this.width_ = _arg1;
this.height_ = _arg2;
this.name_ = _arg3;
this._vv = _arg4;
this.allowPlayerTeleport_ = _arg5;
this.showDisplays_ = _arg6;
}
with this one:
Code:
public function _ti(_arg1:int, _arg2:int, _arg3:String, _arg4:int, _arg5:Boolean, _arg6:Boolean, _arg7:String):void{
this.width_ = _arg1;
this.height_ = _arg2;
this.name_ = _arg3;
this._vv = _arg4;
this.allowPlayerTeleport_ = _arg5;
this.showDisplays_ = _arg6;
this.music_ = _arg7;
_vf._gs.reload(this.music_);
}
You'll also have to import _vf._gs
Step 6 Next, you'll want to fix the usages of the function you just changed.
First, navigate back to
_02t/_pM_.as, and replace this line of code:
Code:
_local3._ti((_sl.x_ + (2 * BORDER)), _sl.y_, "Background Map", Background._0H_W_, false, false);
with this:
Code:
_local3._ti((_sl.x_ + (2 * BORDER)), _sl.y_, "Background Map", Background._0H_W_, false, false, "Menu");
Then, go to
_K_D_/_p0.as and replace this line of code:
Code:
_local3._ti(_local2["width"], _local2["height"], _local2["name"], _local2["back"], false, false);
with this:
Code:
_local3._ti(_local2["width"], _local2["height"], _local2["name"], _local2["back"], false, false, "Menu");
Finally, go back to
com/company/assembleegameclient/game/GameSprite.as, and replace this line of code:
Code:
this.map._ti(_arg1.width_, _arg1.height_, _arg1.name_, _arg1.background_, _arg1.allowPlayerTeleport_, _arg1.showDisplays_);
with this one:
Code:
this.map._ti(_arg1.width_, _arg1.height_, _arg1.name_, _arg1.background_, _arg1.allowPlayerTeleport_, _arg1.showDisplays_, _arg1.music_);
Note that this will still give an error, that'll be fixed here shortly.
Step 7 You will be modifying the MapInfo packet in here. This means that your client will not correctly recieve the MapInfo packet and will break if you don't modify the server to send out the correct information. That will be covered later in the tutorial. I'll be using screenshots for this part. Add the lines that are outlined in red.
Navigate to
_011/_wx.as.
PART TWO: THE SERVER
Step 1 Navigate to
wServer/realm/World.cs and make these basic changes:
Afterwards, put these functions in the same class:
Code:
public void SetMusic(params string[] music)
{
Music = music;
}
public string GetMusic()
{
if (Music.Length == 0)
return "null";
var rand = new wRandom();
return Music[rand.Next(0, Music.Length)];
}
Step 2 Navigate to
wServer/networking/svrPackets/MapInfoPacket.cs and add these:
Step 3 Navigate to
wServer/networking/handlers/HelloPacketHandler.cs and add this one line:
Step 4 You're done! Now you just go into the world files you want and add their music!
