Raised This Month: $32 Target: $400
 8% 

Emit_sound but different sound on every client


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dexon
Member
Join Date: Aug 2019
Old 06-12-2022 , 06:13   Emit_sound but different sound on every client
Reply With Quote #1

Hi,
I want to play a sound from a given location, so I use emit_sound, but I also want this sound to be different for each player on server.
Is it possible?
Dexon is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 06-12-2022 , 10:13   Re: Emit_sound but different sound on every client
Reply With Quote #2

yes: https://www.amxmodx.org/api/amxmodx/emit_sound
lexzor is offline
Old 06-12-2022, 11:33
Dexon
This message has been deleted by Dexon. Reason: Misstype
Dexon
Member
Join Date: Aug 2019
Old 06-12-2022 , 11:36   Re: Emit_sound but different sound on every client
Reply With Quote #3

I already tried to check the syntax for any further information, but i didnt succed. Can you give me an example? Because i still dont see the solution.
To be clear: I want to emit sound Peter.wav from client 1. If client 2 set his personal setting to not Peter .wav, but Alise.wav then client 1 should hear the Peter.wav and client 2 the Alise.wav from the same emit.
Dexon is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 06-12-2022 , 12:41   Re: Emit_sound but different sound on every client
Reply With Quote #4

PHP Code:
#include <amxmodx>

#define NOT_SELECTED_SONG -1

new const   PLUGIN[] = "Song Menu",
            
AUTHOR[] = "Your Name",
            
VERSION[]= "1.0";

enum _:SongData
{
    
szSongName[64],
    
szPath[64]
}

new 
g_iUserSongID[MAX_PLAYERS 1];

new const 
g_szSongs[][SongData] =
{
    
//SONG NAME FOR MENU    //SONG PATH FOR PRECACHE AND EMIT
    
{"First Song",          "sounds/misc/song1.wav"}, // song id = 0
    
{"Second Song",         "sounds/misc/song2.wav"}, // song id = 1
    
{"3th Song",            "sounds/misc/song3.wav"}, // song id = 2
    
{"4h Song",             "sounds/misc/song4.wav"}, // song id = 3... so on
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);

    
register_clcmd("say /menu""cmdMenu");
    
register_clcmd("say_team /menu""cmdMenu");

    
register_clcmd("say /emit""emitSong");
    
register_clcmd("say_team /emit""emitSong");
}

public 
plugin_precache()
{
    for(new 
isizeof(g_szSongs); i++)
    {
        if(
file_exists(g_szSongs[i][szPath]))       
            
precache_generic(g_szSongs[i][szPath]); //WE USE PRECACHE_GENERIC TO AVOID REACHING OF 512 RESOURCE LIMIT
    
}
}

public 
client_authorized(id)
{
    if(
is_user_bot(id) || is_user_hltv(id))
        return 
PLUGIN_CONTINUE;

    
//LET SET PLAYER SONG ID VARIABLE TO -1 SO HE MUST SELECT A SONG
    
g_iUserSongID[id] = NOT_SELECTED_SONG;

    return 
PLUGIN_CONTINUE;
}

public 
cmdMenu(id)
{
    new 
iMenu menu_create("\r[SONGS]\w Playlist""main_menu_handler");

    for(new 
isizeof(g_szSongs); i++)
    {
        
menu_additem(iMenug_szSongs[i][szSongName], g_szSongs[i][szPath]); //LET'S PARSE SONG PATH TO EMIT IT AFTER SELECT IT IN MENU
    
}

    
menu_setprop(iMenuMPROP_EXITMEXIT_ALL);

    if(
is_user_connected(id))
        
menu_display(idiMenu0, -1);
}

public 
main_menu_handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }

    new 
szParsedSongPath[64], szSong[64];
    
menu_item_getinfo(menuitem_szParsedSongPathcharsmax(szParsedSongPath), szSongcharsmax(szSong), _); //LET'S GET PARSED SONG PATH AND ITEM NAME FROM MENU

    
g_iUserSongID[id] = item//MENU ITEM = SONG ID: THAT MEANS IF HE PRESS 1 AND SELECT FIRST SONG, THE SONG ID WILL BE 0

    
client_print(idprint_chat"[SONGS] Your song is %s"szSong);

    
emit_sound(idCHAN_AUTOszParsedSongPathVOL_NORMATTN_NORM0PITCH_NORM); //LET'S EMIT THE SELECTED SONG

    
cmdMenu(id);

    return 
PLUGIN_CONTINUE;
}

