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

Solved String formatting


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-12-2019 , 06:55   String formatting
Reply With Quote #1

Hi,

Would I be able to have a text in my .ini file like this:
PHP Code:
"Player Name: %s | Player Cash: %d" 
and then having the %s and %d show values instead of just %s %d?

This shows the %s and %d's as plain text, without them referencing to values.

PHP Code:
ShowSyncHudMsgidg_iSyncHud"%s"g_eHudsMAIN_HUD ], szNameiCash ); 
If you still didn't get the point:

In-game right now for me it shows:
PHP Code:
Player Name: %Player Cash: %
Instead of showing
PHP Code:
Player NameDoNii Player Cash123456 
I know %L works for language file but what about .ini files?
__________________

Last edited by edon1337; 04-12-2019 at 12:35.
edon1337 is offline
thEsp
BANNED
Join Date: Aug 2017
Old 04-12-2019 , 08:00   Re: String formatting
Reply With Quote #2

I've had actually the same problem, format the string, or just replace values.
thEsp is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-12-2019 , 08:08   Re: String formatting
Reply With Quote #3

Quote:
Originally Posted by thEsp View Post
I've had actually the same problem, format the string, or just replace values.
Formatting it didn't work, what do you mean by 'replace values'?
__________________
edon1337 is offline
thEsp
BANNED
Join Date: Aug 2017
Old 04-12-2019 , 08:17   Re: String formatting
Reply With Quote #4

Quote:
Originally Posted by edon1337 View Post
Formatting it didn't work, what do you mean by 'replace values'?
Replacing %s/%d/%f or words with any value you need. Idk if I'm correct but also you could try parsing (reading) the content,then copy it into a string and format() it.
thEsp is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-12-2019 , 08:22   Re: String formatting
Reply With Quote #5

Quote:
Originally Posted by thEsp View Post
Replacing %s/%d/%f or words with any value you need. Idk if I'm correct but also you could try parsing (reading) the content,then copy it into a string and format() it.
I'm sorry but I still don't get what you're trying to say, how am I supposed to replace the % symbols when I don't know what I'm going to replace it with (since the text in the .ini can always be changed).

Here is my .ini file:
PHP Code:
ZOMBIE_MAIN_HUD  "| ** Server Name ** |^n| ** Player Name: %s ** |^n| ** Health: %d ** |^n| ** Class: %s ** |^n| ** Level: %s ** |^n| ** XP: %d/%d ** |^n| ** Rank: %s ** |^n| ** Points: %d ** |" 
Here is the part where the HUD is displayed:
PHP Code:
public OnFunctionid )
{        
            new 
szFormat256 ];
            
formatexszFormatcharsmaxszFormat ), "%s"eDataZOMBIE_MAIN_HUD ], szNameiHealthszZombieClassszLevelg_iPlayerXPid ], iLevel == g_iMaxLevels ArrayGetCellg_aRankXPg_iPlayerLevelid ] ) : ArrayGetCellg_aRankXP, ( g_iPlayerLevelid ] + ) ), szRankg_iPlayerPointsid ]
            
            
ShowSyncHudMsgidg_iSyncHud"%s"szFormat ); 
__________________

Last edited by edon1337; 04-12-2019 at 08:24.
edon1337 is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 04-12-2019 , 08:28   Re: String formatting
Reply With Quote #6

https://gist.github.com/rsKliPPy/965270db41f16503770d
The closest I remember
__________________
Relaxing is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-12-2019 , 11:18   Re: String formatting
Reply With Quote #7

Maybe the way you're formating it when you're reading the .ini file is "wrong". Not sure if that's what i'm going to say has any sense, but something may be wrong with formatex(), so try that:

PHP Code:
public OnFunction(id)
{        
    
ShowSyncHudMsg
    
(
        
id,
        
g_iSyncHud
        
eData[ZOMBIE_MAIN_HUD], 
        
szName
        
iHealth
        
szZombieClass
        
szLevel
        
g_iPlayerXP[id], 
        (
iLevel == g_iMaxLevels) ? ArrayGetCell(g_aRankXPg_iPlayerLevel[id]) : ArrayGetCell(g_aRankXP, (g_iPlayerLevel[id] + 1)), 
        
szRank
        
g_iPlayerPoints[id]
    ) 

__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 04-12-2019 at 11:19.
EFFx is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-12-2019 , 12:08   Re: String formatting
Reply With Quote #8

Quote:
Originally Posted by EFFx View Post
Maybe the way you're formating it when you're reading the .ini file is "wrong". Not sure if that's what i'm going to say has any sense, but something may be wrong with formatex(), so try that:

PHP Code:
public OnFunction(id)
{        
    
ShowSyncHudMsg
    
(
        
id,
        
g_iSyncHud
        
eData[ZOMBIE_MAIN_HUD], 
        
szName
        
iHealth
        
szZombieClass
        
szLevel
        
g_iPlayerXP[id], 
        (
iLevel == g_iMaxLevels) ? ArrayGetCell(g_aRankXPg_iPlayerLevel[id]) : ArrayGetCell(g_aRankXP, (g_iPlayerLevel[id] + 1)), 
        
szRank
        
g_iPlayerPoints[id]
    ) 

I somehow managed it to recognize the symbols and make them functional, maybe your way did it or I changed something that was stopping it from working, thank you anyways.
The last issue is that it doesn't recognize ^n as functional, ^n should make a new line but instead it's just showing ^n as a text.

EDIT: I found this, basically the same as my problem https://forums.alliedmods.net/showthread.php?t=139530
But oh boy, they really complicated it so much, I don't get what Exolent and fysiks tried to say.

EDIT2: Nevermind, fixed it, figured out what they meant by replacing ^^n with ^n.
__________________

Last edited by edon1337; 04-12-2019 at 12:36.
edon1337 is offline
thEsp
BANNED
Join Date: Aug 2017
Old 04-12-2019 , 12:34   Re: String formatting
Reply With Quote #9

Oh yes, you can't replace ^n with anything neither, that's awkward :@
thEsp is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-12-2019 , 12:36   Re: String formatting
Reply With Quote #10

Quote:
Originally Posted by thEsp View Post
Oh yes, you can't replace ^n with anything neither, that's awkward :@
What do you mean by 'replace' and 'anything'?
^n has it's own function, breaking lines.
__________________
edon1337 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 08:43.


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