| Exolent[jNr] |
06-30-2009 00:05 |
Re: load random sound precache... not working =(
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 ]
new g_iTotalSounds;
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 szText[ 64 ], iLen
new iSize = file_size( szPath, 1 )
for ( new a = 0; a < iSize && g_iTotalSounds < 32; a ++ )
{
read_file ( szPath, a, szText, sizeof ( szText ) - 1, iLen )
if ( ( szText [ 0 ] != ';' ) || (szText [ 0 ] != '/' ) && file_exists ( szText ) )
{
copy( g_szPrecached [ g_iTotalSounds++ ], 63, 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, killer, shouldgib)
{
if(player_should_hear_sound[id] && g_iTotalSounds > 0)
{
new name[33]
get_user_name(id,name,32)
new iSound = random(g_iTotalSounds);
client_cmd (id, "spk ^"%s^"",g_szPrecached[iSound])
log_amx("played %s on target %s | %i",g_szPrecached[iSound],name,id)
}
}
/* 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")
}
|