is this the correct way to read file select random line then show motd from that random line?
in the cfg file the lines are
file name motd header name
"motd1.txt" "MOTD NAME 1"
Code:
new configsdir[200];
new configfile[200];
get_configsdir( configsdir, charsmax( configsdir ) );
format( configfile, charsmax( configsdir ), "%s/motds/motds.cfg", configsdir);
new size = file_size( configfile, 1 ); //Get the number of lines the file has
new random = random_num( 0, size ); //Get any line between 0 and the number of line
new trash; //Useless
new text[256]; //Where the line will be kept
if( file_exists( configfile ) ) read_file( configfile, random, text, charsmax( text ), trash);
else {
log_amx( "%s File Was Not Found", configfile );
return;
}
new Left[ 64 ], Right[ 64 ];
//strbreak( text, Left, charsmax( Left ), Right, charsmax( Right ) );
strbreak( text, Left, 63, Right, 63 );
remove_quotes( Left );
remove_quotes( Right );
new Motd[ 64 ];
format( Motd, charsmax( Motd ), "%s/motds/%s", configsdir, Left );
show_motd( id, Motd, Right );
return;
__________________