Raised This Month: $32 Target: $400
 8% 

change sound from everybody to only attacker


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
combocarte112
Senior Member
Join Date: Jun 2016
Location: Romania
Old 04-05-2020 , 13:19   change sound from everybody to only attacker
Reply With Quote #1

Hello
I want to hear the sound only at the attacker, not to everyone or to the one killed.
Please help me!

Code:
#include <sourcemod>
#include <sdktools>
#include <sdktools_sound>

#define PLUGIN_VERSION "3.1"
#pragma semicolon 1

EngineVersion g_EngineVersion;

new Handle:ksSoundFile = INVALID_HANDLE;
new String:ksSoundName[PLATFORM_MAX_PATH];

new Handle:ksSoundPath = INVALID_HANDLE;
new Handle:ksSoundFiles = INVALID_HANDLE;

new Handle:ksEnabled = INVALID_HANDLE;
new Handle:ksRandom = INVALID_HANDLE;
new Handle:ksOnlyClient = INVALID_HANDLE;

public Plugin:myinfo =
{
	name = "KnifeSound 3.0",
	author = "IceQ?!",
	description = "Plays a specified or random sound when a player gets killed with a knife",
	version = PLUGIN_VERSION,
	url = "https://steamcommunity.com/id/official_iceq"
};

public OnPluginStart()
{
	g_EngineVersion = GetEngineVersion();
	
	ksSoundFiles = CreateArray(PLATFORM_MAX_PATH);
	
	CreateConVar("sm_knifesound_version", PLUGIN_VERSION, "Plays a specified or random sound when a player gets killed with a knife", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	ksEnabled = CreateConVar("sm_knifesound_enable", "1", "0: Disable Plugin | 1: Enable Plugin");
	ksSoundFile = CreateConVar("sm_knifesound_file", "knifesound/mc.mp3",	"Customizable Knifesound File ( without sound/ )");	
	ksSoundPath = CreateConVar("sm_knifesound_path", "knifesound",	"Customizable Knifesound Path ( without sound/ )");
	ksRandom = CreateConVar("sm_knifesound_random", "0", "0: Plays the specified sound file | 1: Plays a random sound file from path");
	ksOnlyClient = CreateConVar("sm_knifesound_client_only", "0", "0: Plays the sound to everybody | 1: Plays the sound only to the killed player");
	HookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre);
}

public OnConfigsExecuted()
{
	GetConVarString(ksSoundFile, ksSoundName, PLATFORM_MAX_PATH);
	FetchAllSoundFiles();
}

FetchAllSoundFiles()
{
	ClearArray(ksSoundFiles);
	
	decl String:sound_dir[PLATFORM_MAX_PATH];
	GetConVarString(ksSoundPath, sound_dir, sizeof(sound_dir));

	decl String:sound_path[PLATFORM_MAX_PATH];
	Format(sound_path, sizeof(sound_path), "sound/%s", sound_dir);
	if (!DirExists(sound_path)) {
		LogError("Directory '%s' does not exist.", sound_path);
		return;
	}
	
	new Handle:h_dir = OpenDirectory(sound_path);
	if (h_dir == INVALID_HANDLE) {
		LogError("'%s'", sound_path);
		return;
	}
	
	new FileType:type = FileType_Unknown;
	new String:filename[PLATFORM_MAX_PATH];
	while (ReadDirEntry(h_dir, filename, sizeof(filename), type))
	{
		if (type != FileType_File) {
			continue;
		}
		decl String:file_ext[5];
		strcopy(file_ext, sizeof(file_ext), filename[strlen(filename) - 4]);
		if (strcmp(file_ext, ".mp3", false) != 0) {
			continue;
		}
		Format(filename, sizeof(filename), "%s/%s", sound_dir, filename);
		PushArrayString(ksSoundFiles, filename);
	}
	if (GetArraySize(ksSoundFiles) == 0)
	{
		LogError("Cannot find any sound files. Path: '%s'", sound_path);
	}
	
	new sounds = GetArraySize(ksSoundFiles);
	decl String:buffer[PLATFORM_MAX_PATH];
	for (new i = 0; i < sounds; i++)
	{
		GetArrayString(ksSoundFiles, i, buffer, sizeof(buffer));
		PrecacheSound(buffer, true);
		Format(buffer, sizeof(buffer), "sound/%s", buffer);
		AddFileToDownloadsTable(buffer);
	}
}



