Raised This Month: $ Target: $400
 0% 

Play Sound


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FormulaZero
BANNED
Join Date: Feb 2007
Location: Sector 7G
Old 02-17-2007 , 19:20   Play Sound
Reply With Quote #1

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?
FormulaZero is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 02-17-2007 , 20:12   Re: Play Sound
Reply With Quote #2

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.
Drak is offline
Send a message via MSN to Drak
FormulaZero
BANNED
Join Date: Feb 2007
Location: Sector 7G
Old 02-17-2007 , 20:16   Re: Play Sound
Reply With Quote #3

So just copy that code with every sound emited?
FormulaZero is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 02-17-2007 , 20:17   Re: Play Sound
Reply With Quote #4

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.
Drak is offline
Send a message via MSN to Drak
Old 02-17-2007, 20:19
FormulaZero
This message has been deleted by FormulaZero.
FormulaZero
BANNED
Join Date: Feb 2007
Location: Sector 7G
Old 02-17-2007 , 20:43   Re: Play Sound
Reply With Quote #6

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

FormulaZero is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 02-17-2007 , 20:57   Re: Play Sound
Reply With Quote #7

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.
Drak is offline
Send a message via MSN to Drak
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 02-18-2007 , 09:16   Re: Play Sound
Reply With Quote #8

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).
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
FormulaZero
BANNED
Join Date: Feb 2007
Location: Sector 7G
Old 02-18-2007 , 10:58   Re: Play Sound
Reply With Quote #9

Oh no, I wasn't plan on doing that I was going to use this on a private server. Thank you both of you.
FormulaZero is offline
Voi
Veteran Member
Join Date: Sep 2006
Location: Gdansk, Poland
Old 02-19-2007 , 10:38   Re: Play Sound
Reply With Quote #10

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
__________________

Last edited by Voi; 02-19-2007 at 10:41.
Voi 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 07:56.


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