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

Get user lang


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LithuanianJack
Senior Member
Join Date: Nov 2013
Location: Vilnius, Lithuania
Old 03-22-2019 , 03:56   Get user lang
Reply With Quote #1

Hello. I got stuck in the line 19 ("array must be indexed"). What's wrong in this line?

PHP Code:
if((lang(id)=="en")) 
PHP Code:
#include <amxmodx>

#define PLUGIN "Get user lang"
#define VERSION "1.0"
#define AUTHOR "LithuanianJack"

const LANG_SIZE 3;

public 
plugin_init() {

       
register_concmd("say /getlang""lang"ADMIN_ALL);
       
register_plugin(PLUGINVERSIONAUTHOR);
}

public 
lang(id) {
        new 
szCurLangLANG_SIZE ];
        
get_user_infoid"lang"szCurLangcharsmaxszCurLang ) );
        
        if((
lang(id)=="en"))
        {
            
client_print_coloridprint_team_red"^4Lang en");
        } else {
            
client_print_coloridprint_team_red"^3Lang other");
        }
}

stock ChatColor(const id, const szMessage[], any:...)
{
    static 
szMsg[190], IdMsg;
    
vformat(szMsgcharsmax(szMsg), szMessage3);
    
    if(!
IdMsgIdMsg get_user_msgid("SayText");
    
    
message_begin(MSG_ONEIdMsg, .player id);
    
write_byte(id);
    
write_string(szMsg);
    
message_end();


Last edited by LithuanianJack; 03-22-2019 at 03:57.
LithuanianJack is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-22-2019 , 10:11   Re: Get user lang
Reply With Quote #2

Your code is not correct.

Code:
public lang(id) {         new szCurLang[ LANG_SIZE ];         get_user_info( id, "lang", szCurLang, charsmax( szCurLang ) );                 if((lang(id)=="en"))         {             client_print_color( id, print_team_red, "^4Lang en");         } else {             client_print_color( id, print_team_red, "^3Lang other");         } }

This part of the code would cause a infinity loop, so:



Code:
public lang(id) {         new szCurLang[ LANG_SIZE ];         get_user_info( id, "lang", szCurLang, charsmax( szCurLang ) );                 if(equali(szCurLang, "en"))         {             client_print_color( id, print_team_red, "^4Lang en");         } else {             client_print_color( id, print_team_red, "^3Lang other");         } }

Besides, why do you just not use the dictionary functionality of the amxmodx? Something like this:

Code:
#include <amxmodx> #define PLUGIN "Plugin" #define VERSION "Version" #define AUTHOR "Author" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     // Language file, ${amxx_datadir}/lang     register_dictionary("filename.txt");     /* filename.txt:         [en]     TRANSLATION_KEY = Whatever English     [ru]         TRANSLATION_KEY = Whatever Russian     */     register_clcmd("say whatever", "whatever") } public whatever(id) {         ChatColor(id, "%L", id, "TRANSLATION_KEY"); } stock ChatColor(const id, const szMessage[], any:...) {     static szMsg[190], IdMsg;     vformat(szMsg, charsmax(szMsg), szMessage, 3);         if(!IdMsg) IdMsg = get_user_msgid("SayText");         message_begin(MSG_ONE, IdMsg, .player = id);     write_byte(id);     write_string(szMsg);     message_end(); }
__________________








CrazY. 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 21:33.


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