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

Solved vformat() ignoring user language on AMXX 183 build 5116


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 05-14-2017 , 13:53   vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #1

I am trying to create a color print stock which uses the AMXX 183 `client_print_color()` function,
when I am using the AMXX 183 compiler. And the AMXX 182 color chat method when I am using the
AMXX 182 compiler.

This is the code I got so far on the Galileo plugin:
Spoiler


However when I am on the AMXX 183 compiler, the message is received on my function is passing
through `vformat()` therefore it is not correctly getting the user language, but the server language instead of.

For AMXX 182 my `color_print()` function is using this other method which is correctly working, for both
AMXX 182 and 183 build 5116:
Spoiler


Resulting on both message correctly in the user language:




However given this minimal code for AMXX 183:
Code:
#include <amxmodx> public plugin_init() {     register_plugin( "New Plug-In", "1.0", "Author" )     register_clcmd( "say test", "test" ) } public test() {     color_print( "Message: ^4%L", LANG_PLAYER, "CMD_MENU" )     client_print_color( 0, print_team_default, "Message: ^4%L", LANG_PLAYER, "CMD_MENU" ); } stock color_print( const lang_formatting[], any:... ) {     server_print( "I AM ENTERING ON color_print() lang_formatting: %s...", lang_formatting )     new formatted_message[ 190 ];     vformat( formatted_message, charsmax( formatted_message ), lang_formatting, 2 );     client_print_color( 0, print_team_default, "Color: %s", formatted_message );     server_print( "( color_print ) [out] Chat printed: `%s`", formatted_message ) }

I got in game while calling the `say test` command:



The one passing through `vformat()` is not getting correctly the player language.

It it a bug on the AMXX 183 build 5116 or the only way is to only use the AMXX 182 color print
method for both AMXX 183 and 182 compilers?
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 05-14-2017 at 13:55.
addons_zz is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 05-14-2017 , 13:57   Re: vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #2

I just noticed the problem, I cannot use `vformat()` to send a message to each players using `LANG_PLAYER`.
Because I am creating one string which must to be in only 1 language, however to show it to all players I neeed
one different copy for each server's players.

Therefore the only way is to always use the AMXX 182 method for compiling for both compilers.
Unless maybe if I use something like How to repass variadic arguments (ellipsis) on Amx Mod X Pawn?
or create a macro as I tried on this other thread: Using print color function with 'LANG_PLAYER' on Amx Mod X '1.8.2' or superior

#Fail
, but I had no success it writing it.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 05-25-2017 at 16:57.
addons_zz is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-14-2017 , 14:03   Re: vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #3

You should use SetGlobalTransTarget. You can also emulate it on AMXX < 1.8.3. See my ChatPrint code https://github.com/WPMGPRoSToTeMa/Ch...int.inc#L7-L17.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 05-15-2017 , 22:02   Re: vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #4

