Raised This Month: $ Target: $400
 0% 

emmiting complex sounds( spk or emit_sound? )


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2010 , 19:23   emmiting complex sounds( spk or emit_sound? )
Reply With Quote #1

Hi everyone!

Here is the situation:

If you play half life: opposing force or sven co-op, you'll come across "shock trooper"s. They say something like this: "may ha hmm may he he". If you check the sound files, and the senteces.txt, you'll find this:
Code:
// SHOCK TROOPER
ST_GREN0 shocktrooper/kss kyur kiml
ST_ALERT0 shocktrooper/dit dit
ST_ALERT1 shocktrooper/dit kss kss
ST_ALERT2 shocktrooper/kss dit dit kss
ST_MONST0 shocktrooper/pur thirv pur kss kss
ST_COVER0 shocktrooper/ka ga blis blis ka
ST_THROW0 shocktrooper/kss wirt ras
ST_TAUNT0 shocktrooper/kiml kiml
ST_CHARGE0 shocktrooper/mub puh mub dit dit
ST_IDLE0 shocktrooper/ku kur ku
ST_QUEST0 shocktrooper/puh pur hyu ka
ST_ANSWER0 shocktrooper/dup dup
ST_CLEAR0 shocktrooper/dup blis dup
ST_CHECK0 shocktrooper/kss kss
You cannot use emit sound here, because most of the sound files don't last for even 1/10th of a second.
Here comes the HL console:
Code:
spk "shocktrooper/mub puh mub dit dit"
And voila, here is the sound we heard.

