shel писал(а): Юлия, меня кое кто просил вас не трогать, поэтому ваш пост я опускаю.
Модераторы: Subb98, liFe iS GoOD
new bool:g_bLang[MAX_PLAYERS + 1];
if(g_bLang[id])
{
//
}
else
{
//
}
public client_connect(id) g_bLang[id] = false
#include < amxmodx >
#include < amxmisc >
#include < hamsandwich >
// put a "//" before the line to instantly show menu on spawn
#define SPAWN_WAIT_TIME 6.0
// put a "//" before the line below to always ask every first spawn
#define DONT_ASK_AGAIN
const LANG_SIZE = 3;
new bool:g_bFirstSpawn[ 33 ];
new pCvar_Langs;
new Array:g_aLangs;
new Trie:g_tArrayIndex;
new g_iTotalLangs;
#if defined DONT_ASK_AGAIN
#include < nvault >
new g_hVault;
#endif
public plugin_init( )
{
register_plugin( "Custom Lang Menu", "0.0.1", "Exolent" );
register_dictionary( "multilingual.txt" );
register_dictionary( "languages.txt" );
register_dictionary( "custom_lang_menu.txt" );
register_clcmd( "say /lang", "ShowLangMenu" );
RegisterHam( Ham_Spawn, "player", "FwdPlayerSpawnPost", 1 );
pCvar_Langs = register_cvar( "amx_menu_langs", "en,lt" );
g_aLangs = ArrayCreate( LANG_SIZE );
g_tArrayIndex = TrieCreate( );
#if defined DONT_ASK_AGAIN
g_hVault = nvault_open( "player_lang" );
#endif
}
public plugin_cfg( )
{
LoadLangs( );
}
public plugin_end( )
{
ArrayDestroy( g_aLangs );
TrieDestroy( g_tArrayIndex );
#if defined DONT_ASK_AGAIN
nvault_close( g_hVault );
#endif
}
#if defined DONT_ASK_AGAIN
public client_authorized( iPlayer )
{
new szAuthid[ 35 ];
get_user_authid( iPlayer, szAuthid, charsmax( szAuthid ) );
new szLang[ LANG_SIZE ];
if( !nvault_get( g_hVault, szAuthid, szLang, charsmax( szLang ) ) )
{
g_bFirstSpawn[ iPlayer ] = true;
}
else
{
set_user_info( iPlayer, "lang", szLang );
}
}
#else
public client_connect( iPlayer )
{
g_bFirstSpawn[ iPlayer ] = true;
}
#endif
public client_disconnect( iPlayer )
{
g_bFirstSpawn[ iPlayer ] = false;
}
public FwdPlayerSpawnPost( iPlayer )
{
if( is_user_alive( iPlayer )
&& g_bFirstSpawn[ iPlayer ] )
{
g_bFirstSpawn[ iPlayer ] = false;
#if defined SPAWN_WAIT_TIME
set_task( SPAWN_WAIT_TIME, "ShowLangMenu", iPlayer );
#else
ShowLangMenu( iPlayer );
#endif
}
}
public ShowLangMenu( iPlayer )
{
if( !g_iTotalLangs )
{
client_cmd( iPlayer, "amx_langmenu" );
}
else
{
new szLang[ LANG_SIZE ];
get_user_info( iPlayer, "lang", szLang, charsmax( szLang ) );
new szTitle[ 96 ];
new iLen = formatex( szTitle, charsmax( szTitle ), "%L:", iPlayer, "CHOOSE_YOUR_LANG" );
if( TrieKeyExists( g_tArrayIndex, szLang ) )
{
iLen += formatex( szTitle[ iLen ], charsmax( szTitle ) - iLen, "^n%L: \w%L", iPlayer, "CURRENT", szLang, "LANG_NAME" );
}
new hMenu = menu_create( szTitle, "MenuLang" );
new szItem[ 64 ];
for( new i = 0; i < g_iTotalLangs; i++ )
{
ArrayGetString( g_aLangs, i, szLang, charsmax( szLang ) );
formatex( szItem, charsmax( szItem ), "%L", szLang, "LANG_NAME" );
menu_additem( hMenu, szItem, szLang );
}
formatex( szItem, charsmax( szItem ), "\y%L", iPlayer, "OTHER" );
menu_additem( hMenu, szItem, "**" );
menu_display( iPlayer, hMenu );
}
}
public MenuLang( iPlayer, hMenu, iItem )
{
if( iItem == MENU_EXIT )
{
goto exit_menu;
}
new iAccess, szLang[ LANG_SIZE ], hCallback;
menu_item_getinfo( hMenu, iItem, iAccess, szLang, charsmax( szLang ), _, _, hCallback );
if( equal( szLang, "**" ) )
{
client_cmd( iPlayer, "amx_langmenu" );
}
else
{
new szCurLang[ LANG_SIZE ];
get_user_info( iPlayer, "lang", szCurLang, charsmax( szCurLang ) );
new szLangName[ 32 ];
formatex( szLangName, charsmax( szLangName ), "%L", szLang, "LANG_NAME" );
if( !equal( szLang, szCurLang ) )
{
set_user_info( iPlayer, "lang", szLang );
client_print( iPlayer, print_chat, "[AMXX] %L", iPlayer, "SET_LANG_USER", szLangName );
#if defined DONT_ASK_AGAIN
new szAuthid[ 35 ];
get_user_authid( iPlayer, szAuthid, charsmax( szAuthid ) );
nvault_set( g_hVault, szAuthid, szLang );
#endif
}
else
{
client_print( iPlayer, print_chat, "[AMXX] %L", iPlayer, "ALREADY_YOUR_LANG", szLangName );
}
}
exit_menu:
menu_destroy( hMenu );
}
LoadLangs( )
{
new szCvarValue[ 128 ];
get_pcvar_string( pCvar_Langs, szCvarValue, charsmax( szCvarValue ) );
new szLang[ LANG_SIZE ], iPos;
while( ( iPos = contain( szCvarValue, "," ) ) >= 0 )
{
copy( szLang, min( charsmax( szLang ), iPos ), szCvarValue );
copy( szCvarValue, charsmax( szCvarValue ), szCvarValue[ iPos + 1 ] );
if( !TrieKeyExists( g_tArrayIndex, szLang )
&& lang_exists( szLang ) )
{
ArrayPushString( g_aLangs, szLang );
TrieSetCell( g_tArrayIndex, szLang, g_iTotalLangs++ );
}
}
if( !TrieKeyExists( g_tArrayIndex, szCvarValue )
&& lang_exists( szCvarValue ) )
{
ArrayPushString( g_aLangs, szCvarValue );
TrieSetCell( g_tArrayIndex, szCvarValue, g_iTotalLangs++ );
}
}
custom_lang_menu.txt
[en]
CHOOSE_YOUR_LANG = Choose your language
CURRENT = Current
ALREADY_YOUR_LANG = %s is already your language!
OTHER = Other
[ru]
CHOOSE_YOUR_LANG = Выберите ваш язык
CURRENT = Текущий
ALREADY_YOUR_LANG = %s язык активирован!
OTHER = Другой...
Сейчас этот форум просматривают: Google [Bot] и гости: 8