Raised This Month: $ Target: $400
 0% 

Reproduce sound every third murder.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-22-2012 , 11:02   Re: Reproduce sound every third murder.
Reply With Quote #2

There's a few things i have to say.
1. new g_streakKills[33][1] new g_streakKills[33] Its a simple array, you don't need to say it only has one row; that is implied when created. And confused me a bit when i first read it.
2. all your sounds need to be precached and have a filetype extension (.wav .mp3 etc)
3. sounds need to be in the sounds folder. not misc (i'm pretty sure) -correct me if i'm wrong
4. There's a better way to do the check. Here it is...
Code:
	new headshot = (hitplace == HIT_HEAD) ? 1 : 0;
	new selfkill = (killer == victim) ? 1 : 0;

	if(!TK && !selfkill && killer)
	{
		g_streakKills[victim][0] = 0;
		g_streakKills[killer][0] += 1;
		
		new a = g_streakKills[killer][0] - 3;
		
		if((a > -1) && !(a % 3))
		{
			if(a > 9)
				a = 5;
			
			new file[32]
			format(file, 31, "misc/%s", g_Sounds[a])
			play_sound(file)
			return
		}
	}

PHP Code:
        g_streakKills[victim] = 0;
        new 
g_streakKills[killer]++;    // Immediately store your increment into the temp var
        
        
if( == )     // all you need to worry about is if it is the third kill 
        
{
            if(
a/= 9)
                
5    // int division by 3 will get you what index you want
            
            
new file[32]
            
formatex(file31"misc/%s"g_Sounds[a])    // formatex is faster than format
            
play_sound(file)
            return
        } 
5. client_cmd(0, "spk %s", sound) Will work just fine without the loop. It'll be faster too and you won't need to check if user is alive. All around win.
6. You should also declare g_sounds as const new const g_sounds[][] = { Its just good habbit, because that never changes. But I'd suggest putting the entire file path into those strings just to make things a bit easier. (i.e. "sounds/multikill.wav", ) That way you can loop through g_sounds in plugin_precache and not need to add anything. Nor will you need to add anything later. All speeding up your code.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 08-22-2012 at 11:10.
Liverwiz is offline
 



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode