Why are you adding the methods in Entity instead of Player? Npcs etc can't play songs so it doesn't make sense to put them there. Also, as you say, load this from json or some other format - this is far too much data to put in a class.
|
This is a little something I've been messing with. This is my first time writing a sound handling system for an RSPS, it isn't perfect, but it's a good base to work off of.
I used http://www.rune-server.org/runescape...sic-areas.html for the locations of the songs and for the IDs I also used a 666 revision list as I couldn't find a good 317 list. So some of the ids will be off and some are missing, they'll have to be fixed manually. For the SoundHandling class I used a sounds list that I found somewhere on here. I didn't add everything in, but that can once again be easily added onto.
Also, if you plan to add this, make sure you have http://www.rune-server.org/runescape...nds-music.html in your client.
- First create the package world.sound;
- Add the following java files inside there:
Sound.java
Spoiler for Sound:
SoundHandling.java
Spoiler for SoundHandling:
SongHandling.java (I've rewritten this class to not use an enum. You'll need to load the data through a json file, download songData.json - Pastebin.com and put it in ./data/songs/songData.json)
Spoiler for SongHandler:
SongLocation.java
Spoiler for SongLocation:
SongData.java
Spoiler for SongData:- In Main.java add this under the new DoorHandler(); and its logger.
Code:SongHandler.readFile(); logger.info("The song system is now running...");- Now in your Player.java file add the two methods:
Code:public void playSound(SoundHandler sound) { if (isPlayer()) { Player player = (Player) this; player.getPacketBuilder().sendSound(sound.getId(), sound.getType(), sound.getDelay(), sound.getVolume()); } } public void playSong(SongHandler sound) { if (isPlayer()) { Player player = (Player) this; player.getPacketBuilder().sendSong(sound.getId()); } }- Now in your PacketEncoder.java file, find sendSound, replace that and add the other methods below:
Code:public PacketEncoder sendSound(int id, int type, int delay, int volume) { PacketBuffer.WriteBuffer out = PacketBuffer.newWriteBuffer(8); out.writeHeader(174); out.writeShort(id); out.writeByte(type); out.writeShort(delay); out.writeShort(volume); player.getSession().encode(out); return this; } public PacketEncoder sendSong(int id) { PacketBuffer.WriteBuffer out = PacketBuffer.newWriteBuffer(2); out.writeHeader(74); out.writeShort(id); player.getSession().encode(out); return this; } public PacketEncoder sendQuickSong(int id, int delay) { PacketBuffer.WriteBuffer out = PacketBuffer.newWriteBuffer(8); out.writeHeader(121); out.writeShort(id); out.writeShort(delay); player.getSession().encode(out); return this; }- Here is a simple debug method if you want it, add it below sendMessage:
Code:public PacketEncoder debugMessage(String message) { if (Config.DEBUG_MODE && player.getStaffRights() >= 1) { PacketBuffer.WriteBuffer out = PacketBuffer.newWriteBuffer(message.length() + 3); out.writeVariablePacketHeader(253); out.writeString("[Debug] " + message); out.finishVariablePacketHeader(); player.getSession().encode(out); return this; } return null; }- Here are two commands:
Code:if (cmd[0].equals("sound")) { int id = Integer.parseInt(cmd[1]); int type = Integer.parseInt(cmd[2]); int delay = Integer.parseInt(cmd[3]); int volume = Integer.parseInt(cmd[4]); player.playSound(new SoundHandler(id, type, delay, volume)); return; } if (cmd[0].equals("song")) { int id = Integer.parseInt(cmd[1]); player.playSong(new SongHandler(id)); return; }- For example to add a sound effect I'll supply you with a basic one, go to your DecodeDropItemPacket.java file, and under "if (player.getInventory().getContainer().contains(ite m)) {" add:
Code:if (item == 995) { player.playSound(new SoundHandler(getMisc.DROP_MONEY.getSoundId())); } else { player.playSound(new SoundHandler(getMisc.DROP_ITEM.getSoundId())); }- For the songs, just go to your MovementQueue.java and add in the playSong method there.
e.g. player.playSong(new SongHandler(player, player.getPosition()));
Once again, this is mainly just to be used as a base, and you'll have to add any other things. Enjoy
Last edited by mr giggles; 09-07-2014 at 02:22 AM. Reason: updating classes
Why are you adding the methods in Entity instead of Player? Npcs etc can't play songs so it doesn't make sense to put them there. Also, as you say, load this from json or some other format - this is far too much data to put in a class.
I'm happy that more and more people are starting to use Asteria..
Goodjob on this one !
i have mine loaded through xml, nice though.
I've got sounds being handled through JSON for Asteria. Good job, though!
PLEASE load that data through JSON or some other external file, as major stated all of that data really shouldn't be loaded in an enum
Yes, if you make it load the data through JSON, it would be cool
Thanks for this, though.
I've converted it to a json for anyone that wants it.
songData.json - Pastebin.com
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |