Raised This Month: $ Target: $400
 0% 

Reproduce sound every third murder.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sutar
Senior Member
Join Date: Sep 2010
Old 08-22-2012 , 10:33   Reproduce sound every third murder.
Reply With Quote #1

Here there is a plugin (I wrote myself) it reproduces sounds: multikill, megakill and other.

For example:
I killed 3 players and play sound multikill.
I killed 3 more players and play sound megakill.
I killed 3 more players and play sound ultrakill.
I killed 3 more players and play sound godlike.

But the problem is that if I killed 3 players, and then a further 3 plays sound godlike. ie passes 2 audio, megakill and ultrakill.

What's the problem?

Code:
#include <amxmodx>
#include <csx>
#include <cstrike>

new g_streakKills[33][1]

new g_Sounds[10][] =
{
	"multikill",
	"megakill",
	"ultrakill",
	"godlike",
	"rampage", 
	"wickedsick",
	"killingspree",
	"unstoppable",
	"monsterkill",
	"ludacrisskill"
}

public plugin_init()
{
	register_plugin("Music Stats", "2.0", "Sutar")
}

public client_putinserver(id)
	g_streakKills[id] = {0}

public client_death(killer, victim, wpnindex, hitplace, TK)
{
	if(wpnindex == CSW_C4)
		return

	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
		}
	}

	return
}

public play_sound(sound[])
{
	new players[32], pnum
	get_players(players, pnum, "c")

	for(new i = 0; i < pnum; i++)
	{
		if(is_user_connecting(players[i]))
			continue
		
		client_cmd(players[i], "spk %s", sound)
	}
}
Sutar is offline
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
Sutar
Senior Member
Join Date: Sep 2010
Old 08-22-2012 , 11:32   Re: Reproduce sound every third murder.
Reply With Quote #3

The best code will be like this?

Code:
#include <cstrike>

new g_streakKills[33]

new g_Sounds[10][] =
{
	"multikill",
	"megakill",
	"ultrakill",
	"godlike",
	"rampage", 
	"wickedsick",
	"killingspree",
	"unstoppable",
	"monsterkill",
	"ludacrisskill"
}

public plugin_init()
{
	register_plugin("Music Stats", "2.0", "Sutar")
}

public client_putinserver(id)
	g_streakKills[id] = {0}

public client_death(killer, victim, wpnindex, hitplace, TK)
{
	if(wpnindex == CSW_C4)
		return

	new headshot = (hitplace == HIT_HEAD) ? 1 : 0;
	new selfkill = (killer == victim) ? 1 : 0;

	if(!TK && !selfkill && killer)
	{
		g_streakKills[victim] = 0;
      		new a = g_streakKills[killer]++;
        
		if(a % 3 == 0)
		{
			if(a/= 3 > 9)
				a = 5
            
			client_cmd(0, "spk misc/%s", g_Sounds[a])
			return
		} 
	}

	return
}
I need to play a sound to the player, every 3 of his murder.

For example:
I killed 2 players - no sound.
I Killed 3 - there was a sound (multikill).
Following the sound, kill 3 more - 2 sound (megakill).

Last edited by Sutar; 08-22-2012 at 11:38.
Sutar is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-22-2012 , 11:41   Re: Reproduce sound every third murder.
Reply With Quote #4

I'd say so. but you still need to prechace all the sound files and give them a file extension. see #2. 3. 6

EDIT: and i'm not sure the efficiency of client_death versus event_death But that isn't much of a problem to be honest....unless you really want to make the best code possible.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 08-22-2012 at 11:43.
Liverwiz is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-22-2012 , 11:51   Re: Reproduce sound every third murder.
Reply With Quote #5

