Raised This Month: $51 Target: $400
 12% 

Table Buffer for Console


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ofir753
Senior Member
Join Date: Aug 2012
Old 06-14-2016 , 11:01   Table Buffer for Console
Reply With Quote #1

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[], maxlengthString:sValues[][][], rowscols)
{
    
FormatEx(sBuffermaxlength"");

    new 
tabCount[cols];
    new 
len;
    new 
tab;
    for (
int i 0rowsi++)
    {
        for (
int j 0colsj++)
        {
            
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 0rowsi++)
    {
        for (
int j 0colsj++)
        {
            
FormatEx(sBuffermaxlength"%s%s"sBuffersValues[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 0tabk++)
            {
                
Format(sBuffermaxlength"%s\t"sBuffer);
            }
        }
        
Format(sBuffermaxlength"%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 clientint args)
{
    new 
String:sBuffer[1024];
    new 
String:sValues[8][4][64];

    for (
int i 08i++)
    {
        for (
int j 04j++)
        {
            if(
== && == 0)
                
FormatEx(sValues[i][j], 64"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
            else if(
== && == 0)
                
FormatEx(sValues[i][j], 64"AAAAAAAAAAAAAAAAAAAAAAAA");
            else if(
== && == 0)
                
FormatEx(sValues[i][j], 64"AAAAAAAAAAAAAAAA");
            else
                
FormatEx(sValues[i][j], 64"Test %d,%d"ij);

        }
    }

    
MakeConsoleTable(sBuffersizeof(sBuffer), sValues84);

    
PrintToConsole(clientsBuffer);

    return 
Plugin_Handled;

Attached Files
File Type: sp Get Plugin or Get Source (consoleTableTest.sp - 189 views - 992 Bytes)
File Type: inc consoletable.inc (1.4 KB, 128 views)
ofir753 is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 06-14-2016 , 13:43   Re: Table Buffer for Console
Reply With Quote #2

Nice release, I hate having to manually make tables.
Addicted. is offline
Electr000999
Senior Member
Join Date: Aug 2011
Old 07-12-2016 , 06:59   Re: Table Buffer for Console
Reply With Quote #3

test failed if i try write like this

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++)
		{
			// FORMAT 1 COLUMN HEADER NAME 
			if(i == 0 && j == 0)
				FormatEx(sValues[i][j], 64, "Col 1");
			// FORMAT 1 COLUMN ROW DATA
			else if(i == 1 && j == 0)
				FormatEx(sValues[i][j], 64, "Row 1");
			else if(i == 2 && j == 0)
				FormatEx(sValues[i][j], 64, "Row 2 tuyi9o");
			else if(i == 3 && j == 0)
				FormatEx(sValues[i][j], 64, "Row 3");
			else if(i == 4 && j == 0)
				FormatEx(sValues[i][j], 64, "Row 4 fjuhkiuuloil");
			else if(i == 5 && j == 0)
				FormatEx(sValues[i][j], 64, "Row 5 fjuhkiuuloil");
			else if(i == 6 && j == 0)
				FormatEx(sValues[i][j], 64, "Row 6 fjuhkiuuloil");
			else if(i == 7 && j == 0)
				FormatEx(sValues[i][j], 64, "Row 7 fjuhkiuuloil");				
			// FORMAT OTHER HEADER COLUMNS
			else if(i == 0 && j == 1)
				FormatEx(sValues[i][j], 64, "Col 2");
			else if(i == 0 && j == 2)
				FormatEx(sValues[i][j], 64, "Col 3");
			else if(i == 0 && j == 3)
				FormatEx(sValues[i][j], 64, "Col 4");	
			else
				FormatEx(sValues[i][j], 64, "%d", GetRandomInt(1,6567888));
		}
	}

	MakeConsoleTable(sBuffer, sizeof(sBuffer), sValues, 8, 4);

	PrintToConsole(client, sBuffer);

	return Plugin_Handled;
}

//http://i.imgur.com/akppDbP.png
I am write in first column same spam like a different player names.
Attached Thumbnails
Click image for larger version

Name:	3366.PNG
Views:	218
Size:	12.1 KB
ID:	156172  

Last edited by Electr000999; 07-12-2016 at 07:00.
Electr000999 is offline
Send a message via Skype™ to Electr000999
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 23:54.


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