public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{	
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	
	if (client == 0 || attacker == 0 || client == attacker) {
		return Plugin_Continue;
	}

	decl String:weapon[32];	
	GetEventString(event, "weapon", weapon, sizeof(weapon));		
	
	new bool:isEnabled = GetConVarBool(ksEnabled);
	new bool:isRandom = GetConVarBool(ksRandom);
	new bool:clientOnly = GetConVarBool();
	new bool:isCSGO = g_EngineVersion == Engine_CSGO;
	
	if (isEnabled) {
		if (StrContains(weapon, "knife", false) != -1 || (isCSGO && StrContains(weapon, "bayonet", false) != -1)) {
			if (isRandom) {
				decl String:random_sound[PLATFORM_MAX_PATH];
				new random = GetRandomInt(0, GetArraySize(ksSoundFiles) - 1);
				GetArrayString(ksSoundFiles, random, random_sound, sizeof(random_sound));
				if (clientOnly)
					EmitSoundToClient(client, random_sound);		
				else
					EmitSoundToAll(random_sound);
			} else {
				if (clientOnly)
					EmitSoundToClient(client, ksSoundName);		
				else
					EmitSoundToAll(ksSoundName);
			}
		}
	}
	
	return Plugin_Continue;
}
combocarte112 is offline
Send a message via Skype™ to combocarte112
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 04-06-2020 , 02:27   Re: change sound from everybody to only attacker
Reply With Quote #2

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdktools_sound>

#define PLUGIN_VERSION "3.1"
#pragma semicolon 1

EngineVersion g_EngineVersion;

new 
Handle:ksSoundFile INVALID_HANDLE;
new 
String:ksSoundName[PLATFORM_MAX_PATH];

new 
Handle:ksSoundPath INVALID_HANDLE;
new 
Handle:ksSoundFiles INVALID_HANDLE;

new 
Handle:ksEnabled INVALID_HANDLE;
new 
Handle:ksRandom INVALID_HANDLE;
new 
Handle:ksOnlyClient INVALID_HANDLE;

public 
Plugin:myinfo =
{
    
name "KnifeSound 3.0",
    
author "IceQ?!",
    
description "Plays a specified or random sound when a player gets killed with a knife",
    
version PLUGIN_VERSION,
    
url "https://steamcommunity.com/id/official_iceq"
};

