AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Play Sound (https://forums.alliedmods.net/showthread.php?t=51428)

FormulaZero 02-17-2007 19:20

Play Sound
 
Hello, I need urgent help!
I want to create a code that when a user says like omg it plays the sound omg.

Yes I know I must have the sounds in my folder, can someone create a FULL EXAMPLE?

Drak 02-17-2007 20:12

Re: Play Sound
 
Code:
#include <amxmodx> #define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("say","say_handle") } public say_handle(id) {     static command[33]     read_argv(1,command,32)         if(equali(command,"omg")) {         // Do the sound here         // Emit Sound way:         emit_sound(id,CHAN_AUTO,"my_sound.wav",1.0,ATTN_NORM,0,PITCH_NORM) //- Emits the sound from the player         // Play to all clients:         client_cmd(0,"spk dir_to_sound/mysound.wav")         return PLUGIN_HANDLED     }     return PLUGIN_CONTINUE }
Simple enough, if you can understand that above code. It should work fine, just make sure you precache your sound(s) and ether emit or play the sound to the clients.

FormulaZero 02-17-2007 20:16

Re: Play Sound
 
So just copy that code with every sound emited?

Drak 02-17-2007 20:17

Re: Play Sound
 
Uhh, what? That code of course wont work, you just need to add your sounds and due ether the emitting way or sending the 'spk' command to all the players.

FormulaZero 02-17-2007 20:43

Re: Play Sound
 
So Would this work:

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "TFC Sounds"
#define VERSION "1.0"
#define AUTHOR "Formula Zero"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_concmd("say","say_handle")
}
public 
say_handle(id)
{
    static 
command[33]
    
read_argv(1,command,32)
    
    if(
equali(command,"omg")) {
        
misc/omg2
        
        emit_sound
(id,CHAN_AUTO,"my_sound.wav",1.0,ATTN_NORM,0,PITCH_NORM//- Emits the sound from the player
        
        
client_cmd(0,"spk dir_to_sound/mysound.wav")
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE



Drak 02-17-2007 20:57

Re: Play Sound
 
Uhh, nope. You might wanna read up some more on functions and stuff. Plus you didn't change anything..But add "misc/omg2"
Code:
#include <amxmodx> #define PLUGIN "TFC Sounds" #define VERSION "1.0" #define AUTHOR "Formula Zero" new yoursound public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("say","say_handle") } public plugin_precache() {      yoursound = precache_sound("DIR_TO_SOUND/sound.wav") } public say_handle(id) {     static command[33]     read_argv(1,command,32)         if(equali(command,"omg")) {               client_cmd(0,"spk dir_to_sound/mysound.wav")         return PLUGIN_HANDLED     }     return PLUGIN_CONTINUE }
Replace the "DIR_TO_SOUND" on both the "client_cmd" and "precache_sound"
Then it should work, I also think that if the user already has the sound there isn't no need to precache it, only to make it downloadable to the clients.

Hawk552 02-18-2007 09:16

Re: Play Sound
 
This is poorly optimized, here's a slightly better way:

Code:
#include <amxmodx> #define PLUGIN "TFC Sounds" #define VERSION "1.0" #define AUTHOR "Formula Zero" new g_Sound[] = "dir/sound.wav" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("say","say_handle") } public plugin_precache()     file_exists(g_Sound) ? precache_sound(g_Sound) : set_fail_state("Could not find sound file") public say_handle(id) {     static command[33]     read_argv(1,command,32)         if(equali(command,"omg",3))     {               client_cmd(0,"spk ^"%s^"",g_Sound)         return PLUGIN_HANDLED     }         return PLUGIN_CONTINUE }

Also, if you're planning on posting this, don't. It'll get unapproved (given one of the rules being not to post something that plays a sound when someone says something).

FormulaZero 02-18-2007 10:58

Re: Play Sound
 
Oh no, I wasn't plan on doing that I was going to use this on a private server. Thank you both of you.

Voi 02-19-2007 10:38

Re: Play Sound
 
as i know this:
emit_sound(id,CHAN_VOICE,"my_sound.wav",1.0,ATTN_NORM,0,PITCH_NORM)

will make the sound played to all clients too, and its usefull to play a sound to all clients at once then spk client command


All times are GMT -4. The time now is 07:56.

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