Raised This Month: $ Target: $400
 0% 

Read File...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-16-2013 , 23:30   Read File...
Reply With Quote #1

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;
__________________
Blizzard_87 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-17-2013 , 00:32   Re: Read File...
Reply With Quote #2

If you do that once during the map, yes, but it doesn't seem to be the case.
Would be better to load all stuff in a dynamic array, datas should be faster to retrieve.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-17-2013 , 07:54   Re: Read File...
Reply With Quote #3

Quote:
Originally Posted by ConnorMcLeod View Post
If you do that once during the map, yes, but it doesn't seem to be the case.
Would be better to load all stuff in a dynamic array, datas should be faster to retrieve.
ok cheers.
__________________
Blizzard_87 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 16:25.


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