AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Table Buffer for Console (https://forums.alliedmods.net/showthread.php?t=283913)

ofir753 06-14-2016 11:01

Table Buffer for Console
 
2 Attachment(s)
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;



Addicted. 06-14-2016 13:43

Re: Table Buffer for Console
 
Nice release, I hate having to manually make tables.

Electr000999 07-12-2016 06:59

Re: Table Buffer for Console
 
1 Attachment(s)
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.


All times are GMT -4. The time now is 18:52.

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