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

Displaying stats issue (adding comma separator)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mehelp
Junior Member
Join Date: Jul 2011
Old 07-20-2011 , 23:36   Displaying stats issue (adding comma separator)
Reply With Quote #1

using l4d2 Custom Player Stats plugin by muukis, was trying to adopt displaying stats to what I'd prefer. got 2 issues to ask about
1.got problem adding comma separator between digits to player's points number.
stats are shown on infected death this way:
Name (1222) got points for killing infected
PHP Code:
GetClientName(iNamesizeof(Name));
CPrintToChat(i"{blue}%s \x01(%i) got points for killing Infected"Name, (ClientPoints[i] + CurrentPoints[i])); 
What I'd want it to look like:
Name (1,222) got poitns for killing infected - with comma after first digit

Powerlord made "port of the AddCommas function to SourceMod.
SourceMod only has a float absolute value function."

PHP Code:
stock AddCommasiNumString:szOutput[] , iLen )
{
    new 
String:szTmp15 ] , iOutputPos iNumPos iNumLen;
    
    if ( 
iNum )
    {
        
szOutputiOutputPos++ ] = '-';
        
iNum = ~iNum 1// Two's complement conversion
    
}
    
    
IntToStringiNumszTmpsizeof(szTmp));
    
iNumLen strlen(szTmp);
    
    if ( 
iNumLen <= )
    {
        
iOutputPos += StrCatszOutput iLen szTmp );
    }
    else
    {
        while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) )
        {
            
szOutputiOutputPos++ ] = szTmpiNumPos++ ];
            
            if ( ( 
iNumLen iNumPos ) && !( (iNumLen iNumPos ) % ) )
            {
                
szOutputiOutputPos++ ] = ',';
            }
        }
        
        
szOutputiOutputPos ] = '\0';
    }
    
    return 
iOutputPos;

tried to call it:
PHP Code:
new String:szPoints[15];
GetClientName(iNamesizeof(Name));
AddCommas((ClientPoints[i] + CurrentPoints[i]), szPointssizeof(szPoints));
CPrintToChat(i"{blue}%s \x01(%s) got points for killing Infected"NameszPoints); 
didn't work. been desperately trying to add this bloody comma for days with no effect, need help

2. another thing about displaying stats - dealing with special infected, for exapmple:
"Name(1,111) got points for (1)Boomer" , VictimName (Boomer) is shown with number in front of it, if there's few of them currently spawned on the map; like when you look at players list thru adminmenu - it says:
1. Hunter
2. (1)Hunter,
when there's couple of infected of the same type. but when you killed (1)Boomer, you can assume there's more nearby, which should be a surprise I suppose. is it possible to remove characters in front of infected name?

Last edited by mehelp; 07-20-2011 at 23:48.
mehelp is offline
mehelp
Junior Member
Join Date: Jul 2011
Old 07-23-2011 , 04:59   Re: Displaying stats issue (adding comma separator)
Reply With Quote #2

ok then.. well maybe there's a way to use dot as a digit separator, not comma? there's actually a format specifier %f for displaying a number with floating point in sourcemod. but how??
mehelp is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 07-23-2011 , 14:27   Re: Displaying stats issue (adding comma separator)
Reply With Quote #3

PHP Code:
stock FormatNumberInt(valueString:buffer[], sizeseperator='.')
{
    
decl String:helper[size];
    
IntToString(valuehelpersize);
    
strcopy(buffersizehelper);

    new 
length strlen(helper);

    new 
n_helper;

    if (
helper[0] == '-') {
        
n_helper += ((length-1) % 3) + 1;

        if (
n_helper == 1) {
            
n_helper 4;
        }
    }
    else {
        
n_helper += length 3;

        if (
n_helper == 0) {
            
n_helper 3;
        }
    }

    new 
n_buffer n_helper;

    while (
n_helper length) {
        
buffer[n_buffer] = seperator;
        
strcopy(buffer[n_buffer 1], sizehelper[n_helper]);

        
n_buffer += 4;
        
n_helper += 3;
    }

Mathematical version: (bit slower with big numbers)

PHP Code:
stock FormatNumber_(valueString:buffer[], sizeseperator='.')
{
    
buffer[0] = '\0';

    new 
divisor 1000;

    while (
value >= 1000 || value <= -1000) {
        new 
offcut value divisor;
        
value RoundToFloor(float(value) / float(divisor));

        
Format(buffersize"%c%03.d%s"seperatoroffcutbuffer);
    }

    
Format(buffersize"%d%s"valuebuffer);

    return;

__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 07-23-2011 at 14:33.
berni is offline
mehelp
Junior Member
Join Date: Jul 2011
Old 07-23-2011 , 21:56   Re: Displaying stats issue (adding comma separator)
Reply With Quote #4

Quote:
Originally Posted by berni View Post
PHP Code:
stock FormatNumberInt(valueString:buffer[], sizeseperator='.')
{
    
decl String:helper[size];
    
IntToString(valuehelpersize);
    
strcopy(buffersizehelper);

    new 
length strlen(helper);

    new 
n_helper;

    if (
helper[0] == '-') {
        
n_helper += ((length-1) % 3) + 1;

        if (
n_helper == 1) {
            
n_helper 4;
        }
    }
    else {
        
n_helper += length 3;

        if (
n_helper == 0) {
            
n_helper 3;
        }
    }

    new 
n_buffer n_helper;

    while (
n_helper length) {
        
buffer[n_buffer] = seperator;
        
strcopy(buffer[n_buffer 1], sizehelper[n_helper]);

        
n_buffer += 4;
        
n_helper += 3;
    }

Mathematical version: (bit slower with big numbers)

PHP Code:
stock FormatNumber_(valueString:buffer[], sizeseperator='.')
{
    
buffer[0] = '\0';

    new 
divisor 1000;

    while (
value >= 1000 || value <= -1000) {
        new 
offcut value divisor;
        
value RoundToFloor(float(value) / float(divisor));

        
Format(buffersize"%c%03.d%s"seperatoroffcutbuffer);
    }

    
Format(buffersize"%d%s"valuebuffer);

    return;

Now finally, thank you, sir, thank you very big. That works perfectly. Such a relief to finally have it. You should run for president or something - that's how smart and pretty you are. Even though I didn't get it why is "Mathematical version: " is funnier than non mathematical one (need to learn more bout scripting, which I will go and do right away), laughed like a horse. Thank you, berni, have a nice day. as nice as possible

Last edited by mehelp; 07-23-2011 at 23:05.
mehelp is offline
Reply


Thread Tools
Display Modes

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 06:52.


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