Quote:
Originally Posted by mehelp
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 AddCommas( iNum, String:szOutput[] , iLen )
{
new String:szTmp[ 15 ] , iOutputPos , iNumPos , iNumLen;
if ( iNum < 0 )
{
szOutput[ iOutputPos++ ] = '-';
iNum = ~iNum + 1; // Two's complement conversion
}
iNumLen = IntToString( iNum, szTmp, sizeof(szTmp));
if ( iNumLen <= 3 )
{
iOutputPos += strcopy( szOutput[ iOutputPos ] , iLen , szTmp );
}
else
{
while ( ( iNumPos < iNumLen ) && ( iOutputPos < iLen ) )
{
szOutput[ iOutputPos++ ] = szTmp[ iNumPos++ ];
if ( ( iNumLen - iNumPos ) && !( (iNumLen = iNumPos ) % 3 ) )
{
szOutput[ iOutputPos++ ] = ',';
}
}
szOutput[ iOutputPos ] = '\0';
}
return iOutputPos;
}
__________________