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

Colors in translation file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-09-2019 , 13:42   Colors in translation file
Reply With Quote #1

By request.

Stock:

PHP Code:
/**
*   @note Used for in-line string translation.
*
*   @param  iClient     Client Index, translation is apllied to.
*   @param  format      String formatting rules. By default, you should pass at least "%t" specifier.
*   @param  ...            Variable number of format parameters.
*   @return char[192]    Resulting string. Note: output buffer is hardly limited.
*/
stock char[] Translate(int iClient, const char[] formatany ...)
{
    
char buffer[192];
    
SetGlobalTransTarget(iClient);
    
VFormat(buffersizeof(buffer), format3);
    return 
buffer;
}

/**
*   @note Prints a message to a specific client in the chat area. Supports named colors in translation file.
*
*   @param  iClient     Client Index.
*   @param  format        Formatting rules.
*   @param  ...            Variable number of format parameters.
*   @no return
*/
stock void CPrintToChat(int iClient, const char[] formatany ...)
{
    
char buffer[192];
    
SetGlobalTransTarget(iClient);
    
VFormat(buffersizeof(buffer), format3);
    
ReplaceColor(buffersizeof(buffer));
    
PrintToChat(iClient"\x01%s"buffer);
}

/**
*   @note Prints a message to all clients in the chat area. Supports named colors in translation file.
*
*   @param  format        Formatting rules.
*   @param  ...            Variable number of format parameters.
*   @no return
*/
stock void CPrintToChatAll(const char[] formatany ...)
{
    
char buffer[192];
    for( 
int i 1<= MaxClientsi++ )
    {
        if( 
IsClientInGame(i) && !IsFakeClient(i) )
        {
            
SetGlobalTransTarget(i);
            
VFormat(buffersizeof(buffer), format2);
            
ReplaceColor(buffersizeof(buffer));
            
PrintToChat(i"\x01%s"buffer);
        }
    }
}

/**
*   @note Prints a hint message to all clients. Supports individual string translation for each client.
*
*   @param  format        Formatting rules.
*   @param  ...            Variable number of format parameters.
*   @no return
*/
stock void CPrintHintTextToAll(const char[] formatany ...)
{
    
char buffer[192];
    for( 
int i 1<= MaxClientsi++ )
    {
        if( 
IsClientInGame(i) && !IsFakeClient(i) )
        {
            
SetGlobalTransTarget(i);
            
VFormat(buffersizeof(buffer), format2);
            
PrintHintText(ibuffer);
        }
    }
}

/**
*   @note Prints a center screen message to all clients. Supports individual string translation for each client.
*
*   @param  format        Formatting rules.
*   @param  ...            Variable number of format parameters.
*   @no return
*/
stock void CPrintCenterTextAll(const char[] formatany ...)
{
    
char buffer[192];
    for( 
int i 1<= MaxClientsi++ )
    {
        if( 
IsClientInGame(i) && !IsFakeClient(i) )
        {
            
SetGlobalTransTarget(i);
            
VFormat(buffersizeof(buffer), format2);
            
PrintCenterText(ibuffer);
        }
    }
}

/**
*   @note Converts named color to control character. Used internally by string translation functions.
*
*   @param  char[]        Input/Output string for convertion.
*   @param  maxLen        Maximum length of string buffer (includes NULL terminator).
*   @param  team         Team number to replace {teamcolor} with appropriate color.
*   @no return
*/
void ReplaceColor(char[] messageint maxLenint team 0)
{
    
ReplaceString(messagemaxLen"{normal}""\x01"false);
    
ReplaceString(messagemaxLen"{default}""\x01"false);
    
ReplaceString(messagemaxLen"{white}""\x01"false);
    
ReplaceString(messagemaxLen"{darkred}""\x02"false);
    switch(
team)
    {
        case 
ReplaceString(messagemaxLen"{teamcolor}""\x0B"false);
        case 
ReplaceString(messagemaxLen"{teamcolor}""\x05"false);
        default: 
ReplaceString(messagemaxLen"{teamcolor}""\x01"false);
    }
    
ReplaceString(messagemaxLen"{pink}""\x03"false);
    
ReplaceString(messagemaxLen"{green}""\x04"false);
    
ReplaceString(messagemaxLen"{highlight}""\x04"false);
    
ReplaceString(messagemaxLen"{yellow}""\x05"false);
    
ReplaceString(messagemaxLen"{lightgreen}""\x05"false);
    
ReplaceString(messagemaxLen"{lime}""\x06"false);
    
ReplaceString(messagemaxLen"{lightred}""\x07"false);
    
ReplaceString(messagemaxLen"{red}""\x07"false);
    
ReplaceString(messagemaxLen"{gray}""\x08"false);
    
ReplaceString(messagemaxLen"{grey}""\x08"false);
    
ReplaceString(messagemaxLen"{olive}""\x09"false);
    
ReplaceString(messagemaxLen"{orange}""\x10"false);
    
ReplaceString(messagemaxLen"{silver}""\x0A"false);
    
ReplaceString(messagemaxLen"{lightblue}""\x0B"false);
    
ReplaceString(messagemaxLen"{blue}""\x0C"false);
    
ReplaceString(messagemaxLen"{purple}""\x0E"false);
    
ReplaceString(messagemaxLen"{darkorange}""\x0F"false);

For Left4dead only


Using:
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

public void OnPluginStart()
{
    
LoadTranslations("test.phrases");
    
    
RegConsoleCmd("sm_test"CmdTest);
}

public 
Action CmdTest(int clientint args)
{
    
char sUser[64];
    
GetClientName(clientsUsersizeof(sUser));
    
    
CPrintToChat(client"%t""alias-client"sUser);
    
CPrintToChatAll("%t""alias-all");
    
    return 
Plugin_Handled;

Translation file example:
addons/sourcemod/translations/test.phrases.txt
Code:
/*
	Following named colors are supported:
	 - {white}	(use instead of \x01 )
	 - {cyan}	(use instead of \x03 )
	 - {orange}	(use instead of \x04 )
	 - {green}	(use instead of \x05 )
*/

"Phrases"
{
	"alias-client"
	{
		"#format"	"{1:s}"
		"ru"		"{cyan}Привет {orange}{1}!"
		"en"		"{cyan}Hello {orange}{1}!"
	}
	"alias-all"
	{
		"ru"		"{cyan}Привет всем!"
		"en"		"{cyan}Hello everybody!"
	}
}
ReplaceColor() is a partial copy-paste (I don't remember credits, sorry).
Attached Thumbnails
Click image for larger version

Name:	num_colors.png
Views:	267
Size:	13.9 KB
ID:	174351  
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 05-06-2019 at 08:33. Reason: added new stocks and description
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 05-06-2019 , 08:29   Re: Colors in translation file
Reply With Quote #2

Appended with:

CPrintCenterTextAll()
CPrintHintTextToAll()
Translate()

and description.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Reply


Thread Tools
Display Modes

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 07:15.


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