If we use the following code, we can emit the sound to all players:
PHP Code:
public sound_to_all(){
    
console_cmd(0,"spk ^"shocktrooper/mub puh mub dit dit^"");

The problem is, it sounds like it comes from everywhere. We could filter out the distance, so someone too far would not hear the sound at all, but all the others would still hear the sound from everywhere. We could add some parameters too for volume:
Code:
spk "shocktrooper/(v30) mub puh mub dit dit"
I bet there is a balance paramether( what is it's letter? ), but isn't there a simpler way to do this then a lot of filtering?
I've tried the following code to make a function, though it's not working:
PHP Code:
#include <amxmodx>

new maxplayers 0;

public 
plugin_init(){
    
register_plugin("SoundTest","1.0","Lulu the hero");
}

//someone connects to the server
public client_connect(id){
    
maxplayers++;
    if(!
is_user_bot(id)){
        
spk("vox/dadada hello",random(40)+80,50);
    }
}

//someone leaves the server
public client_disconnect(id){
    
maxplayers--;
    if(!
is_user_bot(id)){
        
spk("vox/dadada goodbye",random(40)+80,50);
    }
}

public 
spk(sentence[],pitch,volume){
    new 
parsed[100] = "";
    new 
data[4] = "";
    if(
pitch!=100){
        
num_to_str(pitch,data,3);
        if(
equal(parsed,"")){
            
format(parsed,99,"p%s",data);
        }else{
            
format(parsed,99,"%s p%s",parsed,data);
        }
    }
    if(
volume!=100){
        
num_to_str(volume,data,3);
        if(
equal(parsed,"")){
            
format(parsed,99,"v%s",data);
        }else{
            
format(parsed,99,"%s v%s",parsed,data);
        }
    }
    if(!
equal(parsed,"")){
        
format(parsed,99,"/(%s) ",parsed);
        
replace(sentence,30,"/",parsed);
    }
    for(new 
i=1;i<maxplayers;i++){
        if(!
is_user_bot(i)){
            
client_cmd(i,"spk ^"%s^"",sentence);
        }
    }

Thanks everyone for your answers in advance.
Lulu the hero is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-19-2010 , 20:25   Re: emmiting complex sounds( spk or emit_sound? )
Reply With Quote #2

First of all, you should explain what is not working about it (which requires some debugging).

Second, your method of counting players and using that for the for loop is not good. This is how I would do it and see if it works:

-Code Removed-
__________________

Last edited by fysiks; 07-19-2010 at 23:54.
fysiks is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2010 , 20:51   Re: emmiting complex sounds( spk or emit_sound? )
Reply With Quote #3

PHP Code:
public spk(sentence[],pitch,volume)
{
    new 
parsed[100] = "";
    new 
szTemp[7]
    if(
pitch != 100)
    {
        
formatex(szTempcharsmax(szTemp), "p%i"pitch)
        
add(parsedcharsmax(parsed), szTemp)
    }
    if(
volume != 100)
    {
        
formatex(szTempcharsmax(szTemp), "%sv%i"volumeparsed[0] ? " " "")
        
add(parsedcharsmax(parsed), szTemp)
    }
    if(!
equal(parsed,""))
    {
        
format(parsed,99,"/(%s) ",parsed);
        
replace(sentence,30,"/",parsed);
    }
    
    new 
iPlayers[32], iNumPlayers;
    
get_players(iPlayersiNumPlayers);
    for(new 
i=0iNumPlayersi++)
    {
        
client_cmd(iPlayers[i],"spk ^"%s^"",sentence);
    }

Only one error.
The code is only for a test. It would say hello to every connecting player. But it doesn't.

If I can add a balance paramether, then I can calculate a sound source's direction and volume according to the distance.
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2010 , 21:19   Re: emmiting complex sounds( spk or emit_sound? )
Reply With Quote #4

Another example of vox used for creatures is Sven Coop's robot grunt sounds. When the robogrunt sees a grenade it says:

spk "vox/(p120) dadeda emergency evacuate"

it would look like this called from the function:

spk("vox/dadeda emergency evacuate",120,100);

Oh, by the way it's dadeda and not dadada as I thought...

I corrected the plugin and inserted fysiks' code:
PHP Code:
#include <amxmodx>

new maxplayers 0;

public 
plugin_init(){
    
register_plugin("SoundTest","1.0","Lulu the hero");
    
register_concmd("hello","test_spk");
}

public 
test_spk(){
    
spk("vox/dadeda emergency evacuate",120,100);
}

//someone connects to the server
public client_connect(id){
    
maxplayers++;
    if(!
is_user_bot(id)){
        
spk("vox/dadeda hello",random(40)+80,50);
    }
}

//someone leaves the server
public client_disconnect(id){
    
maxplayers--;
    if(!
is_user_bot(id)){
        
spk("vox/dadeda goodbye",random(40)+80,50);
    }
}

public 
spk(sentence[],pitch,volume)
{
    new 
parsed[100] = "";
    new 
szTemp[7]
    if(
pitch != 100)
    {
        
formatex(szTempcharsmax(szTemp), "p%i"pitch)
        
add(parsedcharsmax(parsed), szTemp)
    }
    if(
volume != 100)
    {
        
formatex(szTempcharsmax(szTemp), "%sv%i"volumeparsed[0] ? " " "")
        
add(parsedcharsmax(parsed), szTemp)
    }
    if(!
equal(parsed,""))
    {
        
format(parsed,99,"/(%s) ",parsed);
        
replace(sentence,30,"/",parsed);
    }
    
    new 
iPlayers[32], iNumPlayers;
    
get_players(iPlayersiNumPlayers);
    for(new 
i=0iNumPlayersi++)
    {
        
client_cmd(iPlayers[i],"spk ^"%s^"",sentence);
    }


By the way, what are the parameters of spk/speak?
The ones I've found are the following(tested all the letters)
Code:
  p - pitch(%) - default value is 100 - raises/lowers pitch
  t - tempo(?) - default value is 0 - increasing the tempo(without the pitch increase)
  e - end(%) - default value is 100 - trim the end of a sample(cut down 100-% from the end)
  s - start(%) - default value is 0 - trim the beginning of a sample(cut down a % from the start)
  v - volume(%) - default value is 100 - the volume of the sample

Last edited by Lulu the hero; 07-19-2010 at 21:34.
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2010 , 21:49   Re: emmiting complex sounds( spk or emit_sound? )
Reply With Quote #5

And what about fakemeta's
PHP Code:
EngFunc_BuildSoundMsg,                // void )            (edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch, int msg_dest, int msg_type, const float *pOrigin, edict_t *ed); 
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2010 , 22:19   Re: emmiting complex sounds( spk or emit_sound? )
Reply With Quote #6

Ok, the code is corrected, but a new error appeared, which I don't know where it came from:

Code:
L 07/20/2010 - 04:15:34: replace() buffer not big enough (36>=30)
L 07/20/2010 - 04:15:34: [AMXX] Displaying debug trace (plugin "soundtest.amxx")
L 07/20/2010 - 04:15:34: [AMXX] Run time error 10: native error (native "replace")
L 07/20/2010 - 04:15:34: [AMXX]    [0] soundtest.sma::spk (line 43)
L 07/20/2010 - 04:15:34: [AMXX]    [1] soundtest.sma::test_spk (line 9)
if I increase the number in the plugin, then it works once, then the same error with 43 as number in the 1st line. I've reset the number in the plugin to 30, then it shows 40 in the error( no working calls this time )

The code is:
PHP Code:
#include <amxmodx>

public plugin_init(){
    
register_plugin("SoundTest","1.0","Lulu the hero");
    
register_concmd("hello","test_spk");
}

public 
test_spk(){
    
spk("vox/dadeda emergency evacuate",120,70);
}

//someone connects to the server
public client_connect(id){
    if(!
is_user_bot(id)){
        
spk("vox/dadeda hello",random(40)+80,50);
    }
}

//someone leaves the server
public client_disconnect(id){
    if(!
is_user_bot(id)){
        
spk("vox/dadeda goodbye",random(40)+80,50);
    }
}

public 
spk(sentence[],pitch,volume)
{
    new 
parsed[100] = "";
    new 
szTemp[7]
    if(
pitch != 100)
    {
        
formatex(szTempcharsmax(szTemp), "p%i"pitch)
        
add(parsedcharsmax(parsed), szTemp)
    }
    if(
volume != 100)
    {
        
formatex(szTempcharsmax(szTemp), "%sv%i",(parsed[0] ? " " ""), volume)
        
add(parsedcharsmax(parsed), szTemp)
    }
    if(!
equal(parsed,""))
    {
        
format(parsed,99,"/(%s) ",parsed);
        
replace(sentence,30,"/",parsed);
    }
    
    new 
iPlayers[32], iNumPlayers;
    
get_players(iPlayersiNumPlayers);
    for(new 
i=0iNumPlayersi++)
    {
        
client_cmd(iPlayers[i],"spk ^"%s^"",sentence);
    }

Lulu the hero is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-19-2010 , 22:30   Re: emmiting complex sounds( spk or emit_sound? )
Reply With Quote #7

For that error use replace_all() instead of replace().
__________________
fysiks is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2010 , 23:00   Re: emmiting complex sounds( spk or emit_sound? )
Reply With Quote #8

Replaced it, but still not working...

Code:
L 07/20/2010 - 05:00:36: replace() buffer not big enough (37>=27)
L 07/20/2010 - 05:00:36: [AMXX] Displaying debug trace (plugin "soundtest.amxx")
L 07/20/2010 - 05:00:36: [AMXX] Run time error 10: native error (native "replace")
L 07/20/2010 - 05:00:36: [AMXX]    [0] string.inc::replace_all (line 239)
L 07/20/2010 - 05:00:36: [AMXX]    [1] soundtest.sma::spk (line 43)
L 07/20/2010 - 05:00:36: [AMXX]    [2] soundtest.sma::test_spk (line 9)
PHP Code:
#include <amxmodx>

public plugin_init(){
    
register_plugin("SoundTest","1.0","Lulu the hero");
    
register_concmd("hello","test_spk");
}

public 
test_spk(){
    
spk("vox/dadeda emergency evacuate",120,70);
}

//someone connects to the server
public client_connect(id){
    if(!
is_user_bot(id))
        
spk("vox/dadeda hello",random(40)+80,50);
}

//someone leaves the server
public client_disconnect(id){
    if(!
is_user_bot(id))
        
spk("vox/dadeda goodbye",random(40)+80,50);
}

public 
spk(sentence[],pitch,volume){
    new 
parsed[100] = "";
    new 
szTemp[7]
    if(
pitch != 100){
        
formatex(szTempcharsmax(szTemp), "p%i"pitch);
        
add(parsedcharsmax(parsed), szTemp);
    }
    if(
volume != 100){
        
formatex(szTempcharsmax(szTemp), "%sv%i",(parsed[0] ? " " ""), volume);
        
add(parsedcharsmax(parsed), szTemp);
    }
    if(!
equal(parsed,"")){
        
format(parsed,99,"/(%s) ",parsed);
        
replace_all(sentence,30,"/",parsed);
    }
    new 
iPlayers[32], iNumPlayers;
    
get_players(iPlayersiNumPlayers);
    for(new 
i=0iNumPlayersi++)
        
client_cmd(iPlayers[i],"spk ^"%s^"",sentence);


Last edited by Lulu the hero; 07-19-2010 at 23:04.
Lulu the hero is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-19-2010 , 23:22   Re: emmiting complex sounds( spk or emit_sound? )
Reply With Quote #9

Ok, I figured out the problem. You can't reuse the variable "sentence" because you are trying to make it longer but is only as long as the original string that was submitted to it.

Try this:

PHP Code:
spk(sentence[],pitch,volume)
{
    new 
szSoundSettings[32];
    new 
szCmd[64];
    new 
iPos;
    if(
pitch != 100)
    {
        
iPos formatex(szSoundSettingscharsmax(szSoundSettings), "p%i"pitch)
    }
    
    if(
volume != 100)
    {
        
formatex(szSoundSettings[iPos], charsmax(szSoundSettings) - iPos"%sv%i"szSoundSettings[0] ? " " ""volume)
    }
    
    if(
szSoundSettings[0])
    {
        new 
iSlashPos
        
if( (iSlashPos contain(sentence"/")) != -)
        {
            
iPos add(szCmdcharsmax(szCmd), sentenceiSlashPos+1)
            
formatex(szCmd[iPos], charsmax(szCmd) - iPos"(%s) %s"szSoundSettingssentence[iSlashPos+1])
        }
    }
    else
    {
        
copy(szCmdcharsmax(szCmd), sentence)
    }
    
    new 
iPlayers[32], iNumPlayers;
    
get_players(iPlayersiNumPlayers);
    for(new 
i=0iNumPlayersi++)
    {
        
client_cmd(iPlayers[i],"spk ^"%s^"",szCmd);
    }

__________________

Last edited by fysiks; 07-19-2010 at 23:35.
fysiks is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2010 , 23:57   Re: emmiting complex sounds( spk or emit_sound? )
Reply With Quote #10

Super, I am most greatful to you. Only one thing remains. How to sort out the balancing problems? Idea: make new files, like: emergency_l.wav and emergency_r.wav, but as I see spk only supports 1 channel at a time...( need to test this )

So how can a creature have a complex sound like this?
Lulu the hero 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:11.


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