Raised This Month: $ Target: $400
 0% 

Multilingual text


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Atov
Junior Member
Join Date: Jan 2012
Old 01-22-2012 , 14:07   Multilingual text
Reply With Quote #1

I need the plugin below edited like this:

If the player's language is en (English), then load text from the default file: advertisements.ini, Else if player's language is de (German), then load text from a file called: advertisements_de.ini

But maybe it's possible to load from one file?

Code:
#include <amxmodx>
#include <amxmisc>
 
#define PLUGIN "Easy Advertiser"
#define VERSION "1.3.1"
#define AUTHOR "Aver"
 
#define MAX_ADS 32
 
new gCvarTime;
new gMsgSayText;
 
new Array:gAdvertisements;
new gAdvertisement;
 
public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR);
    
    gCvarTime = register_cvar("ea_time", "45");
    gMsgSayText = get_user_msgid("SayText");
    
    gAdvertisements = ArrayCreate(192, MAX_ADS);
    
    set_task(10.0, "LoadAdvertisements");
}
 
public LoadAdvertisements()
{
    new file[64];
    
    get_configsdir(file, charsmax(file));
    formatex(file, charsmax(file), "%s/easy_advertiser.ini", file);
    
    if(file_exists(file))
    {       
        new fHandle = fopen(file, "rt");
        
        if(!fHandle)
            return;
        
        new szLine[192];
        
        for(new i; i < MAX_ADS && !feof(fHandle); i++)
        {
            fgets(fHandle, szLine, charsmax(szLine));
            
            if(!szLine[0] || szLine[0] == ' ' || szLine[0] == ';')
            {
                i--;
                continue;
            }
            
            ArrayPushString(gAdvertisements, szLine);
        }
        
        set_task(get_pcvar_float(gCvarTime), "ShowAdvertisement");
        
        fclose(fHandle);
    }
    else
        log_amx("Brak pliku 'easy_advertiser.ini' na serwerze");
}
 
public ShowAdvertisement()
{
    if(gAdvertisement >= ArraySize(gAdvertisements))
        gAdvertisement = 0;
    
    new szText[192];
    formatex(szText, charsmax(szText), "%a", ArrayGetStringHandle(gAdvertisements, gAdvertisement));
    
    if(contain(szText, "[team]") != -1 && contain(szText, "[/team]") != -1)
    {
        replace_all(szText, charsmax(szText), "[team]", "^x03");
        replace_all(szText, charsmax(szText), "[/team]", "^x01");
    }
    
    if(contain(szText, "[green]") != -1 && contain(szText, "[/green]") != -1)
    {
        replace_all(szText, charsmax(szText), "[green]", "^x04");
        replace_all(szText, charsmax(szText), "[/green]", "^x01");
    }
    
    new players[32], num;
    get_players(players, num, "ch");
    
    if(contain(szText, "[you]") != -1)
    {
        for(new i; i < num; i++)
        {
            new szTemp[192], szName[32];
            copy(szTemp, charsmax(szTemp), szText);
            get_user_name(players[i], szName, charsmax(szName));
            replace_all(szTemp, charsmax(szTemp), "[you]", szName);
            message_begin(MSG_ONE, gMsgSayText, {0,0,0}, players[i]);
            write_byte(players[i]);
            write_string(szTemp);
            message_end();
        }
    }
    else
    {
        for(new i; i < num; i++)
        {
            message_begin(MSG_ONE, gMsgSayText, {0,0,0}, players[i]);
            write_byte(players[i]);
            write_string(szText);
            message_end();
        }
    }
    
    gAdvertisement++;
    set_task(get_pcvar_float(gCvarTime), "ShowAdvertisement");
}



Last edited by Atov; 01-22-2012 at 14:10.
Atov is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-22-2012 , 14:49   Re: Multilingual text
Reply With Quote #2

Make a ML file like normal plugins that is like this:
Code:
[en]
MESSAGE_ONE = This is an English message.
MESSAGE_TWO = This is another English message.

[<other language>]
MESSAGE_ONE = <Message in other language>
MESSAGE_TWO = <Message in other language>

[<other language>]
MESSAGE_ONE = <Message in other language>
MESSAGE_TWO = <Message in other language>

...
You will need to register this ML file in your plugin.

Then have your advertisements.ini select which messages you want:
Code:
MESSAGE_ONE
MESSAGE_TWO
When you are ready to show the advertisement, format it as ML line using the player's id to convert to their language.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-22-2012 , 15:00   Re: Multilingual text
Reply With Quote #3

For more detailed info: http://wiki.amxmodx.org/Advanced_Scr...ingual_Support
__________________
fysiks is offline
Atov
Junior Member
Join Date: Jan 2012
Old 01-23-2012 , 08:23   Re: Multilingual text
Reply With Quote #4

Thanks Exolent and Fysiks.
Atov 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 10:09.


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