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

Text align in Console


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Predator01337
Junior Member
Join Date: Feb 2012
Old 06-28-2012 , 15:16   Text align in Console
Reply With Quote #1

PHP Code:
PrintToConsole(client"#%d | %s | %s | %s"useridnamesteamidip); 
Will print to the console of client:
Code:
#0000 | Testname | STEAM_0:00000 | 00.000.00.000
#00 | Tstname | STEAM_0:000 | 0.0.00.0
But what i want to realize is this:

Code:
#0000 | Testname | STEAM_0:00000 | 00.000.00.000
#00   | Tstname  | STEAM_0:000   | 0.0.00.0
I just don't know how to do it.

My English isn't very good but hopefully someone could help me
Predator01337 is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 06-28-2012 , 15:25   Re: Text align in Console
Reply With Quote #2

You have to equally pad out each item between the |
To do that successfully you have to prepare all of your data that you're going to print. Determine the largest piece of data for each split by the |
Then pad out each piece of data according to what the largest piece of data in that column is.
To do that do

new spaces = SizeOfBiggestPieceOfData-strlen(PieceOfData);
for(new i=0; i<spaces; i++)
{
Format(PieceOfData, sizeof(PieceOfData), "%s ", PieceOfData);
}


This might all be fuzzy, but it's the only way I can think of doing this.
Keep in mind this might not work if the font that the game you're using doesn't have equal length characters.
__________________

Last edited by McFlurry; 06-28-2012 at 15:33.
McFlurry is offline
Send a message via Skype™ to McFlurry
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 06-28-2012 , 15:43   Re: Text align in Console
Reply With Quote #3

I made this one day when i was realllllly bored.
PHP Code:
public OnMapStart()
{
    new 
String:steamarray[7][30] = {"STEAM_0:0:12645810""STEAM_0:0:222777""STEAM_0:1:13921601""STEAM_0:1:14923191""STEAM_0:0:6762100""STEAM_0:1:324537""STEAM_0:1:1234"}

    
CreateColumn(steamarray7truetrue30);
    
    for(new 
07i++)
    {
        
PrintToServer(steamarray[i]);
    }
}
CreateColumn(String:testarray[][], sizebool:begbool:endmaxsize)
{
    new 
long;
    for(new 
0sizei++)
    {
        if(
strlen(testarray[i]) > long)
            
long strlen(testarray[i]);
    }
    for(new 
0sizei++)
    {    
        new 
diff long strlen(testarray[i]);
        if(
diff 0)
        {
            for(new 
0diffo++)
            {
                
StrCat(testarray[i], maxsize" ");
            }
        }
    }
    if(
beg)
    {
        for(new 
0sizei++)
        {
            
Format(testarray[i], maxsize"| %s"testarray[i]);
        }
    }
    if(
end)
    {    
        for(new 
0sizei++)
            
StrCat(testarray[i], maxsize" |");
    }

Note: I did this about 3 years ago when i first started out. And there might be a better way to do this.

You have to pass all the data for each column in a array then loop and format each array if beg/end is true it will auto add | to the start or end.
Dr!fter is offline
Predator01337
Junior Member
Join Date: Feb 2012
Old 06-28-2012 , 16:03   Re: Text align in Console
Reply With Quote #4

Thank you for this replies.

I test it tomorrow.

I'm gonna optimize my code and combine it with yours.
Predator01337 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-28-2012 , 17:27   Re: Text align in Console
Reply With Quote #5

I guess no one ever reads the Advanced Formatting section of the Format wiki page.

I hate to say this, though, we're going to need to use Format once because we need values from functions and constants in our final format:

PHP Code:
#define STEAMID_LENGTH 32

    
decl String:logFormat[40];
    
Format(logFormatsizeof(logFormat), "#%%-4d | %%-%ds | %%-%ds | %%-15s"MAX_NAME_LENGTHSTEAMID_LENGTH);

    
PrintToConsole(clientlogFormatuseridnamesteamidip); 
Note: Untested, but should give you 4 character userids (btw, this really should be increased to 5), MAX_NAME_LENGTH names, 32-character Steam IDs, and 15 character IPs (assuming IPv4 addresses with no port).
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-28-2012 at 17:35.
Powerlord is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 06-28-2012 , 17:56   Re: Text align in Console
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
I guess no one ever reads the Advanced Formatting section of the Format wiki page.

I hate to say this, though, we're going to need to use Format once because we need values from functions and constants in our final format:

PHP Code:
#define STEAMID_LENGTH 32

    
decl String:logFormat[40];
    
Format(logFormatsizeof(logFormat), "#%%-4d | %%-%ds | %%-%ds | %%-15s"MAX_NAME_LENGTHSTEAMID_LENGTH);

    
PrintToConsole(clientlogFormatuseridnamesteamidip); 
Note: Untested, but should give you 4 character userids (btw, this really should be increased to 5), MAX_NAME_LENGTH names, 32-character Steam IDs, and 15 character IPs (assuming IPv4 addresses with no port).
This is what I was going to post. I've used the advanced formatting a lot when creating timers to pad single-digit numbers with a leading zero. Lets me easily change 0:5 to 00:05.
__________________
Dr. McKay is offline
el_psycho
Member
Join Date: Feb 2012
Location: Vancouver, Canada
Old 08-26-2012 , 18:48   Re: Text align in Console
Reply With Quote #7

This is very useful.
I have an additional question:
How would i go about aligning text to the right? Like in the player names in a chatlog like this:
Code:
[20:15:35]        SomePlayer: player chat message
[20:15:38]     AnotherPlayer: another player's message
Thanks.

Last edited by el_psycho; 08-26-2012 at 18:48.
el_psycho is offline
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 15:02.


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