Thread: Scripting Forum
View Single Post
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-19-2011 , 10:55   Re: Scripting Forum
Reply With Quote #22

Quote:
Originally Posted by mehelp View Post
need help adding comma separator between digits to number, displaying in chat

want chat to display player's points on infected death with comma after thousand, for instance:
stupid (10,222) got 1 point for killing infected
can't get 10222 number with comma
what doI do with this:
PrintToChat(i, "%s (%i) got point for killing Infected", Name, (ClientPoints[i] + CurrentPoints[i]));

was advised to go
http://forums.alliedmods.net/showpos...45&postcount=5
but that requires amxmod. what's the way for sourcemod?
You really should post this as its own thread.

Having said that, here's a quick and completely untested port of the AddCommas function to SourceMod. SourceMod only has a float absolute value function, so I did a two's complement to swap the sign.

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

__________________
Not currently working on SourceMod plugin development.
Powerlord is offline