AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to add a comma to a HUD message? (https://forums.alliedmods.net/showthread.php?t=336223)

GlobalPlague 02-05-2022 10:31

How to add a comma to a HUD message?
 
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.

Supremache 02-05-2022 10:46

Re: How to add a comma to a HUD message?
 
https://forums.alliedmods.net/showthread.php?t=335641

fysiks 02-05-2022 14:09

Re: How to add a comma to a HUD message?
 
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);



All times are GMT -4. The time now is 11:44.

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