Quote:
Originally Posted by Liverwiz View Post
3. sounds need to be in the sounds folder. not misc (i'm pretty sure) -correct me if i'm wrong
First, when using precache_sound() and the "spk" command, the "sound/" folder is implied.
The "misc/" folder in front will transform to "sound/misc/" for both precache and the "spk" command, so you don't need to put it there.
Quote:
Originally Posted by Liverwiz View Post
4. There's a better way to do the check. Here it is...
PHP Code:
        new g_streakKills[killer]++;    // Immediately store your increment into the temp var 
Actually, that will store the value before you add 1 to it, because the ++ is after the variable which makes it a POST increment.
This is the valid way:
PHP Code:
        new = ++g_streakKills[killer];    // Immediately store your increment into the temp var 
This way it increases the value in the streak kills array, and then stores that value into the "a" variable.
Quote:
Originally Posted by Liverwiz View Post
PHP Code:
            if(a/= 9
That is just ugly and confusing. Just put it on separate lines:
PHP Code:
            a /= 3;
            if(
9
Quote:
Originally Posted by Liverwiz View Post
6. ... But I'd suggest putting the entire file path into those strings just to make things a bit easier. (i.e. "sounds/multikill.wav", ) ...
Again, "sound" folder not needed.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Sutar
Senior Member
Join Date: Sep 2010
Old 08-22-2012 , 11:51   Re: Reproduce sound every third murder.
Reply With Quote #6

Code:
//AMXXPC compile.exe
// by the AMX Mod X Dev Team

//// miscstats.sma
// D:\Server\test_minimap1\cstrike\addons\amxmodx\scripting\miscstats.sma(44) :
warning 213: tag mismatch
// Header size:            312 bytes
// Code size:             1292 bytes
// Data size:             1908 bytes
// Stack/heap size:      16384 bytes; estimated max. usage=44 cells (176 bytes)
// Total requirements:   19896 bytes
//
// 2 Warnings.
// Done.
//
// Compilation Time: 0,14 sec
// ----------------------------------------

Press enter to exit ...
And the plugin does not play sounds in order for three murders.
Sutar is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-22-2012 , 12:13   Re: Reproduce sound every third murder.
Reply With Quote #7

Quote:
Originally Posted by Exolent[jNr] View Post
Actually, that will store the value before you add 1 to it, because the ++ is after the variable which makes it a POST increment.
This is the valid way:
PHP Code:
        new = ++g_streakKills[killer];    // Immediately store your increment into the temp var 
This way it increases the value in the streak kills array, and then stores that value into the "a" variable.
Oh, right. my bad.

As for the implication of sound.....lol, forgot that too. I've been told that before. I just never remember. -_-


Quote:
Originally Posted by Sutar View Post
Code:
//AMXXPC compile.exe
// by the AMX Mod X Dev Team

//// miscstats.sma
// D:\Server\test_minimap1\cstrike\addons\amxmodx\scripting\miscstats.sma(44) :
warning 213: tag mismatch
// Header size:            312 bytes
// Code size:             1292 bytes
// Data size:             1908 bytes
// Stack/heap size:      16384 bytes; estimated max. usage=44 cells (176 bytes)
// Total requirements:   19896 bytes
//
// 2 Warnings.
// Done.
//
// Compilation Time: 0,14 sec
// ----------------------------------------

Press enter to exit ...
And the plugin does not play sounds in order for three murders.
follow exolent's instructions
PHP Code:
          new = ++g_streakKills[killer];
        
        if(
== 0)
        {
            
a/= 3;
            if(
9)
                

The increment was in the improper order. This made it so you were dealing with old data, not the updated one. If exolent didn't explain it well enough here is a long, drawn out example....
Code:
// new a = g_streakKills[killer]++;    // this is the same as..... new a = g_streakKills[killer]; g_streakKills[killer] = g_streakKills[killer] + 1; // new a = ++g_streakKills[killer]    // this is the same as..... g_streakKills[killer] = g_streakKills[killer] + 1; new a = g_streakKills[killer];
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 08-22-2012 at 12:55.
Liverwiz is offline
Old 08-22-2012, 15:52
Sutar
This message has been deleted by Sutar. Reason: new Message
Sutar
Senior Member
Join Date: Sep 2010
Old 08-23-2012 , 03:59   Re: Reproduce sound every third murder.
Reply With Quote #8

The problem is, that does not play the first sound (multikill)

3 / 3 = 1

May need to take away from g_streakKills[killer] - 3?

For example:
Quote:
g_streakKills[killer] += 1;

new a = g_streakKills[killer] - 3;

if(a > 0 && !(a % 3))
{
a/= 3;
if(a > 9)
a = 5
And I'm doing this:

Quote:
if(headshot)
g_streakKills[killer][0] += 2;
else
g_streakKills[killer][0] += 1;
the killed in head += 2
Just killed += 1

But the problem is that if a player kills 2 times in the head, no sound.

For example:
Quote:
g_streakKills[killer] += 2 //one killed in head
g_streakKills[killer] += 2 //two killed in head (g_streakKills[killer] = 4)

new a = g_streakKills[killer] - 3;

if(a > 0 && !(a % 3)) //a = 1 and the function does not work on...
{
...
Sutar is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-23-2012 , 09:48   Re: Reproduce sound every third murder.
Reply With Quote #9

Try this:
PHP Code:
        new = ++g_streakKills[killer] - 3;    // Immediately store your increment into the temp var 
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-23-2012 , 10:48   Re: Reproduce sound every third murder.
Reply With Quote #10

Quote:
Originally Posted by Exolent[jNr] View Post
Try this:
PHP Code:
        new = ++g_streakKills[killer] - 3;    // Immediately store your increment into the temp var 
I was wondering why he subtracted 3 from that originally....
I apologize, Sutar, you were -mostly- right all along. Just needed a few tweaks.
Aren't we lucky to have such a smart guy like Exolent around to correct me when i'm being a dumbass?
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Reply



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