AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved String formatting (https://forums.alliedmods.net/showthread.php?t=315521)

edon1337 04-12-2019 06:55

String formatting
 
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?

thEsp 04-12-2019 08:00

Re: String formatting
 
I've had actually the same problem, format the string, or just replace values.

edon1337 04-12-2019 08:08

Re: String formatting
 
Quote:

Originally Posted by thEsp (Post 2647185)
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'?

thEsp 04-12-2019 08:17

Re: String formatting
 
Quote:

Originally Posted by edon1337 (Post 2647187)
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.

edon1337 04-12-2019 08:22

Re: String formatting
 
Quote:

Originally Posted by thEsp (Post 2647188)
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 ); 


Relaxing 04-12-2019 08:28

Re: String formatting
 
https://gist.github.com/rsKliPPy/965270db41f16503770d
The closest I remember

EFFx 04-12-2019 11:18

Re: String formatting
 
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]
    ) 



edon1337 04-12-2019 12:08

Re: String formatting
 
Quote:

Originally Posted by EFFx (Post 2647210)
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.

thEsp 04-12-2019 12:34

Re: String formatting
 
Oh yes, you can't replace ^n with anything neither, that's awkward :@

edon1337 04-12-2019 12:36

Re: String formatting
 
Quote:

Originally Posted by thEsp (Post 2647224)
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.


All times are GMT -4. The time now is 13:41.

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