Raised This Month: $51 Target: $400
 12% 

How to add custom knife deploy sound


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fawkes37
Senior Member
Join Date: Jul 2008
Old 08-07-2020 , 00:58   How to add custom knife deploy sound
Reply With Quote #1

How to add a custom knife deploy sound? (The sound when they switch to knife.)

I tried adding to zp50_zombie_sounds of Zombie Plague, where the other attack/knife sounds are handled, but with no success (soundfile is 'weapons/knife_deploy1.wav', so we check for 'd', 'e', 'p' in specific indexes):
Code:
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;
}
Also adding the SMA file.

Thanks in advance
Attached Files
File Type: sma Get Plugin or Get Source (zp50_zombie_sounds.sma - 81 views - 22.2 KB)
Fawkes37 is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 08-07-2020 , 01:55   Re: How to add custom knife deploy sound
Reply With Quote #2

Quote:
Originally Posted by Fawkes37 View Post
How to add a custom knife deploy sound? (The sound when they switch to knife.)

I tried adding to zp50_zombie_sounds of Zombie Plague, where the other attack/knife sounds are handled, but with no success (soundfile is 'weapons/knife_deploy1.wav', so we check for 'd', 'e', 'p' in specific indexes):
Code:
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;
}
Also adding the SMA file.

Thanks in advance
For zombies or for humans?

Last edited by AnimalMonster; 08-07-2020 at 01:56.
AnimalMonster is offline
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
Fawkes37
Senior Member
Join Date: Jul 2008
Old 08-07-2020 , 16:38   Re: How to add custom knife deploy sound
Reply With Quote #4

Ok, so this seems to work for both humans and zombies:
Code:
public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch)
{
	static sound[SOUND_MAX_LENGTH]
	if (sample[14] == 'd' && sample[15] == 'e' && sample[16] == 'p')
	{
		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;
	}
	return FMRES_IGNORED;
}
But this doesn't:
Code:
public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch)
{
	static sound[SOUND_MAX_LENGTH]
	if (zp_core_is_zombie(id) && sample[14] == 'd' && sample[15] == 'e' && sample[16] == 'p')
	{
		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;
	}
	return FMRES_IGNORED;
}
This tells me that in Zombie Plague, we switch to knife before we are declared as a zombie. As I want to change this sound only for zombies and not humans, is there another check we can do to assure that? I wouldn't want to dig too deep into ZP core to make changes just for this.

Last edited by Fawkes37; 08-07-2020 at 16:39.
Fawkes37 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 02:56.


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