Raised This Month: $ Target: $400
 0% 

How to add custom knife deploy sound


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Fawkes37
Senior Member
Join Date: Jul 2008
Old 08-07-2020 , 08:31   Re: How to add custom knife deploy sound
Reply With Quote #3

For zombies and nemesis. If its too cumbersome to find what I've added in that sma, here is ONLY my code's part:


Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <amx_settings_api>
#include <cs_ham_bots_api>
#include <zp50_core>
#define LIBRARY_NEMESIS "zp50_class_nemesis"
#include <zp50_class_nemesis>

// Settings file
new const ZP_SETTINGS_FILE[] = "zombieplague.ini"

new const sound_nemesis_draw_knife[][] = { "items/equip_nvg.wav" }
new const sound_zombie_draw_knife[][] = { "items/equip_nvg.wav" }

#define SOUND_MAX_LENGTH 64

// Custom sounds
new Array:g_sound_nemesis_draw_knife
new Array:g_sound_zombie_draw_knife

new cvar_nemesis_sounds_attack, cvar_zombie_sounds_attack

public plugin_init()
{
	register_plugin("[ZP] Zombie Sounds", ZP_VERSION_STRING, "ZP Dev Team")
	
	register_forward(FM_EmitSound, "fw_EmitSound")
	RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
	RegisterHamBots(Ham_Killed, "fw_PlayerKilled")
	
	cvar_zombie_sounds_attack = register_cvar("zp_zombie_sounds_attack", "1")
	cvar_nemesis_sounds_attack = register_cvar("zp_nemesis_sounds_attack", "1")
}

public plugin_precache()
{
	// Initialize arrays
	g_sound_nemesis_draw_knife = ArrayCreate(SOUND_MAX_LENGTH, 1)
	g_sound_zombie_draw_knife = ArrayCreate(SOUND_MAX_LENGTH, 1)
	
	// Load from external file
	amx_load_setting_string_arr(ZP_SETTINGS_FILE, "Sounds", "NEMESIS DRAW KNIFE", g_sound_nemesis_draw_knife)
	amx_load_setting_string_arr(ZP_SETTINGS_FILE, "Sounds", "ZOMBIE DRAW KNIFE", g_sound_zombie_draw_knife)
	
	// If we couldn't load custom sounds from file, use and save default ones
	new index
	if (ArraySize(g_sound_nemesis_draw_knife) == 0)
	{
		for (index = 0; index < sizeof sound_nemesis_draw_knife; index++)
			ArrayPushString(g_sound_nemesis_draw_knife, sound_nemesis_draw_knife[index])
		
		// Save to external file
		amx_save_setting_string_arr(ZP_SETTINGS_FILE, "Sounds", "NEMESIS DRAW KNIFE", g_sound_nemesis_draw_knife)
	}
	if (ArraySize(g_sound_zombie_draw_knife) == 0)
	{
		for (index = 0; index < sizeof sound_zombie_draw_knife; index++)
			ArrayPushString(g_sound_zombie_draw_knife, sound_zombie_draw_knife[index])
		
		// Save to external file
		amx_save_setting_string_arr(ZP_SETTINGS_FILE, "Sounds", "ZOMBIE DRAW KNIFE", g_sound_zombie_draw_knife)
	}
	
	// Precache sounds
	new sound[SOUND_MAX_LENGTH]
// Nemesis Class loaded?
	if (LibraryExists(LIBRARY_NEMESIS, LibType_Library))
	{
		for (index = 0; index < ArraySize(g_sound_nemesis_draw_knife); index++)
		{
			ArrayGetString(g_sound_nemesis_draw_knife, index, sound, charsmax(sound))
			precache_sound(sound)
		}
	}	
	for (index = 0; index < ArraySize(g_sound_zombie_draw_knife); index++)
	{
		ArrayGetString(g_sound_zombie_draw_knife, index, sound, charsmax(sound))
		precache_sound(sound)
	}
}

public plugin_natives()
{
	set_module_filter("module_filter")
	set_native_filter("native_filter")
}

public module_filter(const module[])
{
	if (equal(module, LIBRARY_NEMESIS))
		return PLUGIN_HANDLED;
	
	return PLUGIN_CONTINUE;
}

public native_filter(const name[], index, trap)
{
	if (!trap)
		return PLUGIN_HANDLED;
		
	return PLUGIN_CONTINUE;
}

// Emit Sound Forward
public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch)
{
	// Replace these next sounds for zombies only
	if (!is_user_connected(id) || !zp_core_is_zombie(id))
		return FMRES_IGNORED;
	
	static sound[SOUND_MAX_LENGTH]
	
	if (get_pcvar_num(cvar_zombie_sounds_attack) || get_pcvar_num(cvar_nemesis_sounds_attack))
	{
		// Zombie attacks with knife
		if (sample[8] == 'k' && sample[9] == 'n' && sample[10] == 'i')
		{
			// Nemesis Class loaded?
			if (LibraryExists(LIBRARY_NEMESIS, LibType_Library) && zp_class_nemesis_get(id) && get_pcvar_num(cvar_nemesis_sounds_attack))
			{
				if (sample[14] == 'd' && sample[15] == 'e' && sample[16] == 'p') // deploy
				{
					ArrayGetString(g_sound_nemesis_draw_knife, random_num(0, ArraySize(g_sound_nemesis_draw_knife) - 1), sound, charsmax(sound))
					emit_sound(id, channel, sound, volume, attn, flags, pitch)
					return FMRES_SUPERCEDE;
				}
			}
			else if (get_pcvar_num(cvar_zombie_sounds_attack) && !zp_class_nemesis_get(id))
			{
				if (sample[14] == 'd' && sample[15] == 'e' && sample[16] == 'p') // deploy
				{
					ArrayGetString(g_sound_zombie_draw_knife, random_num(0, ArraySize(g_sound_zombie_draw_knife) - 1), sound, charsmax(sound))
					emit_sound(id, channel, sound, volume, attn, flags, pitch)
					return FMRES_SUPERCEDE;
				}
			}
		}
	}
	
	return FMRES_IGNORED;
}

Last edited by Fawkes37; 08-07-2020 at 08:51.
Fawkes37 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 13:54.


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