AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   mp3 play not working for rehlds (https://forums.alliedmods.net/showthread.php?t=298789)

TBagT 06-22-2017 16:16

mp3 play not working for rehlds
 
So one of plugin users said that the music in his server which uses rehlds doesn't play is it the rehlds fault or the mp3 format ?
PHP Code:

client_cmdid"mp3 play sound/%s"playSongsong_path ] ); 


PRoSToTeM@ 06-22-2017 16:24

Re: mp3 play not working for rehlds
 
Is it exist on the client? Is it correclty precached?

TBagT 06-22-2017 16:31

Re: mp3 play not working for rehlds
 
Yeah, the problem was I was using precache_sound instead of precache_generic for mp3 :D

TBagT 06-23-2017 06:13

Re: mp3 play not working for rehlds
 
Sorry for bumping but I don't get it is it rehlds fault or mp3 format because it works fine for me
I'll provide full plugin, maybe I am missing something.
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN  "Music"
#define VERSION "1.0.1"
#define AUTHOR  "TBagT"

#pragma semicolon 1

#define SONG_NAME_MAX 64
#define SONG_PATH_MAX 128
#define SONG_TASK     5955
#define TASK_SHOW_AD  6000
#define is_a_player(%1) (1<=%1<=32)
const OFFSET_CSMENUCODE 205;

enum _:SongData song_nameSONG_NAME_MAX ], song_pathSONG_PATH_MAX ], song_lengthboolis_wav };
enum _:PlayerData current_song_idboolplay_songs };
enum _:PluginCvars PLAY_FOR_JUST_CONNECTEDSHOW_ADSHOW_AD_TIMER }

new Array: 
Songsboolplugin_active trueboolround_started false,
    
g_total_songs 0g_say_textg_player33 ][ PlayerData ],
    
g_cvarsPluginCvars ], cfg_dirSONG_PATH_MAX ];

new const 
clcmd_commands[ ][ ] = {
        
"say /music",      "clcmd_music",
        
"say_team /music""clcmd_music",
        
"say /stop",       "client_stop_music",
        
"say_team /stop",  "client_stop_music"
};

public 
plugin_precache( ) {
        
register_dictionary"music_plugin.txt" );

        
Songs ArrayCreateSongData );

        static 
configDirSONG_PATH_MAX ];
        
get_configsdirconfigDircharsmaxconfigDir ) );
        
formatexcfg_dircharsmaxcfg_dir ), "%s/music_plugin.cfg"configDir );

        if( !
file_existscfg_dir ) )
                
plugin_active false;
        else
                
insert_songs( );

        if( 
g_total_songs ) {
                new 
indexSongItemSongData ];
                for( 
index 0index g_total_songsindex++ ) {
                        
ArrayGetArraySongsindexSongItem );
                        
precache_genericSongItemsong_path ] );
                }
        } else
                
plugin_active false;
}

public 
plugin_init( ) {
        
register_pluginPLUGINVERSIONAUTHOR );
        
register_cvar"music_plugin"VERSIONFCVAR_SPONLY FCVAR_SERVER );
        
set_cvar_string"music_plugin"VERSION );

        if( 
plugin_active ) {
                
g_cvarsPLAY_FOR_JUST_CONNECTED ] = register_cvar"music_play_just_connected""1"    );
                
g_cvarsSHOW_AD ]                 = register_cvar"music_show_ad",             "1"    );
                
g_cvarsSHOW_AD_TIMER ]           = register_cvar"music_ad_timer",            "30.0" );

                
register_logevent"lev_round_start"2"1=Round_Start" );
                
register_logevent"lev_round_end",   2"1=Round_End" );
                
RegisterHamHam_Spawn"player""fw_player_spawn");

                for( new 
index 0index sizeofclcmd_commands ); index += )
                        
register_clcmdclcmd_commandsindex ], clcmd_commandsindex ] );

                
g_say_text get_user_msgid"SayText" );
        } else
                
log_amx"%L"LANG_SERVER"MUSIC_PLUGIN_ERR" );
}

public 
plugin_end( ) {
        
ArrayDestroySongs );
}

public 
client_putinserverid ) {
        if( !
plugin_active )
                return;

        
g_playerid ][ current_song_id ] = -1;
        
g_playerid ][ play_songs ] = boolget_pcvar_numg_cvarsPLAY_FOR_JUST_CONNECTED ] );
}

public 
client_disconnectid ) {
        if( !
plugin_active )
                return;

        
client_stop_musicidfalse );
}

public 
fw_player_spawnid ) {
        if( !
plugin_active )
                return;

        if( 
g_playerid ][ current_song_id ] == -&& round_started && g_playerid ][ play_songs ] ) {
                new 
random_song_id generate_random_song( );
                
client_start_musicidrandom_song_id );
        }
}

