Raised This Month: $ Target: $400
 0% 

allow user to set whether they hear a sound..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-27-2009 , 22:43   allow user to set whether they hear a sound..
Reply With Quote #1

im making my very first plugin, its quite a simple plugin.. it will play a sound when a user dies... but if you die ALOT it can get VERY annoying, so im trying to make a command that will stop the plugin from working for that client.. I dont know how to do this though

heres my source, can someone help me?

PHP Code:
/* Script generated by Pawn Studio */

#include <amxmodx>
#include <amxmisc>
#include <HamSandwich>

#define PLUGIN    "Death Noise"
#define AUTHOR    "HLM A.K.A Master"
#define VERSION    "1.0"



public plugin_init()
{
register_plugin(PLUGINVERSIONAUTHOR)
RegisterHam(Ham_Killed"player" "ham_player_killed"1)
register_clcmd("amx_deathmsg","blocksounds",_,"Enables/Disables the death sound")
}

public 
plugin_precache()
{
precache_sound("misc/Terminated.wav")
}

public 
blocksounds(id)
{
    new 
arg[5]
    
read_argv(1,arg,4)
    
    new 
name[33]
    
get_user_name(id,name,32)
    
    if( 
equal(arg"off"))
    {
        
client_print(id,print_chat"[AMXX] %s, you will no longer hear the sound on death. "name)
        return 
PLUGIN_HANDLED
    
}
    else if( 
equal(arg"on"))
    {
        
client_print(id,print_chat"[AMXX] %s, you will hear the sound on death. ",name)
        return 
PLUGIN_CONTINUE
    
}
}

public 
ham_player_killed(id)
{

new 
name[33]
get_user_name(id,name,32)

client_cmd(id"speak misc/Terminated.wav")
return 
HAM_HANDLED

__________________
+|- KARMA Respectively


Last edited by HLM; 06-29-2009 at 20:14.
HLM is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2009 , 00:08   Re: command to stop a plugin on command executer
Reply With Quote #2

You really need to try and compile your plugins before posting here. Then, you will get a list of errors. Fix the errors. Then if it doesn't work then, then you can post here.


PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <HamSandwich>

#define PLUGIN    "Death Noise"
#define AUTHOR    "HLM A.K.A Master"
#define VERSION    "1.0"

new bool:player_should_hear_sound[33]

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 
plugin_precache()
{
    
precache_sound("misc/Terminated.wav")
}

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
        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
        client_print
(id,print_chat"[AMXX] You now hear the sound when you die. ")
    }
    else
    {
        
client_print(idprint_console"Enables/Disables the death sound.")
        
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"speak misc/Terminated.wav")
    }
}

/* all of this is new and untested */
public client_connect(id)
{
    
player_should_hear_sound[id] = true

__________________

Last edited by fysiks; 06-28-2009 at 00:17.
fysiks is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-28-2009 , 00:40   Re: command to stop a plugin on command executer
Reply With Quote #3

ok, I edited the post above to the proper working one, but it still doesnt work.. whether I set amx_deathmsg on or off, I still here it, but otherwise it works fine..
__________________
+|- KARMA Respectively

HLM is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2009 , 01:30   Re: command to stop a plugin on command executer
Reply With Quote #4

Ok, now that it compiles, take a look at my code and try to understand it. Then, when you understand what things do, add parts of it into your plugin. Infact there is only one major thing you need to add to make it work like you want.
__________________
fysiks is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-28-2009 , 01:39   Re: command to stop a plugin on command executer
Reply With Quote #5

you set everything under a boolean, making it possible for on/off operation..

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <HamSandwich>

#define PLUGIN    "Death Noise"
#define AUTHOR    "HLM A.K.A Master"
#define VERSION    "1.0"

new bool:player_should_hear_sound[33]  //booleans can only be true or false (on or off)

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 
plugin_precache()
{
    
precache_sound("misc/Terminated.wav")
}

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"speak misc/Terminated.wav")
    }
}

/* all of this is new and untested */
public client_connect(id)
{
    
player_should_hear_sound[id] = true

__________________
+|- KARMA Respectively

HLM is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2009 , 12:10   Re: command to stop a plugin on command executer
Reply With Quote #6

My main point was that you had nothing in "ham_player_killed" to prevent the sound from playing. So, you needed to add a variable (doesn't have to be boolean but I used it because it only has two states) to determine if the player is supposed to hear the sound or not.
__________________
fysiks is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-28-2009 , 17:26   Re: command to stop a plugin on command executer
Reply With Quote #7

okay, so in order for it to work I have to declare it when the action happens, thank you fysiks
__________________
+|- KARMA Respectively

HLM is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-28-2009 , 17:51   Re: command to stop a plugin on command executer
Reply With Quote #8

Quote:
Originally Posted by HLM View Post
okay, so in order for it to work I have to declare it when the action happens, thank you fysiks
No, you are not declaring anything. You need to check if the player is supposed to be getting the sound. Which is what the player_should_hear_sound var is.
__________________
fysiks is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-28-2009 , 22:05   Re: command to stop a plugin on command executer
Reply With Quote #9

ohh, okay that makes sense, you can defenitely tell that im still learning
__________________
+|- KARMA Respectively

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

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
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:41.


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