AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud? (https://forums.alliedmods.net/showthread.php?t=335641)

StickBarosanu 12-20-2021 14:50

How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud?
 
Hi! I want to make the xp hud to look like 5,000/10,000xp instead of 5000/10000xp. I'm using ocixcrom level system plugin

I want to make this:https://i.imgur.com/pEyajk0_d.webp?m...fidelity=grand


To look like this one:https://i.imgur.com/XeBntCb.jpg

Thank you!!

OciXCrom 12-20-2021 15:04

Re: How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud?
 
This would require messing with the main code (crx_ranksystem.sma).

Add this function somewhere in the code (e.g. in the bottom):

PHP Code:

// Credits to Bugsy
AddCommasiNum szOutput[] , iLen )
{
    new 
szTmp15 ] , iOutputPos iNumPos iNumLen;
    
    if ( 
iNum )
    {
        
szOutputiOutputPos++ ] = '-';
        
iNum absiNum );
    }
    
    
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;


Then find the "update_hudinfo" function (line 1442).
You'll see this piece of code:

Code:
if(has_argument(szMessage, ARG_CURRENT_XP)) {     num_to_str(g_ePlayerData[id][XP], szPlaceHolder, charsmax(szPlaceHolder))     replace_string(szMessage, charsmax(szMessage), ARG_CURRENT_XP, szPlaceHolder) }

This is how the XP is displayed - it converts the number into a string.
Simply change "num_to_str" to "AddCommas" and it should add commas to the number.

Do the same to the other portions of the code below this one - for ARG_NEXT_XP and ARG_XP_NEEDED.

GlobalPlague 02-15-2022 10:43

Re: How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud?
 
Quote:

Originally Posted by OciXCrom (Post 2766572)
This would require messing with the main code (crx_ranksystem.sma).

Add this function somewhere in the code (e.g. in the bottom):

PHP Code:

// Credits to Bugsy
AddCommasiNum szOutput[] , iLen )
{
    new 
szTmp15 ] , iOutputPos iNumPos iNumLen;
    
    if ( 
iNum )
    {
        
szOutputiOutputPos++ ] = '-';
        
iNum absiNum );
    }
    
    
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;


Then find the "update_hudinfo" function (line 1442).
You'll see this piece of code:

Code:
if(has_argument(szMessage, ARG_CURRENT_XP)) {     num_to_str(g_ePlayerData[id][XP], szPlaceHolder, charsmax(szPlaceHolder))     replace_string(szMessage, charsmax(szMessage), ARG_CURRENT_XP, szPlaceHolder) }

This is how the XP is displayed - it converts the number into a string.
Simply change "num_to_str" to "AddCommas" and it should add commas to the number.

Do the same to the other portions of the code below this one - for ARG_NEXT_XP and ARG_XP_NEEDED.

This method doesn't work. I did exactly what you recommended, the .sma file got compiled without any errors or warnings, but there is still no comma.

OciXCrom 02-15-2022 13:37

Re: How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud?
 
Impossible. Post the full code with your changes.

GlobalPlague 02-16-2022 17:42

Re: How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud?
 
Quote:

Originally Posted by OciXCrom (Post 2771551)
Impossible. Post the full code with your changes.

Wait... it was my mistake.

I forgot i edited your plugin a little bit.

The AddCommas function works only for the original HUD message of your plugin, but doesn't work for the edited HUD message.

My ZM server doesn't use the original HUD message. Instead, i disabled it:

Code:

HUDINFO_ENABLED = 1
===>

Code:

HUDINFO_ENABLED = 0
I had to enable the original HUD, so i can see the comma, and realize the AddCommas function actually works perfectly.

See this screenshot: https://pasteboard.co/X1vmEk3HoSoa.jpg

As you can see in the image above, the AddCommas function works only for the original HUD, but not for the edited HUD - the HUD added in the ZP HUD info message.

I would like the original HUD to be disabled, so only the edited HUD to remain. In other words, i want the comma to be added to the HUD rank message that is part of the ZP HUD info message.

Do you understand what I'm talking about? My English is bad, but i will try explaining better, if you don't understand me.

Supremache 02-16-2022 17:57

Re: How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud?
 
This function should work in any plugin with any code but make sure you are Use it correctly.

PHP Code:

if (id != ID_SHOWHUD)
{
    
// Show name, health, class, and ammo packs and armor
    
set_dhudmessage(00138HUD_SPECT_XHUD_SPECT_Y16.01.10.00.0)
    
show_dhudmessage(ID_SHOWHUD"%L %s^nHP: %d - %L %s - %L %d - %L %d"ID_SHOWHUD"SPECTATING"g_playername[id],
    
pev(idpev_health), ID_SHOWHUD"CLASS_CLASS", class, ID_SHOWHUD"AMMO_PACKS1"g_ammopacks[id], ID_SHOWHUD"ARMOR"pev(idpev_armorvalue))
}
else
{
    new 
szXPCommas16 ], szNextXPCommas16 ], szAPCommas16 ];
    
AddCommasmysystem_get_user_xpid ), szXPCommascharsmaxszXPCommas ) );
    
AddCommasmysystem_get_user_next_xp(id), szNextXPCommascharsmaxszNextXPCommas ) );
    
AddCommasg_ammopacks[id], szAPCommascharsmaxszAPCommas ) );
    
    
set_dhudmessage(redgreenblueHUD_STATS_XHUD_STATS_Y06.01.10.00.0)
    
show_dhudmessage(ID_SHOWHUD"%L: %d - %L %s - %L %d - %L %d^nXP: %s/%s | Level: %d/%d: %s"id"ZOMBIE_ATTRIB1"pev(ID_SHOWHUDpev_health), ID_SHOWHUD"CLASS_CLASS",
    class, 
ID_SHOWHUD"AMMO_PACKS1"g_ammopacks[ID_SHOWHUD], ID_SHOWHUD"ARMOR"pev(ID_SHOWHUDpev_armorvalue), szXPCommasszNextXPCommasmysystem_get_user_level(id), mysystem_get_max_levels(), ranknameszAPCommas )



GlobalPlague 02-16-2022 19:35

Re: How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud?
 
Quote:

Originally Posted by Supremache (Post 2771657)
This function should work in any plugin with any code but make sure you are Use it correctly.

PHP Code:

if (id != ID_SHOWHUD)
{
    
// Show name, health, class, and ammo packs and armor
    
set_dhudmessage(00138HUD_SPECT_XHUD_SPECT_Y16.01.10.00.0)
    
show_dhudmessage(ID_SHOWHUD"%L %s^nHP: %d - %L %s - %L %d - %L %d"ID_SHOWHUD"SPECTATING"g_playername[id],
    
pev(idpev_health), ID_SHOWHUD"CLASS_CLASS", class, ID_SHOWHUD"AMMO_PACKS1"g_ammopacks[id], ID_SHOWHUD"ARMOR"pev(idpev_armorvalue))
}
else
{
    new 
szXPCommas16 ], szNextXPCommas16 ], szAPCommas16 ];
    
AddCommasmysystem_get_user_xpid ), szXPCommascharsmaxszXPCommas ) );
    
AddCommasmysystem_get_user_next_xp(id), szNextXPCommascharsmaxszNextXPCommas ) );
    
AddCommasg_ammopacks[id], szAPCommascharsmaxszAPCommas ) );
    
    
set_dhudmessage(redgreenblueHUD_STATS_XHUD_STATS_Y06.01.10.00.0)
    
show_dhudmessage(ID_SHOWHUD"%L: %d - %L %s - %L %d - %L %d^nXP: %s/%s | Level: %d/%d: %s"id"ZOMBIE_ATTRIB1"pev(ID_SHOWHUDpev_health), ID_SHOWHUD"CLASS_CLASS",
    class, 
ID_SHOWHUD"AMMO_PACKS1"g_ammopacks[ID_SHOWHUD], ID_SHOWHUD"ARMOR"pev(ID_SHOWHUDpev_armorvalue), szXPCommasszNextXPCommasmysystem_get_user_level(id), mysystem_get_max_levels(), ranknameszAPCommas )



So, firstly, i have to add Bugsy's AddCommas code at the bottom of the main ZPA source code, and then use the code you gave me. Did i understand you correctly?

Supremache 02-16-2022 20:58

Re: How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud?
 
Quote:

Originally Posted by GlobalPlague (Post 2771660)
So, firstly, i have to add Bugsy's AddCommas code at the bottom of the main ZPA source code, and then use the code you gave me. Did i understand you correctly?

Yes, but i want you learn how to use it!!

OciXCrom 02-17-2022 14:20

Re: How can i make ocixcrom level plugin to show 5,000/10,000Xp in hud?
 
If you're using a different plugin for the HUD, of course you need to add the AddCommas function there.


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

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