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

How to add a comma to a HUD message?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 02-05-2022 , 10:31   How to add a comma to a HUD message?
Reply With Quote #1

Hello. Can someone explain to me how to add a comma to the HUD Info message for health?

Here is an example of a HUD message:

Health: 5000 | Class: Zombie | Ammo: 30 | Armor: 0

Here is how the HUD message should look like:

Health: 5,000 | Class: Zombie | Ammo: 30 | Armor: 0

As you can see, the second HUD message has a comma where the stats of Health is – it’s “5,000”, instead of “5000”.

So, can someone explain to me how to add a comma?

I added the following code at the end of the source code of ZP:

PHP Code:
public AddCommasiNum szOutput[] , iLen )
{
    new 
szTmp17 ] , iOutputPos iNumPos iNumLen;
    
    
//if ( iNum < 0 )
    //{
    //    szOutput[ iOutputPos++ ] = '-';
    //    iNum = abs( iNum );
    //}
    
    
iNumLen num_to_striNum szTmp charsmaxszTmp ) );
    
    if ( 
iNumLen <= )
    {
        
iOutputPos += copyszOutputiOutputPos ] , iLen szTmp );
    }
    else
    {
        while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) ) 
        {
            
szOutputiOutputPos++ ] = szTmpiNumPos++ ];
            
            if( ( 
iNumLen iNumPos ) && !( ( iNumLen iNumPos ) % ) ) 
                
szOutputiOutputPos++ ] = ',';
        }
            
        
szOutputiOutputPos ] = EOS;
    }
    
    return 
iOutputPos;

However, it didn’t work, and there is still no comma.

Then, I added this to the code responsible for showing the HUD Info message:

PHP Code:
add_point(g_ammopacks[id
After that, I added the following code at the bottom of the source code of ZP:

PHP Code:
stock add_point(number)

    new 
countistr[29], str2[35], len
    num_to_str
(numberstrcharsmax(str))
    
len strlen(str)
    
    for (
0leni++)
    {
        if (
!= && ((len i) %== 0))
        {
            
add(str2charsmax(str2), "."1)
            
count++
            
add(str2[i+count], 1str[i], 1)
        }
        else
            
add(str2[i+count], 1str[i], 1)
    }

    return 
str2;

But, again, it didn’t work.

Maybe, I’m doing it the wrong way, or the codes are wrong?

The second code is about adding a point, not a comma. I prefer my HUD to have a comma, instead of a point, but if no one knows how to add exactly a comma, I will be ok with adding a point.

Thanks.

Last edited by GlobalPlague; 02-05-2022 at 10:32.
GlobalPlague is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 02-05-2022 , 10:46   Re: How to add a comma to a HUD message?
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=335641
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-05-2022 , 14:09   Re: How to add a comma to a HUD message?
Reply With Quote #3

The AddCommas() function by Bugsy which you have in your post works exactly as expected so you are using it wrong. Also, there is no reason to change anything in the function.

So, go back to using the AddCommas() function (I recommend taking it directly from the thread mentioned by Supremache). Then, create a temporary string to hold the resulting string and replace the %d in the format string in show_hudmessage() with %s and replace the value being used in that position to this new temporary string. Like this:

Code:
show_hudmessage(id, "Health: %d | Class: %s | Ammo: %d | Armor: %d", iHealth, szClassName, iAmmo, iArmor);
Code:
new szHealth[15];
AddCommas(iHealth, szHealth, charsmax(szHealth));
show_hudmessage(id, "Health: %s | Class: %s | Ammo: %d | Armor: %d", szHealth, szClassName, iAmmo, iArmor);
__________________
fysiks 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 12:49.


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