Raised This Month: $ Target: $400
 0% 

Emit_sound but different sound on every client


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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 #2

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
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 00:19.


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