public 
lev_round_start( ) {
        if( !
plugin_active )
                return;

        
round_started true;

        if( 
boolget_pcvar_numg_cvarsSHOW_AD ] ) )
                
set_taskget_pcvar_floatg_cvarsSHOW_AD_TIMER ] ), "show_ad_task"TASK_SHOW_AD__"b" );

        
client_start_music_all( );
}

public 
lev_round_end( ) {
        if( !
plugin_active )
                return;

        
round_started false;

        if( 
task_existsTASK_SHOW_AD ) )
                
remove_taskTASK_SHOW_AD );

        
client_stop_music_all( );
}

public 
insert_songs( ) {
        new 
filePointer fopencfg_dir"r" );
        if( 
filePointer ) {
                new 
readDataSONG_PATH_MAX ];
                new 
SongItemSongData ];
                new 
SngNameSONG_NAME_MAX ], SngPathSONG_PATH_MAX ], SngLen];

                while( 
fgetsfilePointerreadDatacharsmaxreadData ) ) ) {
                        if( 
equalreadData"^n" ) || equalreadData"^r^n" ) )
                               continue;

                        
parsereadDataSngNamecharsmaxSngName ) - 1SngPathcharsmaxSngPath ) - 1SngLen);

                        if( !
file_existsSngPath ) ) {
                                
log_amx"%L"LANG_SERVER"SONG_NOT_FOUND"SngPath );
                                continue;
                        }

                        if( 
containiSngPath".wav" ) == -&& containiSngPath".mp3" ) == -) {
                                
log_amx"%L"LANG_SERVER"SONG_INVALID_FORMAT"SngName );
                                continue;
                        }

                        
SongItemsong_name ] = SngName;
                        
SongItemsong_path ] = SngPath;
                        
SongItemsong_length ] = _:str_to_numSngLen );
                        
SongItemis_wav ]    = ( containiSngPath".wav" ) != -) ? true false;

                        
ArrayPushArraySongsSongItem );
                        
g_total_songs++;
                }
                
fclosefilePointer );
        } else
                
plugin_active false;
}

client_start_music_all( ) {
        if( !
plugin_active )
                return;

        new 
random_song_id generate_random_song( );

        new 
players32 ], pnum;
        
get_playersplayerspnum );
        for( new 
index 0index pnumindex++ ) {
                if( 
g_playerplayersindex ] ][ play_songs ] )
                        
client_start_musicplayersindex ], random_song_id );
        }
}

client_start_musicidsong ) {
        if( !
plugin_active )
                return 
PLUGIN_CONTINUE;

        if( 
song g_total_songs )
                return 
PLUGIN_CONTINUE;

        
client_stop_musicidfalse );

        if( !
g_playerid ][ play_songs ] )
                
g_playerid ][ play_songs ] = true;

        
g_playerid ][ current_song_id ] = song;

        new 
playSongSongData ];
        
ArrayGetArraySongssongplaySong );

        
log_amx"It is: %s", ( playSongis_wav ] ) ? "spk" "mp3 play" );
        
log_amx"Song Path: %s"playSongsong_path ] );

        
client_cmdid"%s ^"%s^"", ( playSongis_wav ] ) ? "spk" "mp3 play"playSongsong_path ] );
        
set_taskfloatplaySongsong_length ] ), "client_song_finished"id SONG_TASK );

        return 
PLUGIN_CONTINUE;
}

public 
client_song_finishedid ) {
        
id -= SONG_TASK;

        new 
random_song_id;
        if( 
g_total_songs ) {
                do {
                        
random_song_id generate_random_song( );
                } while( 
g_playerid ][ current_song_id ] == random_song_id );
        } else
                
random_song_id 0;

        
client_start_musicidrandom_song_id );
}

client_stop_music_all( ) {
        if( !
plugin_active )
                return;

        new 
players32 ], pnum;
        
get_playersplayerspnum );
        for( new 
index 0index pnumindex++ )
                
client_stop_musicplayersindex ], false );
}

public 
client_stop_musicidboolstop_every ) {
        if( !
plugin_active )
                return 
PLUGIN_CONTINUE;

        if( 
stop_every )
                
g_playerid ][ play_songs ] = false;

        
g_playerid ][ current_song_id ] = -1;

        
remove_taskid SONG_TASK );
        
client_cmdid"mp3 stop" );

        return 
PLUGIN_CONTINUE;
}

/* MENU */
public clcmd_musicid ) {
        if( !
plugin_active )
                return 
PLUGIN_CONTINUE;

        static 
menuSONG_PATH_MAX ];
        new 
menu_id;

        
formatexmenucharsmaxmenu ), "%L"LANG_PLAYER"MUSIC_MENU_TITLE" );
        
