AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Read File... (https://forums.alliedmods.net/showthread.php?t=216120)

Blizzard_87 05-16-2013 23:30

Read File...
 
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;

ConnorMcLeod 05-17-2013 00:32

Re: Read File...
 
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.

Blizzard_87 05-17-2013 07:54

Re: Read File...
 
Quote:

Originally Posted by ConnorMcLeod (Post 1953189)
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.


All times are GMT -4. The time now is 16:25.

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