- Joined
- Jan 23, 2007
- Messages
- 2,605
- Reaction score
- 360
Hey, i just figured out how to get sounds working lol, yes im late but atleast its done now >.>
NOTE: This is for weapons, so when you hit with a whip on a NPC or Player, it will do the whip sound.
I think i did do a SPECIALS sound tutorial, not sure lol
riiiight, this is rather simple, but yeh ill explain.
STEP 1:
First goto Player.java, we will be calling the int from there, so search any boolean or watever, and above it paste this int.
Ok as i did on my weapons tutorial, ill do the same here, going through lines of the code.
Line 1.
This is a basic switch method we are using, it's SOO much easier to use than if statements and stuff like that.. You will see its also got this.equipment[3], well this is telling us, if the item is in slot 3, then do the sounds once activated bla bla bla..
Line 2:
This is the weapon id, in the case its a Whip!
Right so here we are calling the Return Sound, so just loop through some sounds or look at a sounds list until you get the correct id, and return it. That sound id above is obviously the Whip attack emote sound.
Thats all you need to know about that code lol, so yaaa lets move on to 2 more other things you need to do.
STEP 2:
Right in this step we will be making it so we call the sounds once an attack emote has been called.
NOTE: I will be going by my file names and code, so if you dont got it, you will have to look for the defend or attack emotes yourself, it's really not hard!
Ok, Open up PlayerCombat.java and search for:
Then under requestAnim, add this..
This is calling the sound if in the area, and you will notice its calling the INT which we placed in Player.java.
SOOooo we now need to do the same when attacking NPCS, so goto PlayerNPCCombat.java.
Then search for:
Under the requestAnim, add this:
Which is the same calling method..
I almost forgot, add these to Frames.java
You can call different sounds in different ways, making it global or none global etc.....
Done, works, any errors please post below..
Thanks
-Joe
NOTE: This is for weapons, so when you hit with a whip on a NPC or Player, it will do the whip sound.
I think i did do a SPECIALS sound tutorial, not sure lol
riiiight, this is rather simple, but yeh ill explain.
STEP 1:
First goto Player.java, we will be calling the int from there, so search any boolean or watever, and above it paste this int.
Code:
public int getWepSound() {
switch (this.equipment[3]) {
case 4151:
return 2720;
default:
return 10000;
}
}
Ok as i did on my weapons tutorial, ill do the same here, going through lines of the code.
Line 1.
Code:
switch (this.equipment[3]) {
Line 2:
Code:
case 4151:
This is the weapon id, in the case its a Whip!
Code:
return 2720;
Right so here we are calling the Return Sound, so just loop through some sounds or look at a sounds list until you get the correct id, and return it. That sound id above is obviously the Whip attack emote sound.
Thats all you need to know about that code lol, so yaaa lets move on to 2 more other things you need to do.
STEP 2:
Right in this step we will be making it so we call the sounds once an attack emote has been called.
NOTE: I will be going by my file names and code, so if you dont got it, you will have to look for the defend or attack emotes yourself, it's really not hard!
Ok, Open up PlayerCombat.java and search for:
Code:
if (!p.usingSpecial) {
p.requestAnim(p.attackEmote, 0);
Then under requestAnim, add this..
Code:
p.frames.playSoundInArea(p.absX, p.absY, 4, p.getWepSound(), 1, 0);
This is calling the sound if in the area, and you will notice its calling the INT which we placed in Player.java.
SOOooo we now need to do the same when attacking NPCS, so goto PlayerNPCCombat.java.
Then search for:
Code:
p.addSkillXP(3 * hitDamage * CombatXPRate ,3);
}
n.requestAnim(n.defendEmote, 0);
Under the requestAnim, add this:
Code:
p.frames.playSoundInArea(p.absX, p.absY, 4, p.getWepSound(), 1, 0);
Which is the same calling method..
I almost forgot, add these to Frames.java
Code:
public void addSoundEffect(Player player, int soundId, int bytes, int delay) {
for (Player p : Engine.players) {
if (p == null || player == null)
continue;
p.stream.createFrame(119);
p.stream.writeWord(soundId);
p.stream.writeByte(bytes);
p.stream.writeWord(delay);
}
}
public void playSound(Player p, int soundId, int j, int delay) {
if(p == null || p.stream == null || p.disconnected[0]){
return;
}
p.stream.createFrame(119);
p.stream.writeWord(soundId);
p.stream.writeByte(j);
p.stream.writeWord(delay);
}
/**
* Plays a sound on a absolute X and Y and XXX squares around that, can use p.absX, p.absY...
* @param distance The distance players must be to hear the sound
*/
public void playSoundInArea(int playX, int playY, int distance, int soundId, int j, int delay) {
for (Player p : Engine.players) {
if(p == null || p.stream == null || p.disconnected[0]){
continue;
}
if(Misc.getDistance(playX, playY, p.absX, p.absY) <= distance) {
p.stream.createFrame(119);
p.stream.writeWord(soundId);
p.stream.writeByte(j);
p.stream.writeWord(delay);
}
}
}
/**
* Plays a sound for everyone that is online
*/
public void playGlobalSound(int soundId, int j, int delay) {
for (Player p : Engine.players) {
if(p == null || p.stream == null || p.disconnected[0]){
continue;
}
p.stream.createFrame(119);
p.stream.writeWord(soundId);
p.stream.writeByte(j);
p.stream.writeWord(delay);
}
}
You can call different sounds in different ways, making it global or none global etc.....
Done, works, any errors please post below..
Thanks
-Joe