okay, here we go, this is a little more 'advanced' in my opinion, so heres the problem... im trying to:
make it load the sounds from a file [
deathsounds.ini] status:
SUCCESS
make it precache the sounds in [
deathsounds.ini] status:
SUCCESS
make it play a random sound when user dies from [
deathsounds.ini] status:
FAIL
the source is NOT cake, so here..
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <HamSandwich>
#define PLUGIN "Death Noise"
#define AUTHOR "HLM A.K.A Master"
#define VERSION "1.0"
/* credit goes to TheRadiance ( https://forums.alliedmods.net/member.php?u=32826 ) for sound precaching and loading */
new bool:player_should_hear_sound[33] //booleans can only be true or false (on or off)
new g_szPrecached [ 32 ] [ 64 ]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
RegisterHam(Ham_Killed, "player" , "ham_player_killed", 1)
register_clcmd("amx_deathmsg","blocksounds",_,"<^"on^" | ^"off^"> - Enables/Disables the death sound")
}
public client_putinserver(id)
{
set_task(25.0, "show_info", id)
}
public plugin_precache ( )
{
new szPath [ 64 ]
get_configsdir ( szPath, sizeof ( szPath ) - 1 )
format ( szPath, sizeof ( szPath ) - 1, "%s/deathsounds.ini", szPath )
if ( !file_exists ( szPath ) )
return
new iCount
for ( new a = 0; a < file_size ( szPath, 1 ); a ++ )
{
new szText [ 64 ]
new iLen
read_file ( szPath, a, szText, sizeof ( szText ) - 1, iLen )
if ( ( szText [ 0 ] != ';' ) || (szText [ 0 ] != '/' ) && file_exists ( szText ) )
{
g_szPrecached [ iCount++ ] = szText
log_amx ( "^"%s^" sound precached.", szText )
precache_sound ( szText )
}
}
}
public blocksounds(id)
{
new arg[4] //this was moved from line 27-28 for the new untested section...
read_argv(1,arg,3)
if( equal(arg, "off") )
{
player_should_hear_sound[id] = false //now they cant hear sounds, since the boolean was set to false!
client_print(id,print_chat, "[AMXX] You will no longer hear the sound when you die. ")
}
else if( equal(arg, "on") )
{
player_should_hear_sound[id] = true //since the boolean is true players can hear sounds!
client_print(id,print_chat, "[AMXX] You now hear the sound when you die. ")
}
else
{
client_print(id, print_console, "Enables/Disables the death sound.") //thank you for the "missing operator option =)
client_print(id, print_console, "Valid arguments are ^"on^" or ^"off^"")
}
return PLUGIN_HANDLED
}
public ham_player_killed(id)
{
if(player_should_hear_sound[id])
{
client_cmd (id, "spk ^"%s^"",g_szPrecached[random(32)])
}
}
/* all of this is new and untested */
public client_connect(id)
{
player_should_hear_sound[id] = true
}
public show_info(id)
{
client_print(id, print_chat, "Death Sounds is enabled on this server.^n")
client_print(id, print_chat, "When you die, you will hear a sound, to disable this^n")
client_print(id, print_chat, "type amx_deathmsg off in console.^n")
}
__________________