public 
emitSong(id)
{
    static 
iSongID;
    
iSongID g_iUserSongID[id//LET'S GET PLAYER SONG ID IN A STATIC VARIABLE ASSUMING THAT FUNCTION IS USED FREQUENTLY

    
if(iSongID == NOT_SELECTED_SONG//IF PLAYER HASN'T SELECTED A SONG HE CAN'T EMIT IT
    
{
        
client_print(idprint_chat"[SONGS] You must select a song");
        return 
PLUGIN_HANDLED;
    }

    
emit_sound(idCHAN_AUTOg_szSongs[iSongID][szPath], VOL_NORMATTN_NORM0PITCH_NORM); //LET'S EMIT THE PLAYER SONG USING THAT GLOBAL VARIABLE WHERE WE HAVE PLAYLIST
    
client_print(idprint_chat"[SONGS] You emit song %s"g_szSongs[iSongID][szSongName]);

    return 
PLUGIN_HANDLED;

i hope this will help you. i don't know if that plugin works or is what you need, but in emit_sound syntax at sample parameter you must put the song path that you want to emit. in the above code i was trying to show you how it should look.

and there already is a plugin that is doing a great job and get s updates when it needs: https://forums.alliedmods.net/showthread.php?p=2117299

Last edited by lexzor; 06-12-2022 at 12:57.
lexzor is offline
Dexon
Member
Join Date: Aug 2019
Old 06-12-2022 , 12:56   Re: Emit_sound but different sound on every client
Reply With Quote #5

In this sma, (if im not mistaken) if someone emits sound from menu, or via cmd it will play the sound the player chose.
Here:
PHP Code:
emit_sound(idCHAN_AUTOszParsedSongPathVOL_NORMATTN_NORM0PITCH_NORM); //LET'S EMIT THE SELECTED SONG 
And here:
PHP Code:
emit_sound(idCHAN_AUTOg_szSongs[iSongID][szPath], VOL_NORMATTN_NORM0PITCH_NORM); //LET'S EMIT THE PLAYER SONG USING THAT GLOBAL VARIABLE WHERE WE HAVE PLAYLIST 
They both emit the given sound what the given player chose. But I dont see any reference to my question. They emit a sound, but it doesnt show anywhere that the emitted sound would be different for each player on the server. I dont even see looping through all players or calling all players to check what they chose and use that sound. So the sound won't be different for each player, it will be the same sound as the player who typed the cmd chose, and not what each of them chose. Hope I wasnt confusing.
If im wrong, please enlight me.
Dexon is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 06-12-2022 , 13:02   Re: Emit_sound but different sound on every client
Reply With Quote #6

in variable
PHP Code:
g_iUserSongID[id
we store what song player is choosing after select it in the menu
so, if player select second song in menu, song id will be 1.

PHP Code:
static iSongID;
    
iSongID g_iUserSongID[id//LET'S GET PLAYER SONG ID IN A STATIC VARIABLE ASSUMING THAT FUNCTION IS USED FREQUENTLY 
here we create a new static var to not do something like this

PHP Code:
emit_sound(idCHAN_AUTOg_szSongs[g_iUserSongID[id]][szPath], VOL_NORMATTN_NORM0PITCH_NORM); //LET'S EMIT THE PLAYER SONG USING THAT GLOBAL VARIABLE WHERE WE HAVE PLAYLIST 
so this
PHP Code:
static iSongID;
    
iSongID g_iUserSongID[id//LET'S GET PLAYER SONG ID IN A STATIC VARIABLE ASSUMING THAT FUNCTION IS USED FREQUENTLY

emit_sound(idCHAN_AUTOg_szSongs[iSongID][szPath], VOL_NORMATTN_NORM0PITCH_NORM); //LET'S EMIT THE PLAYER SONG USING THAT GLOBAL VARIABLE WHERE WE HAVE PLAYLIST 
will emit g_szSongs[iSongID][szPath]. assuming that iSongID is 1 (that means the second song from menu),

g_szSongs[iSongID][szPatth] is sounds/misc/song2.wav
lexzor is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 06-12-2022 , 13:10   Re: Emit_sound but different sound on every client
Reply With Quote #7

so, let's say you want a command that will emit a sound for all connected players that selected a sound

you can do something like this

PHP Code:
public emit_for_all_players(id)
{
    new 
iPlayers[MAX_PLAYERS], iNum;
    
get_players(iPlayersiNum"ch");

    for(new 
iiPlayeriSongIDiNumi++)
    {
        
iPlayer iPlayers[i];

        if(
is_user_connected(iPlayer))
        {
            
iSongID g_iUserSongID[iPlayer];

            if(
iSongID != NOT_SELECTED_SONG)
            {
                
emit_sound(iPlayerCHAN_AUTOg_szSongs[iSongID][szPath], VOL_NORMATTN_NORM0PITCH_NORM); 
            }
        }
    }

    
client_print(0print_chat"[SONGS] Admin emit your selected sound");

    return 
PLUGIN_HANDLED;

in that loop we get song id from every player, check if user is connected and he has selected a song then we emit the song he selected

Last edited by lexzor; 06-12-2022 at 13:23.
lexzor is offline
Dexon
Member
Join Date: Aug 2019
Old 06-12-2022 , 13:16   Re: Emit_sound but different sound on every client
Reply With Quote #8

Thank you for taking time, but Im not quite sure that you understand my question.
What function you just wrote is emitting sound from all players, but I want to emit a sound from ONLY 1 player, and every client should hear that sound BUT that sound what each of them chosen already.
1 emit, different sounds for different players.
Lets say, there are 16 players on the server. One of them emits a sound, but the other 15 players hear a different sound what they chose from lets say a menu.
Dexon is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 06-12-2022 , 13:21   Re: Emit_sound but different sound on every client
Reply With Quote #9

that's exactly what the above code is doing. we store player selected song id in a variable then we use that variable to emit the song he selected.

my explanations are really bad maybe that s why you don't understand what i did
lexzor is offline
Dexon
Member
Join Date: Aug 2019
Old 06-12-2022 , 13:33   Re: Emit_sound but different sound on every client
Reply With Quote #10

Maybe I dont understand yea, but the code u sent is emitting sound from all players online and selected a sound, so if 16 players online + selected sound it will be played 16 times, 16 different places. its not exactly what I want, because I want to emit from 1 place, but 16 different sound for each player.
The exact thing i want to do:
I want to replace shooting sounds. I already did it, but I also want for example if someone shoots with ak, then each player should hear different sounds that they chose from a menu, when the player with ak shoots.
Dexon 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 03:29.


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