public 
OnPluginStart()
{
    
g_EngineVersion GetEngineVersion();
    
    
ksSoundFiles CreateArray(PLATFORM_MAX_PATH);
    
    
CreateConVar("sm_knifesound_version"PLUGIN_VERSION"Plays a specified or random sound when a player gets killed with a knife"FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
ksEnabled CreateConVar("sm_knifesound_enable""1""0: Disable Plugin | 1: Enable Plugin");
    
ksSoundFile CreateConVar("sm_knifesound_file""knifesound/mc.mp3",    "Customizable Knifesound File ( without sound/ )");    
    
ksSoundPath CreateConVar("sm_knifesound_path""knifesound",    "Customizable Knifesound Path ( without sound/ )");
    
ksRandom CreateConVar("sm_knifesound_random""0""0: Plays the specified sound file | 1: Plays a random sound file from path");
    
ksOnlyClient CreateConVar("sm_knifesound_client_only""0""0: Plays the sound to everybody | 1: Plays the sound only to the killed player");
    
HookEvent("player_death"Event_PlayerDeathEventHookMode_Pre);
}

public 
OnConfigsExecuted()
{
    
GetConVarString(ksSoundFileksSoundNamePLATFORM_MAX_PATH);
    
FetchAllSoundFiles();
}

FetchAllSoundFiles()
{
    
ClearArray(ksSoundFiles);
    
    
decl String:sound_dir[PLATFORM_MAX_PATH];
    
GetConVarString(ksSoundPathsound_dirsizeof(sound_dir));

    
decl String:sound_path[PLATFORM_MAX_PATH];
    
Format(sound_pathsizeof(sound_path), "sound/%s"sound_dir);
    if (!
DirExists(sound_path)) {
        
LogError("Directory '%s' does not exist."sound_path);
        return;
    }
    
    new 
Handle:h_dir OpenDirectory(sound_path);
    if (
h_dir == INVALID_HANDLE) {
        
LogError("'%s'"sound_path);
        return;
    }
    
    new 
FileType:type FileType_Unknown;
    new 
String:filename[PLATFORM_MAX_PATH];
    while (
ReadDirEntry(h_dirfilenamesizeof(filename), type))
    {
        if (
type != FileType_File) {
            continue;
        }
        
decl String:file_ext[5];
        
strcopy(file_extsizeof(file_ext), filename[strlen(filename) - 4]);
        if (
strcmp(file_ext".mp3"false) != 0) {
            continue;
        }
        
Format(filenamesizeof(filename), "%s/%s"sound_dirfilename);
        
PushArrayString(ksSoundFilesfilename);
    }
    if (
GetArraySize(ksSoundFiles) == 0)
    {
        
LogError("Cannot find any sound files. Path: '%s'"sound_path);
    }
    
    new 
sounds GetArraySize(ksSoundFiles);
    
decl String:buffer[PLATFORM_MAX_PATH];
    for (new 
0soundsi++)
    {
        
GetArrayString(ksSoundFilesibuffersizeof(buffer));
        
PrecacheSound(buffertrue);
        
Format(buffersizeof(buffer), "sound/%s"buffer);
        
AddFileToDownloadsTable(buffer);
    }
}



public 
Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{    
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
    if (
client == || attacker == || client == attacker) {
        return 
Plugin_Continue;
    }

    
decl String:weapon[32];    
    
GetEventString(event"weapon"weaponsizeof(weapon));        
    
    new 
bool:isEnabled GetConVarBool(ksEnabled);
    new 
bool:isRandom GetConVarBool(ksRandom);
    new 
bool:clientOnly GetConVarBool();
    new 
bool:isCSGO g_EngineVersion == Engine_CSGO;
    
    if (
isEnabled) {
        if (
StrContains(weapon"knife"false) != -|| (isCSGO && StrContains(weapon"bayonet"false) != -1)) {
            if (
isRandom) {
                
decl String:random_sound[PLATFORM_MAX_PATH];
                new 
random GetRandomInt(0GetArraySize(ksSoundFiles) - 1);
                
GetArrayString(ksSoundFilesrandomrandom_soundsizeof(random_sound));
                
EmitSoundToClient(attackerrandom_sound);        
            } else {
                
EmitSoundToClient(attackerksSoundName);        
            }
        }
    }
    
    return 
Plugin_Continue;

__________________
8guawong is offline
combocarte112
Senior Member
Join Date: Jun 2016
Location: Romania
Old 04-13-2020 , 03:00   Re: change sound from everybody to only attacker
Reply With Quote #3

Quote:
Originally Posted by 8guawong View Post
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdktools_sound>

#define PLUGIN_VERSION "3.1"
#pragma semicolon 1

EngineVersion g_EngineVersion;

new 
Handle:ksSoundFile INVALID_HANDLE;
new 
String:ksSoundName[PLATFORM_MAX_PATH];

new 
Handle:ksSoundPath INVALID_HANDLE;
new 
Handle:ksSoundFiles INVALID_HANDLE;

new 
Handle:ksEnabled INVALID_HANDLE;
new 
Handle:ksRandom INVALID_HANDLE;
new 
Handle:ksOnlyClient INVALID_HANDLE;

public 
Plugin:myinfo =
{
    
name "KnifeSound 3.0",
    
author "IceQ?!",
    
description "Plays a specified or random sound when a player gets killed with a knife",
    
version PLUGIN_VERSION,
    
url "https://steamcommunity.com/id/official_iceq"
};

public 
OnPluginStart()
{
    
g_EngineVersion GetEngineVersion();
    
    
ksSoundFiles CreateArray(PLATFORM_MAX_PATH);
    
    
CreateConVar("sm_knifesound_version"PLUGIN_VERSION"Plays a specified or random sound when a player gets killed with a knife"FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
ksEnabled CreateConVar("sm_knifesound_enable""1""0: Disable Plugin | 1: Enable Plugin");
    
ksSoundFile CreateConVar("sm_knifesound_file""knifesound/mc.mp3",    "Customizable Knifesound File ( without sound/ )");    
    
ksSoundPath CreateConVar("sm_knifesound_path""knifesound",    "Customizable Knifesound Path ( without sound/ )");
    
ksRandom CreateConVar("sm_knifesound_random""0""0: Plays the specified sound file | 1: Plays a random sound file from path");
    
ksOnlyClient CreateConVar("sm_knifesound_client_only""0""0: Plays the sound to everybody | 1: Plays the sound only to the killed player");
    
HookEvent("player_death"Event_PlayerDeathEventHookMode_Pre);
}

public 
OnConfigsExecuted()
{
    
GetConVarString(ksSoundFileksSoundNamePLATFORM_MAX_PATH);
    
FetchAllSoundFiles();
}

FetchAllSoundFiles()
{
    
ClearArray(ksSoundFiles);
    
    
decl String:sound_dir[PLATFORM_MAX_PATH];
    
GetConVarString(ksSoundPathsound_dirsizeof(sound_dir));

    
decl String:sound_path[PLATFORM_MAX_PATH];
    
Format(sound_pathsizeof(sound_path), "sound/%s"sound_dir);
    if (!
DirExists(sound_path)) {
        
LogError("Directory '%s' does not exist."sound_path);
        return;
    }
    
    new 
Handle:h_dir OpenDirectory(sound_path);
    if (
h_dir == INVALID_HANDLE) {
        
LogError("'%s'"sound_path);
        return;
    }
    
    new 
FileType:type FileType_Unknown;
    new 
String:filename[PLATFORM_MAX_PATH];
    while (
ReadDirEntry(h_dirfilenamesizeof(filename), type))
    {
        if (
type != FileType_File) {
            continue;
        }
        
decl String:file_ext[5];
        
strcopy(file_extsizeof(file_ext), filename[strlen(filename) - 4]);
        if (
strcmp(file_ext".mp3"false) != 0) {
            continue;
        }
        
Format(filenamesizeof(filename), "%s/%s"sound_dirfilename);
        
PushArrayString(ksSoundFilesfilename);
    }
    if (
GetArraySize(ksSoundFiles) == 0)
    {
        
LogError("Cannot find any sound files. Path: '%s'"sound_path);
    }
    
    new 
sounds GetArraySize(ksSoundFiles);
    
decl String:buffer[PLATFORM_MAX_PATH];
    for (new 
0soundsi++)
    {
        
GetArrayString(ksSoundFilesibuffersizeof(buffer));
        
PrecacheSound(buffertrue);
        
Format(buffersizeof(buffer), "sound/%s"buffer);
        
AddFileToDownloadsTable(buffer);
    }
}



public 
Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{    
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
    if (
client == || attacker == || client == attacker) {
        return 
Plugin_Continue;
    }

    
decl String:weapon[32];    
    
GetEventString(event"weapon"weaponsizeof(weapon));        
    
    new 
bool:isEnabled GetConVarBool(ksEnabled);
    new 
bool:isRandom GetConVarBool(ksRandom);
    new 
bool:clientOnly GetConVarBool();
    new 
bool:isCSGO g_EngineVersion == Engine_CSGO;
    
    if (
isEnabled) {
        if (
StrContains(weapon"knife"false) != -|| (isCSGO && StrContains(weapon"bayonet"false) != -1)) {
            if (
isRandom) {
                
decl String:random_sound[PLATFORM_MAX_PATH];
                new 
random GetRandomInt(0GetArraySize(ksSoundFiles) - 1);
                
GetArrayString(ksSoundFilesrandomrandom_soundsizeof(random_sound));
                
EmitSoundToClient(attackerrandom_sound);        
            } else {
                
EmitSoundToClient(attackerksSoundName);        
            }
        }
    }
    
    return 
Plugin_Continue;

SourcePawn Compiler 1.10
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC

plugin.sp(117) : error 092: number of arguments does not match definition
plugin.sp(117) : warning 204: symbol is assigned a value that is never used: "clientOnly"
plugin.sp(40) : warning 204: symbol is assigned a value that is never used: "ksOnlyClient"

1 Error.

Not working.
combocarte112 is offline
Send a message via Skype™ to combocarte112
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 04-13-2020 , 03:24   Re: change sound from everybody to only attacker
Reply With Quote #4

Quote:
Originally Posted by combocarte112 View Post
SourcePawn Compiler 1.10
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC

plugin.sp(117) : error 092: number of arguments does not match definition
plugin.sp(117) : warning 204: symbol is assigned a value that is never used: "clientOnly"
plugin.sp(40) : warning 204: symbol is assigned a value that is never used: "ksOnlyClient"

1 Error.

Not working.
Attached Files
File Type: sp Get Plugin or Get Source (KnifeSound.sp - 110 views - 4.3 KB)
__________________

Last edited by 8guawong; 04-13-2020 at 03:27.
8guawong is offline
combocarte112
Senior Member
Join Date: Jun 2016
Location: Romania
Old 04-13-2020 , 03:29   Re: change sound from everybody to only attacker
Reply With Quote #5

thx man
combocarte112 is offline
Send a message via Skype™ to combocarte112
combocarte112
Senior Member
Join Date: Jun 2016
Location: Romania
Old 04-13-2020 , 06:49   Re: change sound from everybody to only attacker
Reply With Quote #6

the sound does not download when I enter the server
combocarte112 is offline
Send a message via Skype™ to combocarte112
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-14-2020 , 07:13   Re: change sound from everybody to only attacker
Reply With Quote #7

Look log errors from sourcemod logs.
__________________
Do not Private Message @me
Bacardi is offline
combocarte112
Senior Member
Join Date: Jun 2016
Location: Romania
Old 04-14-2020 , 08:46   Re: change sound from everybody to only attacker
Reply With Quote #8

Quote:
Originally Posted by Bacardi View Post
Look log errors from sourcemod logs.
I have no error, but the plugin does not download my audio file
combocarte112 is offline
Send a message via Skype™ to combocarte112
Reply


Thread Tools
Display Modes

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 14:58.


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