Thread: Simple weapon sound system

Results 1 to 5 of 5
  1. #1 Simple weapon sound system 
    Registered Member

    Join Date
    Sep 2008
    Posts
    2,219
    Thanks given
    148
    Thanks received
    204
    Rep Power
    1570
    A few things that I've added since I posted this:
    • Added special support
    • Added a command and option for toggling sound


    Code:
    /*
     * Class Sounds
     *
     * Version 1.0
     *
     * Sunday, November 1, 2009
     *
     * Created by Aeterna
     */
    public class Sounds {
    
    	/*
    	 * A reference to the Client class.
    	 */
    	public Client c;
    
    	/*
    	 * Declares the ID of the sound that will play.
    	 */
    	public int weaponSound;
    	/*
    	 * An array containing the weapon, and it's sound.
    	 * Used as {weapon, normalSound, specialSound}
    	 */
    	public final int[][] WEAPON_SOUNDS = {
    		{4151, 1080, 1081}, {1319, 400, 398}, {1377, 399, 398}, {861, 370, 398},
    		{4675, 394, 398}, {1333, 396, 398}, {5698, 398, 398}
    	};
    	
    	/*
    	 * Class constructor.
    	 */
    	public Sounds(Client c) {
    		this.c = c;
    	}
    
    	/*
    	 * Returns the sound that will play depending on the current weapon, and if they player
    	 * is using a special attack.
    	 */
    	public int getSound(int weapon) {
    		for (int[] WEAPON_SOUNDS : weapons) {
    			if (weapon == weapons[0]) {
    				if (c.usingSpecial) {
    					weaponSound = weapons[1];
    				} else {
    					weaponSound = weapons[2];
    				}
    			}
    		}
    		return weaponSound;
    	}
    
    }
    Code:
    	/**
    	 * Attempts to play a midi.
    	 * @param sound The sound ID which is going to be played.
    	 * @param distance The distance or 'delay' between the player and the sound.
    	 * @param volume How loud the sound will be played.
    	 */
    	public void playSound(int sound, int distance, int volume) {
    		if (usingSound) {
    			outStream.createFrame(174);
    			outStream.writeWord(sound);
    			outStream.writeByte(distance);
    			outStream.writeWord(volume);
    		} else {
    			sM("You do not have sound enabled.  To enable it type ::sound ON");
    		}
    	}
    Code:
    	/*
    	 * Attemtps to call the class Sound.
    	 */
    	Sound sound = new Sound(this);
    Code:
    	playSound(sound.getSound(playerEquipment[playerWeapon]), 50, 0);
    Code:
    /*
     * A command used for toggling sound on and off.
     * Usage: ::sound off, ::sound on
     */
    if (command.startsWith("sound")) {
    	String[] args = command.split(" ");
    	if (args[1].equalsIgnoreCase("on")) {
    		usingSound = true;
    		sendMessag("You have toggled sound on.");
    	} else if (args[1].equalsIgnoreCase("off")) {
    		usingSound = false;
    		sendMessage("You have toggled sound off.");
    	} else {
    		sM("Invalid input.");
    	}
    }

    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  2. #2  
    Registered Member Ikea4Life's Avatar
    Join Date
    Aug 2009
    Posts
    200
    Thanks given
    87
    Thanks received
    4
    Rep Power
    46
    Cool.
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Jun 2008
    Age
    24
    Posts
    2,313
    Thanks given
    485
    Thanks received
    231
    Rep Power
    0
    By 'distance' between the sound and player, dont u mean delay?
    Reply With Quote  
     

  4. #4  
    Community Veteran

    Dexter Morgan's Avatar
    Join Date
    Nov 2008
    Age
    16
    Posts
    4,364
    Thanks given
    1,027
    Thanks received
    703
    Discord
    View profile
    Rep Power
    2991
    Quote Originally Posted by JINRAKE View Post
    By 'distance' between the sound and player, dont u mean delay?
    Uh no shits.

    I've tested and it works.
    [Only registered and activated users can see links. ]
    Quote Originally Posted by UberNation View Post
    Did you update the quantum network sockets to match the polarity of the wilderness counter levels in the Boolean that divides the wilderness level by zero?
    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Sep 2008
    Posts
    2,219
    Thanks given
    148
    Thanks received
    204
    Rep Power
    1570
    Thanks for letting me know.

    I added specials and a command for toggling.

    [Only registered and activated users can see links. ]

    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •