Hey, I have made a small stock for formatting a orinated table to player console, here is an example
http://i.imgur.com/akppDbP.png
The Stock:
PHP Code:
/**
* Formatting a orianted table for console output
*
* @param sBuffer String to be Formated
* @param maxlength size of sBuffer
* @param sValues Table content, first dem symbols the row, second dem symbols the col
* @param rows Count of the rows
* @param cols Count of the cols
*
* @noreturn
*/
stock MakeConsoleTable(String:sBuffer[], maxlength, String:sValues[][][], rows, cols)
{
FormatEx(sBuffer, maxlength, "");
new tabCount[cols];
new len;
new tab;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
len = strlen(sValues[i][j]);
if(len > 15)
{
len -= 15;
tab = 2;
if(len > 0)
tab += (len / 8);
}
else
{
tab = 1;
}
if(tab > tabCount[j])
tabCount[j] = tab;
}
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
FormatEx(sBuffer, maxlength, "%s%s", sBuffer, sValues[i][j]);
len = strlen(sValues[i][j]);
if(len > 15)
{
len -= 15;
tab = 2;
if(len > 0)
tab += (len / 8);
tab = tabCount[j] - tab + 1;
}
else
{
tab = tabCount[j]
}
for (int k = 0; k < tab; k++)
{
Format(sBuffer, maxlength, "%s\t", sBuffer);
}
}
Format(sBuffer, maxlength, "%s\n", sBuffer);
}
}
The Test File:
PHP Code:
#include <sourcemod>
#include <consoletable>
public Plugin myinfo =
{
name = "Console Table Test",
author = "Ofir",
description = "",
version = "1.0",
url = "steamcommunity.com/id/OfirGal1337"
};
public void OnPluginStart()
{
RegConsoleCmd("sm_table", Command_Table);
}
public Action Command_Table(int client, int args)
{
new String:sBuffer[1024];
new String:sValues[8][4][64];
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 4; j++)
{
if(i == 0 && j == 0)
FormatEx(sValues[i][j], 64, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
else if(i == 1 && j == 0)
FormatEx(sValues[i][j], 64, "AAAAAAAAAAAAAAAAAAAAAAAA");
else if(i == 2 && j == 0)
FormatEx(sValues[i][j], 64, "AAAAAAAAAAAAAAAA");
else
FormatEx(sValues[i][j], 64, "Test %d,%d", i, j);
}
}
MakeConsoleTable(sBuffer, sizeof(sBuffer), sValues, 8, 4);
PrintToConsole(client, sBuffer);
return Plugin_Handled;
}