Raised This Month: $ Target: $400
 0% 

Random Music


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-16-2021 , 08:49   Re: Random Music
Reply With Quote #1

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

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 11:37.


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