menu_id menu_createmenu"menu_items_random" );

        
formatexmenucharsmaxmenu ), "%L"LANG_PLAYER"PLAY_RANDOM_SONG" );
        
menu_additemmenu_idmenu );

        
formatexmenucharsmaxmenu ), "%L"LANG_PLAYER"MUSIC_LIST_ITEM"g_total_songs );
        
menu_additemmenu_idmenu );

        
formatexmenucharsmaxmenu ), "%s%L", ( g_playerid ][ play_songs ] ) ? "\w" "\d"LANG_PLAYER"STOP_PLAYING" );
        
menu_additemmenu_idmenu );

    
formatexmenucharsmaxmenu ), "%L"LANG_PLAYER"EXIT_MUSIC_MENU" );
    
menu_setpropmenu_idMPROP_EXITNAMEmenu );

        
set_pdata_intidOFFSET_CSMENUCODE);
        
menu_displayidmenu_id);

        return 
PLUGIN_CONTINUE;
}

public 
menu_items_randomidmenuitem ) {
        if( !
plugin_active )
                return 
PLUGIN_HANDLED;

        switch( 
item ) {
                case 
0: {
                        new 
random_song_id generate_random_song( );
                        
client_start_musicidrandom_song_id );
                        
clcmd_musicid );
                }
                case 
1: {
                        
clcmd_music_listid );
                }
                case 
2: {
                        
client_stop_musicidtrue );
                        
clcmd_musicid );
                }
        }
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
}

public 
clcmd_music_listid ) {
        if( !
plugin_active )
                return 
PLUGIN_CONTINUE;

        static 
menuSONG_NAME_MAX ], SongItemSongData ];
        new 
menu_iditem_data], index;

        
formatexmenucharsmaxmenu ), "%L"LANG_PLAYER"MUSIC_LIST" );
        
menu_id menu_createmenu"music_list_handler" );

        for( 
index 0index g_total_songsindex++ ) {
                
ArrayGetArraySongsindexSongItem );

                
item_data] = index;
                
item_data] = 0;

                
formatexmenucharsmaxmenu ), "%s%s \r[ \y%d:%02d \r]", ( g_playerid ][ current_song_id ] == index ) ? "\d" "\w"SongItemsong_name ], SongItemsong_length ] / 60SongItemsong_length ] % 60 );
                
menu_additemmenu_idmenuitem_data );
        }

        
formatexmenucharsmaxmenu ), "%L"LANG_PLAYER"BACK_MUSIC_MENU" );
    
menu_setpropmenu_idMPROP_BACKNAMEmenu );

    
formatexmenucharsmaxmenu ), "%L"LANG_PLAYER"NEXT_MUSIC_MENU" );
    
menu_setpropmenu_idMPROP_NEXTNAMEmenu );

    
formatexmenucharsmaxmenu ), "%L"LANG_PLAYER"EXIT_MUSIC_MENU" );
    
menu_setpropmenu_idMPROP_EXITNAMEmenu );

        
set_pdata_intidOFFSET_CSMENUCODE);
        
menu_displayidmenu_id);

        return 
PLUGIN_CONTINUE;
}

public 
music_list_handleridmenuitem ) {
        if( 
item == MENU_EXIT || !plugin_active ) {
                
menu_destroymenu );
                return 
PLUGIN_HANDLED;
        }

        new 
item_data], dummyindex;
        
menu_item_getinfomenuitemdummyitem_datacharsmaxitem_data ), __dummy );
        
index item_data];
        
client_start_musicidindex );

        
clcmd_music_listid );
        return 
PLUGIN_HANDLED;
}

public 
show_ad_task( ) {
        
client_printcolor0"%L"LANG_PLAYER"AD_NOTIFICATION" );
}

generate_random_song( ) {
        return 
random_num0g_total_songs );
}

stock client_printcolor( const id, const input[], any:... ) {
        new 
count 1players32 ];
        static 
msg191 ];
        
vformatmsg190input);

        
replace_allmsg190"!g""^4" );
        
replace_allmsg190"!y""^1" );
        
replace_allmsg190"!t""^3" );

        if( 
id && is_user_connectedid ) )
                
players] = id;
        else
                
get_playersplayerscount"ch" );

        for( new 
index 0index countindex++ ) {
                
message_beginMSG_ONE_UNRELIABLEg_say_text_playersindex ] );
                
write_byteplayersindex ] );
                
write_stringmsg );
                
message_end( );
        }



PRoSToTeM@ 06-23-2017 08:40

Re: mp3 play not working for rehlds
 
Is mp3 sounds path 'sound/' prefixed?

JusTGo 06-23-2017 09:13

Re: mp3 play not working for rehlds
 
try with "developer 1" in client consol and give us the output


All times are GMT -4. The time now is 23:08.

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