I do not how it could help, but I fixed it creating this macro:
Code:
#if AMXX_VERSION_NUM < 183     #define COLOR_CHAT(%1) hidden_color_print( %1 );     new g_user_msgid; #else     #define COLOR_CHAT(%1) client_print_color( %1 ); #endif
And defining the header of the `color_print()` function as:
Code:
stock hidden_color_print( const player_id, not_used, const lang_formatting[], any:... ) {     // Added to remove the not used warning     not_used = not_used  ? 0 : 0;

Now to use it is just to call the macro as:
Code:
COLOR_CHAT( 0, 0, "%L", LANG_PLAYER, "GAL_WINNER_NO_ONE_VOTED", g_nextMapName )
Or:
Code:
COLOR_CHAT( 0, print_team_default, "%L", LANG_PLAYER, "GAL_WINNER_NO_ONE_VOTED", g_nextMapName )

And depending on whether you use the AMXX 183 compiler or AMXX 182 compiler, it will call the proper natives.
The only downside is the redundant second parameter on the call to `COLOR_CHAT( player_id, redundant_data, ... )`.

This is a full example:
Spoiler
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 05-19-2017 at 12:18.
addons_zz is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-16-2017 , 02:09   Re: vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #5

Quote:
Originally Posted by addons_zz View Post
I do not how it could help
After SetGlobalTransTarget call, vformat will "eat" all LANG_PLAYER as player id specified in SetGlobalTransTarget.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 05-16-2017 , 13:19   Re: vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #6

Thanks, I understood it. Though my problem is to switch from a stock implementation of and AMXX 183 native `client_print_color` on AMXX 182, and a sigle native call `client_print_color` when the server is using the AMXX 183.

I also noticed on the code above the call `COLOR_CHAT` does not need to be a macro, but can be used as a simple function call replacing:
Code:
#if AMXX_VERSION_NUM < 183     #define COLOR_CHAT(%1) hidden_color_print( %1 );     new g_user_msgid; #else     #define COLOR_CHAT(%1) client_print_color( %1 ); #endif
With:
Code:
#if AMXX_VERSION_NUM < 183     #define color_chat hidden_color_print     new g_user_msgid; #else     #define color_chat client_print_color #endif

Here is an updated example:
Spoiler
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 05-19-2017 at 12:17.
addons_zz is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-16-2017 , 15:56   Re: vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #7

You can use something like this:
Code:
#if defined client_print_color     #define color_chat client_print_color     #endinput #endif
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 05-25-2017 , 16:46   Re: vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #8

I would not use `#endinput` because it is not in a include file, but directly on the main code.

I figured out how to create the macro I was looking for, but I figured it out, it is not possible to also
insert a message prefix, if I am sending the message directly to the AMXX natives as client_print_color().

This is the main code which does the trick:
Code:
/**  * This is holder to allow pass fake "variadic" arguments to the macro COLOR().  *  * @param variadic_args     a variable number of arguments  */ #define CHAT(%1) %1 /**  * Properly switch the colored chat implementation accordantly to the AMXX's compilers version.  */ #if AMXX_VERSION_NUM < 183     /**      * Same as the functions COLOR(CHAT) just bellow, but uses color_print_only() for AMXX 182.      *      * @see <a href="https://www.amxmodx.org/api/amxmodx/client_print">client_print</a>      */     #define COLOR(%1,%2) \     { \         if( IS_COLORED_CHAT_ENABLED() ) \         { \             color_print_only( %1, %2 ); \         } \         else \         { \             client_print( %1, print_chat, %2 ); \         } \     }     new g_user_msgid; #else     /**      * Dynamically switch on runtime the client colored print function supported by the current game      * mod running. This is necessary because the colored print function client_print_color() is      * only supported by a very few game modes. Therefore we cannot know at compile time whether the      * game mod will supported the colored print function client_print_color().      *      * The usage is: COLOR( 0, CHAT( "Message: %d", argument ) )      *      * @param player_id         the player id      * @param variadic_args     a variable number of arguments      *      * @see <a href="https://www.amxmodx.org/api/amxmodx/client_print_color">client_print_color</a>      */     #define COLOR(%1,%2) \     { \         if( IS_COLORED_CHAT_ENABLED() ) \         { \             client_print_color( %1, print_team_default, %2 ); \         } \         else \         { \             client_print( %1, print_chat, %2 ); \         } \     } #endif

This is a full example using it:
Spoiler


__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 05-25-2017 at 16:53.
addons_zz is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-25-2017 , 17:05   Re: vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #9

Please use SetGlobalTransTarget instead of this big loop.
Quote:
Originally Posted by PRoSToTeM@ View Post
You can also emulate it on AMXX < 1.8.3. See my ChatPrint code https://github.com/WPMGPRoSToTeMa/Ch...int.inc#L7-L17.
__________________

Last edited by PRoSToTeM@; 05-25-2017 at 17:06.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 05-25-2017 , 19:00   Re: vformat() ignoring user language on AMXX 183 build 5116
Reply With Quote #10

Looking over your code, your loop seems bigger and involve much more things.
However you seems support other colors mine could not. But for now mine seems fine.

You could do a tutorial explaining your code and why it is better, secure and faster than all the alternatives out there.
May be I am able to analyze your code and do it by myself, however have much things to do.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz 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 15:20.


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