Raised This Month: $ Target: $400
 0% 

load random sound precache... not working =(


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-29-2009 , 20:26   load random sound precache... not working =(
Reply With Quote #1

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(PLUGINVERSIONAUTHOR)
    
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 szPathsizeof szPath ) - 
    
format szPathsizeof szPath ) - 1"%s/deathsounds.ini"szPath 
    
    if ( !
file_exists szPath ) ) 
        return 
    
    new 
iCount 
    
    
for ( new 0file_size szPath); ++ ) 
    { 
        new 
szText 64 
        new 
iLen 
        read_file 
szPathaszTextsizeof szText ) - 1iLen 
        if ( ( 
szText ] != ';' ) || (szText ] != '/' ) && 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(idprint_console"Enables/Disables the death sound.")        //thank you for the "missing operator option =)
        
client_print(idprint_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(idprint_chat"Death Sounds is enabled on this server.^n")
    
client_print(idprint_chat"When you die, you will hear a sound, to disable this^n")
    
client_print(idprint_chat"type amx_deathmsg off in console.^n")

__________________
+|- KARMA Respectively

HLM is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-29-2009 , 22:23   Re: load random sound precache... not working =(
Reply With Quote #2

just an update..

changed
PHP Code:
public ham_player_killed(id)
{
    if(
player_should_hear_sound[id])
    {
        
        
client_cmd (id"spk ^"%s^"",g_szPrecached[random(32)])
    }

to
PHP Code:
public ham_player_killed(id)
{
    if(
player_should_hear_sound[id])
    {
        new 
name[33]
        
get_user_name(id,name,32)
        
        
client_cmd (id"spk ^"%s^"",g_szPrecached[random(32)])
        
log_amx("played %s on target %s | %s",g_szPrecached[random(32)],name,id)
    }

now heres the output of the log when I kill myself..

Code:
L 06/29/2009 - 21:52:21: [deathsnd.amxx] played  on target -[EVIL]- Master | S4L | ä
no idea why its like this...

can someone help me out?

edit: why cant I change client_cmd(id to client_cmd(name ?
__________________
+|- KARMA Respectively


Last edited by HLM; 06-29-2009 at 22:55. Reason: updated again..
HLM is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-29-2009 , 23:39   Re: load random sound precache... not working =(
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
PHP Code:
g_szPrecached iCount++ ] = szText 

PHP Code:
copy(g_szPrecached[iCount++], 63szText
Hope it helps .

Oh, and it's nearly a sin around here to declare variables in a loop if you can avoid it . lol
Quote:
Originally Posted by HLM View Post
why cant I change client_cmd(id to client_cmd(name ?
http://www.amxmodx.org/funcwiki.php?go=func&id=230

Also

Code:
log_amx("played %s on target %s | %s",g_szPrecached[random(32)],name,id)
Code:
log_amx("played %s on target %s | %d",g_szPrecached[random(32)],name,id)
"id" is an integer, not a string.

Also, the sound in client_cmd() will not likely be the same as the sound in log_amx()
__________________

Last edited by fysiks; 06-29-2009 at 23:42.
fysiks is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-30-2009 , 00:05   Re: load random sound precache... not working =(
Reply With Quote #4

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(PLUGINVERSIONAUTHOR)
    
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 szPathsizeof szPath ) - 
    
format szPathsizeof szPath ) - 1"%s/deathsounds.ini"szPath 
    
    if ( !
file_exists szPath ) ) 
        return 
    
    new 
szText64 ], iLen
    
    
new iSize file_sizeszPath)
    for ( new 
0iSize && g_iTotalSounds 32++ ) 
    { 
        
read_file szPathaszTextsizeof szText ) - 1iLen 
        if ( ( 
szText ] != ';' ) || (szText ] != '/' ) && file_exists szText ) ) 
        { 
            
copyg_szPrecached g_iTotalSounds++ ], 63szText )
            
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(idprint_console"Enables/Disables the death sound.")        //thank you for the "missing operator option =)
        
client_print(idprint_console"Valid arguments are ^"on^" or ^"off^"")
    }
    
    return 
PLUGIN_HANDLED
}

public 
ham_player_killed(idkillershouldgib)
{
    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(idprint_chat"Death Sounds is enabled on this server.^n")
    
client_print(idprint_chat"When you die, you will hear a sound, to disable this^n")
    
client_print(idprint_chat"type amx_deathmsg off in console.^n")

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 15:38.


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