/** * @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[] format, any ...) { char buffer[192]; SetGlobalTransTarget(iClient); VFormat(buffer, sizeof(buffer), format, 3); 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[] format, any ...) { char buffer[192]; SetGlobalTransTarget(iClient); VFormat(buffer, sizeof(buffer), format, 3); ReplaceColor(buffer, sizeof(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[] format, any ...) { char buffer[192]; for( int i = 1; i <= MaxClients; i++ ) { if( IsClientInGame(i) && !IsFakeClient(i) ) { SetGlobalTransTarget(i); VFormat(buffer, sizeof(buffer), format, 2); ReplaceColor(buffer, sizeof(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[] format, any ...) { char buffer[192]; for( int i = 1; i <= MaxClients; i++ ) { if( IsClientInGame(i) && !IsFakeClient(i) ) { SetGlobalTransTarget(i); VFormat(buffer, sizeof(buffer), format, 2); PrintHintText(i, buffer); } } }
/** * @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[] format, any ...) { char buffer[192]; for( int i = 1; i <= MaxClients; i++ ) { if( IsClientInGame(i) && !IsFakeClient(i) ) { SetGlobalTransTarget(i); VFormat(buffer, sizeof(buffer), format, 2); PrintCenterText(i, buffer); } } }
/** * @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[] message, int maxLen, int team = 0) { ReplaceString(message, maxLen, "{normal}", "\x01", false); ReplaceString(message, maxLen, "{default}", "\x01", false); ReplaceString(message, maxLen, "{white}", "\x01", false); ReplaceString(message, maxLen, "{darkred}", "\x02", false); switch(team) { case 3 : ReplaceString(message, maxLen, "{teamcolor}", "\x0B", false); case 2 : ReplaceString(message, maxLen, "{teamcolor}", "\x05", false); default: ReplaceString(message, maxLen, "{teamcolor}", "\x01", false); } ReplaceString(message, maxLen, "{pink}", "\x03", false); ReplaceString(message, maxLen, "{green}", "\x04", false); ReplaceString(message, maxLen, "{highlight}", "\x04", false); ReplaceString(message, maxLen, "{yellow}", "\x05", false); ReplaceString(message, maxLen, "{lightgreen}", "\x05", false); ReplaceString(message, maxLen, "{lime}", "\x06", false); ReplaceString(message, maxLen, "{lightred}", "\x07", false); ReplaceString(message, maxLen, "{red}", "\x07", false); ReplaceString(message, maxLen, "{gray}", "\x08", false); ReplaceString(message, maxLen, "{grey}", "\x08", false); ReplaceString(message, maxLen, "{olive}", "\x09", false); ReplaceString(message, maxLen, "{orange}", "\x10", false); ReplaceString(message, maxLen, "{silver}", "\x0A", false); ReplaceString(message, maxLen, "{lightblue}", "\x0B", false); ReplaceString(message, maxLen, "{blue}", "\x0C", false); ReplaceString(message, maxLen, "{purple}", "\x0E", false); ReplaceString(message, maxLen, "{darkorange}", "\x0F", false); }
For Left4dead only
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[] format, any ...) { char buffer[192]; SetGlobalTransTarget(iClient); VFormat(buffer, sizeof(buffer), format, 3); 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[] format, any ...) { char buffer[192]; SetGlobalTransTarget(iClient); VFormat(buffer, sizeof(buffer), format, 3); ReplaceColor(buffer, sizeof(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[] format, any ...) { char buffer[192]; for( int i = 1; i <= MaxClients; i++ ) { if( IsClientInGame(i) && !IsFakeClient(i) ) { SetGlobalTransTarget(i); VFormat(buffer, sizeof(buffer), format, 2); ReplaceColor(buffer, sizeof(buffer)); PrintToChat(i, "\x01%s", buffer); } } }
/** * @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). * @no return */ stock void ReplaceColor(char[] message, int maxLen) { ReplaceString(message, maxLen, "{white}", "\x01", false); ReplaceString(message, maxLen, "{cyan}", "\x03", false); ReplaceString(message, maxLen, "{orange}", "\x04", false); ReplaceString(message, maxLen, "{green}", "\x05", false); }
/** * @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[] format, any ...) { char buffer[192]; for( int i = 1; i <= MaxClients; i++ ) { if( IsClientInGame(i) && !IsFakeClient(i) ) { SetGlobalTransTarget(i); VFormat(buffer, sizeof(buffer), format, 2); PrintHintText(i, buffer); } } }
/** * @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[] format, any ...) { char buffer[192]; for( int i = 1; i <= MaxClients; i++ ) { if( IsClientInGame(i) && !IsFakeClient(i) ) { SetGlobalTransTarget(i); VFormat(buffer, sizeof(buffer), format, 2); PrintCenterText(i, buffer); } } }
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 client, int args) { char sUser[64]; GetClientName(client, sUser, sizeof(sUser));