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

[TUT] Using print color function with 'LANG_PLAYER' on Amx Mod X '1.8.2' or superior


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-07-2016 , 12:14   [TUT] Using print color function with 'LANG_PLAYER' on Amx Mod X '1.8.2' or superior
Reply With Quote #1

[Tutorial]
Using print color function with 'LANG_PLAYER' on
Amx Mod X '1.8.2' or superior


Contents' Table

Some ideas to use the color player chat at the AMXX 1.8.2 and a solution came up using these threads:
  1. help with multilang
  2. Multi-Lingual Support
  3. [TUT] Dynamic / Fake Natives
  4. Language System
  5. https://www.amxmodx.org/api/amxmodx/client_print_color

Introduction | go to top

The problem happens because the constant 'LANG_PLAYER' is used to send a message to all players, but when do we use the color print function on Amx Mod X 1.8.2, we have to send that message to every player, then we cannot use the constant 'LANG_PLAYER'. As we need to send the colored text to every player, we need need to use the player_id instead of the constant 'LANG_PLAYER'.

The sad part part about that is, that we cannot create a macro function that easly print colored text to all uses respecting the 'LANG_PLAYER' constant limitation on Amx Mod X '1.8.2'. Latter on, will be show a unsucessful atempt to create a general way to print colored functions on Amx Mod X '1.8.2'.

Here are present 2 new implementations for Amx Mod X '1.8.2' that are compatible simultaniasly with the Amx Mod X '1.8.3' or superior. One implementation is using a remastered ConnorMcLeod code, and another just using preprocessor directives to improve speed. And both implementations are compatible with each other, which means that you can use both at your code. Here you can find the original implementation made by ConnorMcLeod.

If you run this functions on a Game Mod that do not support colored messages, they will be displayed as normal messages without any errors or bad formats.

To this works, we need to register the LANG file dictionary as colored dictionary, then we can use '!t', '!g', and '!y' for colors at the lang file. And this allow you to use '!g for green', '!y for yellow' and '!t for team' color at the colored registred dictionary file and '^1', '^3' and '^4' inside de plugin. To register the dictionary as a colored dictionary, simple call 'register_dictionary_colored' provided here bellow, instead of 'register_dictionary' when you register your LANG dictionary.


Points | go to top
  • If the player id is 0 we need to repeat this code that follow or equivalent every time we need to print a chat color, because this is the implementation based on preprocessor directives. So, if you want to use the optimized way at the Amx Mod X '1.8.2', you have to use the code as follows bellow. If you do not want to use the optimized way, just simply/normally call the function 'color_print' using the 'LANG_PLAYER' constant and do not use this preprocessor based way every time you want to print colored messages to all players.
    Spoiler
  • The way as follows, is a simple call the the function 'color_print' mentioned. With the way presented bellow you do not need to start your LANG file constants with a color, as the calling function already do that using the default color '^1' yellow. You can use this, if you do not want the optimized way on the Amx Mod X '1.8.2', but despite that, this way will be optimized at the Amx Mod X '1.8.3' or superior. This is an example when the player_id is greater than 0:
    Code:
        color_print( player_id, "^1%L %L %L", player_id, "LANG_A", any_variable_used_on_LANG_A )
  • This is an example, when you do not use a LANG file dictionary, and put the colors at the source code:
    Code:
        // Every formatted message must begin with a color.     color_print( player_id, "^1Here is everyting yellow.^3Now it is team color.^4\              Now everything is green and my poor string variable is^1 %s yellow again.", poor_string_variable )

Snippets | go to top

This is when you know that it is just for only one player: (You can use this to show a colored message to all player on Amx Mod X '1.8.2' with player_id as 0 and using LANG_PLAYER instead of player_id, but it will be not optimized. But if you are at the Amx Mod X '1.8.3' or superior, it will be optimized)
Code:
    color_print( player_id, "^1%L", player_id, "MY_LANG_CONSTANT" ) // here, use player_id instead of LANG_PLAYER
This is when you want to put a message to all players: (This is the optimized war for Amx Mod X '1.8.2' or superior)
Spoiler


Global variables and functions needed | go to top
Spoiler


The function 'color_print' | go to top
Spoiler


The function 'register_dictionary_colored' | go to top
Spoiler


Trying to use macros fail | go to top

This is how was tried to create a macro function to let us to just use a simple and normal function call as in the Amx Mod X 1.8.3. But looks like that the key Variadic Macros are not supported on Pawn, because every time it was used, the preprocessor does not recognize/associate the ellipsis arguments during the macro expansion:
Spoiler

That code assumes that every time you call the 'PRINT_COLORED_TEXT()' macro function to display a colored message to all players, you will use the 'LANG_PLAYER_COLORED' constant, instead of the default one 'LANG_PLAYER'.

These sources used to find out that is or impossible or too cumbersome to implement a macro functions to emcapsulate the color function print on the Amx Mod X 1.8.2:
  1. https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
  2. https://en.wikibooks.org/wiki/C_Programming/Preprocessor
  3. http://www.cs.yale.edu/homes/aspnes/pinewiki/C(2f)Macros.html
  4. https://gcc.gnu.org/onlinedocs/cpp/Undefining-and-Redefining-Macros.html
  5. http://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments
  6. http://stackoverflow.com/questions/13122846/align-macro-kernel
__________________
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 15:14. Reason: fixed misspelings
addons_zz is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-07-2016 , 13:11   Re: Using print color function with 'LANG_PLAYER' on Amx Mod X 1.8.2
Reply With Quote #2


A more elaborated failure with macros | go to top
Spoiler


Full Working Example | go to top
Spoiler


# Update 05/2017

I managed to create the macro, but it has the downfall to not allow insert prefixes on the message:
  1. vformat() ignoring user language on AMXX 183 build 5116#postcount=8
__________________
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 17:03. Reason: A more elaborated fail
addons_zz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-07-2016 , 19:34   Re: Using print color function with 'LANG_PLAYER' on Amx Mod X 1.8.2
Reply With Quote #3

If Connor's method is more efficient then you should not post this. It makes it harder for people to find actual good code/tutorials.
__________________
fysiks is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-09-2016 , 09:26   Re: Using print color function with 'LANG_PLAYER' on Amx Mod X 1.8.2
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
If Connor's method is more efficient then you should not post this. It makes it harder for people to find actual good code/tutorials.
I just posted too early i.e., before to finish. Now I finished it, and it is equivalent with more habilites.
__________________
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; 01-09-2016 at 09:27.
addons_zz is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-20-2016 , 06:13   Re: [TUT] Using print color function with 'LANG_PLAYER' on Amx Mod X '1.8.2' or super
Reply With Quote #5

Better use something like this:
PHP Code:
// Hack hack hack
#if !defined SetGlobalTransTarget
    #define SetGlobalTransTarget ChatPrint_SetGlobalTransTarget
       
    
stock ChatPrint_SetGlobalTransTarget(nClientIndex) {
        new 
oldFlags pev(nClientIndexpev_flags);
        
set_pev(nClientIndexpev_flagsFL_FAKECLIENT); // Emulate bot
        
console_cmd(nClientIndex""); // When player is bot this function call only SetDefLang function
        
set_pev(nClientIndexpev_flagsoldFlags); // Restore flags
    
}
#endif 
My ChatPrint function include
__________________

Last edited by PRoSToTeM@; 12-30-2016 at 14:25.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
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 09:06.


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