AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   allow user to set whether they hear a sound.. (https://forums.alliedmods.net/showthread.php?t=95850)

HLM 06-27-2009 22:43

allow user to set whether they hear a sound..
 
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 :oops:

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



fysiks 06-28-2009 00:08

Re: command to stop a plugin on command executer
 
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



HLM 06-28-2009 00:40

Re: command to stop a plugin on command executer
 
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..

fysiks 06-28-2009 01:30

Re: command to stop a plugin on command executer
 
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.

HLM 06-28-2009 01:39

Re: command to stop a plugin on command executer
 
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



fysiks 06-28-2009 12:10

Re: command to stop a plugin on command executer
 
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.

HLM 06-28-2009 17:26

Re: command to stop a plugin on command executer
 
okay, so in order for it to work I have to declare it when the action happens, thank you fysiks

fysiks 06-28-2009 17:51

Re: command to stop a plugin on command executer
 
Quote:

Originally Posted by HLM (Post 859559)
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.

HLM 06-28-2009 22:05

Re: command to stop a plugin on command executer
 
ohh, okay that makes sense, you can defenitely tell that im still learning :oops: :?

HLM 06-29-2009 19:25

Re: load random precached sound.. not working =(
 
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")




All times are GMT -4. The time now is 15:41.

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