Raised This Month: $32 Target: $400
 8% 

Solved Translations - text with "%"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 08-19-2018 , 17:15   Translations - text with "%"
Reply With Quote #1

Hello,
Code:
Format(format, sizeof format, "%T", "INFORMATION", id, percent)
Code:
	"INFORMATION"
	{
		"#format"	"{1:d}"
		"en" 		"({1} %)"
	}
When I create something like this "%", my text look like that:


(55 )
but i want something like that:
(55 %)

Code:
"en" 		"({1} %%)" -> not work

Last edited by Qes; 08-19-2018 at 18:28.
Qes is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-19-2018 , 17:44   Re: Translations - text with "%"
Reply With Quote #2

I suspect you are double-formatting somewhere (or more, given that %% also didn't work), % shouldn't need escaping in translation files.

Please provide the complete code.
__________________
asherkin is offline
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 08-19-2018 , 17:52   Re: Translations - text with "%"
Reply With Quote #3

Code:
public Action:InfoHUD(Handle:timer, any:id)
{
	if(!IsValidClient(id))
		return Plugin_Continue;

	decl String:format_array[256];

	if(!IsPlayerAlive(id))
	{
		new iSpecMode = GetEntProp(id, Prop_Send, "m_iObserverMode");
		if(iSpecMode == 4 || iSpecMode == 5)
		{
			new iSpectatedClient = GetEntPropEnt(id, Prop_Send, "m_hObserverTarget");
			if(0 < iSpectatedClient <= MaxClients)
			{
				new target = iSpectatedClient;
				new procent = 0

				if(poziom_gracza[target] >= 1)
				{
					new ileMa = doswiadczenie_gracza[target],ilePotrzeba = PobierzDoswiadczeniePoziomu(poziom_gracza[target]),ilePotrzebaBylo = poziom_gracza[target]-1 >= 0 ? PobierzDoswiadczeniePoziomu(poziom_gracza[target]-1) : 0;
					new Float:fProcent = 0.0;
					fProcent = (float((ileMa - ilePotrzebaBylo)) / float((ilePotrzeba - ilePotrzebaBylo))) * 100.0;
					procent = RoundFloat(fProcent);
				}

				Format(format_array, sizeof format_array, "%T", "HUD_INFORMATION", id, nazwy_klas[klasa_gracza[iSpectatedClient]], nazwy_perkow[perk_gracza[iSpectatedClient]], poziom_gracza[iSpectatedClient], procent, cod_get_user_coins(iSpectatedClient));
				//PrintHintText(id, "%s\nLVL %d [%d %% XP]\n%s", nazwy_klas[klasa_gracza[iSpectatedClient]], poziom_gracza[iSpectatedClient], procent, nazwy_perkow[perk_gracza[iSpectatedClient]]);
			}
		}
	}
	else
	{
		new procent = 0;

		if(poziom_gracza[id] >= 1)
		{
			new ileMa = doswiadczenie_gracza[id],ilePotrzeba = PobierzDoswiadczeniePoziomu(poziom_gracza[id]),ilePotrzebaBylo = poziom_gracza[id]-1 >= 0 ? PobierzDoswiadczeniePoziomu(poziom_gracza[id]-1) : 0;
			new Float:fProcent = 0.0;
			fProcent = (float((ileMa - ilePotrzebaBylo)) / float((ilePotrzeba - ilePotrzebaBylo))) * 100.0;
			procent = RoundFloat(fProcent);
		}
		Format(format_array, sizeof format_array, "%T", "HUD_INFORMATION", id, nazwy_klas[klasa_gracza[id]], nazwy_perkow[perk_gracza[id]], poziom_gracza[id], procent, cod_get_user_coins(id));
	}

	SetHudTextParams(0.4, 0.08, 1.2, 0, 255, 0, 255, 0, 0.0, 0.0, 0.0);
	ShowHudText(id, 5, format_array);

	return Plugin_Continue;
}
and
Code:
public OnClientPutInServer(id)
{
	Handle_Tasks_Client[id] = CreateTimer(1.0, InfoHUD, id, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
Qes is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-19-2018 , 18:15   Re: Translations - text with "%"
Reply With Quote #4

ShowHudText takes a format param, change it to:
Code:
ShowHudText(id, 5, "%s", format_array);
Unrelated to the issue, but you should also not pass client indexes through async operations like timers, use userids instead.
__________________

Last edited by asherkin; 08-19-2018 at 18:16.
asherkin is offline
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 08-19-2018 , 18:28   Re: Translations - text with "%"
Reply With Quote #5

Ok, thank you
Quote:
Unrelated to the issue, but you should also not pass client indexes through async operations like timers, use userids instead.
Ok, thank you for this tip
Qes is offline
dustinandband
Senior Member
Join Date: May 2015
Old 08-29-2018 , 20:36   Re: Translations - text with "%"
Reply With Quote #6

Quote:
Originally Posted by asherkin View Post
ShowHudText takes a format param, change it to:
Code:
ShowHudText(id, 5, "%s", format_array);
Unrelated to the issue, but you should also not pass client indexes through async operations like timers, use userids instead.
What's the reason for that? Asking because I see many plugins pass the userid then turn it back into the client index.
dustinandband is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-29-2018 , 23:26   Re: Translations - text with "%"
Reply With Quote #7

Quote:
Originally Posted by dustinandband View Post
What's the reason for that? Asking because I see many plugins pass the userid then turn it back into the client index.
The reason is because a client index isn't a unique identifier for the client. A client could leave and spew invalid client errors, or a client could leave and a new one would join taking the same index (causing whatever operation you initiated to happen on the wrong client).

Converting to userid and back is a safe way to prevent this due to the fact that you'd have to GetClientOfUserId (which returns 0 if the userid became/is invalid)
headline 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 17:08.


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