Sometimes you may want to print lot of lines in client console.
But, the result is very often mixed and torned by the engine (at least in L4D, not sure about other games).
Below method is not 100% guarantee the lines will be always in correct order.
However, in most cases it is.
Each PrintToConsole command has auto-splitted between different frames, so the output looks fine.
PS. One simple walkaround could be concatenating all lines in a single variable using \n
However, the max buffer per command is like ~254 characters length.
So, if you have more data to output, these methods may be helpful for you:
public Action Cmd_Test1(int client, int argc) { for( int i = 0; i < 10; i++ ) { PrintToConsoleQueue(client, "Line number %i.", i); } return Plugin_Handled; }
public Action Cmd_Test2(int client, int argc) { for( int i = 0; i < 10; i++ ) { PrintToConsole(client, "Line number %i.", i); } return Plugin_Handled; }
void PrintToConsoleQueue(int client, const char[] format, any ...) { static char buffer[254]; static ArrayList al; if( !al ) { al = new ArrayList(ByteCountToCells(254)); } SetGlobalTransTarget(client); VFormat(buffer, sizeof(buffer), format, 3); if( al.Length == 0 ) { RequestFrame(Frame_PrintQueue, al); } al.Push(client); al.PushString(buffer); }
Sometimes you may want to print one very huge line.
Below technique allows you to split it by delimiter you specified and print without mixing/torning:
Spoiler
PHP Code:
char DELIM[] = "\x1D";
public void OnPluginStart() { RegAdminCmd ("sm_test3", Cmd_Test3, ADMFLAG_ROOT, "Test printing the huge line, splitting it by DELIM and preventing mixed/torned lines"); }
public Action Cmd_Test3(int client, int argc) { char buffer[4096]; char s[254]; for( int i = 0; i < 10; i++ ) { FormatEx(s, sizeof(s), "Line number %i. Some very loooooooong and complicated string...", i); StrCat(buffer, sizeof(buffer), s); StrCat(buffer, sizeof(buffer), DELIM); } PrintToConsoleFramed(client, buffer); return Plugin_Handled; }
Thanks for the guide Dragokas, I had to use that kind of solution once already, since I usually output my plugin configs to the console, and depending on the plugin, may have a lot of info.