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

Random Music


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
1M1e
Member
Join Date: Mar 2020
Old 09-15-2021 , 08:26   Random Music
Reply With Quote #1

Hello,

I tried to make this code works on every new round but its not working can you tell me what I did wrong?

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "1M1e"

new g_iCvars;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("HLTV""OnNewRound""a""1=0""2=0")
    
    
g_iCvars register_cvar("random_music""1")
    
    
register_clcmd("say /stop""StopMusic")
    
register_clcmd("say_team /stop""StopMusic")
    
register_clcmd("say /play""PlayMusic")
    
register_clcmd("say_team /play""PlayMusic")
    
}

public 
StopMusic(id)
{
        
client_cmd(id"mp3 stop")
    
g_iCvars 0
}

public 
PlayMusic(id)
{
    
g_iCvars 1
}

public 
client_connect()
{
    
g_iCvars 1
}

public 
OnNewRound(id)
{
    
    
client_cmd(0"mp3 stop")
    
    if(
get_pcvar_num(g_iCvars))
    {
        new 
random random_num(1,10);
        
        switch( 
random )
        {
            case 
1:
            {
                
client_cmd(id"mp3 play ^"sound/music/music1^"")
            }
            case 
2:
            {
                
client_cmd(id"mp3 play ^"sound/music/music2^"")
            }
            case 
3:
            {
                
client_cmd(id"mp3 play ^"sound/music/music3^"")
            }
            case 
4:
            {
                
client_cmd(id"mp3 play ^"sound/music/music4^"")
            }
            case 
5:
            {
                
client_cmd(id"mp3 play ^"sound/music/music5^"")
            }
            case 
6:
            {
                
client_cmd(id"mp3 play ^"sound/music/music6^"")
            }
            case 
7:
            {
                
client_cmd(id"mp3 play ^"sound/music/music7^"")
            }
            case 
8:
            {
                
client_cmd(id"mp3 play ^"sound/music/music8^"")
            }
            case 
9:
            {
                
client_cmd(id"mp3 play ^"sound/music/music9^"")
            }
            case 
10:
            {
                
client_cmd(id"mp3 play ^"sound/music/music10^"")
            }
        }
    }
    return 
PLUGIN_HANDLED


Last edited by 1M1e; 09-15-2021 at 08:28.
1M1e is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-15-2021 , 09:34   Re: Random Music
Reply With Quote #2

g_iCvars = 1 this is not how you set cvar values. By doing this you just wrote "1" to a variable and in the process of doing so lost the actual cvar pointer. To set a cvar you have to use set_pcvar_num/float/string.
__________________
HamletEagle is offline
1M1e
Member
Join Date: Mar 2020
Old 09-16-2021 , 08:43   Re: Random Music
Reply With Quote #3

Like this?

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new g_iCvars

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("HLTV""OnNewRound""a""1=0""2=0")
    
    
g_iCvars register_cvar("random_music""1")
    
    
register_clcmd("say /stop""StopMusic")
    
register_clcmd("say_team /stop""StopMusic")
    
register_clcmd("say /play""PlayMusic")
    
register_clcmd("say_team /play""PlayMusic")
    
}

public 
StopMusic(id)
{
    
client_cmd(id"mp3 stop")
    
set_pcvar_num(g_iCvars0)
}

public 
PlayMusic(id)
{
    
set_pcvar_num(g_iCvars1)
}

public 
client_connect()
{
    
set_pcvar_num(g_iCvars1)
}

public 
OnNewRound(id)
{
    
    
client_cmd(0"mp3 stop")
    
    if(
get_pcvar_num(g_iCvars))
    {
        new 
random random_num(1,10);
        
        switch( 
random )
        {
            case 
1:
            {
                
client_cmd(id"mp3 play ^"sound/Teddy_CSO/Halloween_Teddy^"")
            }
            case 
2:
            {
                
client_cmd(id"mp3 play ^"sound/music/music2^"")
            }
            case 
3:
            {
                
client_cmd(id"mp3 play ^"sound/music/music3^"")
            }
            case 
4:
            {
                
client_cmd(id"mp3 play ^"sound/music/music4^"")
            }
            case 
5:
            {
                
client_cmd(id"mp3 play ^"sound/music/music5^"")
            }
            case 
6:
            {
                
client_cmd(id"mp3 play ^"sound/music/music6^"")
            }
            case 
7:
            {
                
client_cmd(id"mp3 play ^"sound/music/music7^"")
            }
            case 
8:
            {
                
client_cmd(id"mp3 play ^"sound/music/music8^"")
            }
            case 
9:
            {
                
client_cmd(id"mp3 play ^"sound/music/music9^"")
            }
            case 
10:
            {
                
client_cmd(id"mp3 play ^"sound/music/music10^"")
            }
            
        }
    }
    return 
PLUGIN_HANDLED

if its like this then its not working

Last edited by 1M1e; 09-16-2021 at 08:49.
1M1e is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-16-2021 , 08:49   Re: Random Music
Reply With Quote #4

Sure it doesn't work. HLTV event is a global event, it doesn't pass any "id" parameter. You have to iterate over all players using get_players and a for loop.
__________________
HamletEagle is offline
Crackhead69
Member
Join Date: Feb 2021
Old 09-16-2021 , 11:17   Re: Random Music
Reply With Quote #5

Since you're changing the cvar value on 1 on every connect i think that you may wanted it to be individual, so i added a global bool which you can change if it wasn't your goal.

PHP Code:
#include <amxmodx>

new bool:g_PlayMusic[33]

new const 
szMusicList[][] =
{
    
"sound/music/music1",
    
"sound/music/music2",
    
"sound/music/music3",
    
"sound/music/music4"
}

public 
plugin_init()
{
    
register_event("HLTV""OnNewRound""a""1=0""2=0")

    
register_clcmd("say /stop""StopMusic")
    
register_clcmd("say_team /stop""StopMusic")
    
    
register_clcmd("say /play""PlayMusic")
    
register_clcmd("say_team /play""PlayMusic")
}

public 
StopMusic(id)
{
    
client_cmd(id"mp3 stop")
    
g_PlayMusic[id] = false
}

public 
PlayMusic(id)
    
g_PlayMusic[id] = true

public client_authorized(id)
    
g_PlayMusic[id] = true

public OnNewRound()
{
    new 
players[32],num
    get_players
(players,num,"ch")
    
    for(new 
ii<numi++)
    {
        
client_cmd(players[i], "mp3 stop")
        
        if(
g_PlayMusic[players[i]] == true)
            
client_cmd(players[i], "mp3 play ^"%s^""szMusicList[random(sizeof(szMusicList))])
    }

I am not sure if it will work since im not confident if i did that line correctly -

PHP Code:
client_cmd(players[i], "mp3 play ^"%s^""szMusicList[random(sizeof(szMusicList))]) 

Last edited by Crackhead69; 09-16-2021 at 11:19.
Crackhead69 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:37.


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