View Single Post
bboygrun
CHOMP
Join Date: May 2010
Location: France
Old 05-24-2011 , 10:50   Re: Base Builder Shop
#10

Il y a des choses qui servent vraiment à rien du genre :

PHP Code:
stock client_print_color(idiColor=DontChange, const szMsg[], any:...)
{
    
// check if id is different from 0
    
if( id && !is_user_connected(id) )
    {
        return 
0;
    }

    if( 
iColor Grey )
    {
        
iColor DontChange;
    }

    new 
szMessage[192];
    if( 
iColor == DontChange )
    {
        
szMessage[0] = 0x04;
    }
    else
    {
        
szMessage[0] = 0x03;
    }

    new 
iParams numargs();
    
// Specific player code
    
if(id)
    {
        if( 
iParams == )
        {
            
copy(szMessage[1], charsmax(szMessage)-1szMsg);
        }
        else
        {
            
vformat(szMessage[1], charsmax(szMessage)-1szMsg4);
        }

        if( 
iColor )
        {
            new 
szTeam[11]; // store current team so we can restore it
            
get_user_team(idszTeamcharsmax(szTeam));

            
// set id TeamInfo in consequence
            // so SayText msg gonna show the right color
            
Send_TeamInfo(ididg_szTeamName[iColor]);

            
// Send the message
            
Send_SayText(ididszMessage);

            
// restore TeamInfo
            
Send_TeamInfo(ididszTeam);
        }
        else
        {
            
Send_SayText(ididszMessage);
        }
    } 

    
// Send message to all players
    
else
    {
        
// Figure out if at least 1 player is connected
        // so we don't send useless message if not
        // and we gonna use that player as team reference (aka SayText message sender) for color change
        
new iPlayers[32], iNum;
        
get_players(iPlayersiNum"ch");
        if( !
iNum )
        {
            return 
0;
        }

        new 
iFool iPlayers[0];

        new 
iMlNumberij;
        new Array:
aStoreML ArrayCreate();
        if( 
iParams >= // ML can be used
        
{
            for(
j=4j<iParamsj++)
            {
                
// retrieve original param value and check if it's LANG_PLAYER value
                
if( getarg(j) == LANG_PLAYER )
                {
                    
i=0;
                    
// as LANG_PLAYER == -1, check if next parm string is a registered language translation
                    
while( ( szMessage] = getarg1i++ ) ) ) {}
                    if( 
GetLangTransKey(szMessage) != TransKey_Bad )
                    {
                        
// Store that arg as LANG_PLAYER so we can alter it later
                        
ArrayPushCell(aStoreMLj++);

                        
// Update ML array saire so we'll know 1st if ML is used,
                        // 2nd how many args we have to alterate
                        
iMlNumber++;
                    }
                }
            }
        }

        
// If arraysize == 0, ML is not used
        // we can only send 1 MSG_BROADCAST message
        
if( !iMlNumber )
        {
            if( 
iParams == )
            {
                
copy(szMessage[1], charsmax(szMessage)-1szMsg);
            }
            else
            {
                
vformat(szMessage[1], charsmax(szMessage)-1szMsg4);
            }

            if( 
iColor )
            {
                new 
szTeam[11];
                
get_user_team(iFoolszTeamcharsmax(szTeam));
                
Send_TeamInfo(0iFoolg_szTeamName[iColor]);
                
Send_SayText(0iFoolszMessage);
                
Send_TeamInfo(0iFoolszTeam);
            }
            else
            {
                
Send_SayText(0iFoolszMessage);
            }
        }

        
// ML is used, we need to loop through all players,
        // format text and send a MSG_ONE_UNRELIABLE SayText message
        
else
        {
            new 
szTeam[11], szFakeTeam[10];
            
            if( 
iColor )
            {
                
get_user_team(iFoolszTeamcharsmax(szTeam));
                
copy(szFakeTeamcharsmax(szFakeTeam), g_szTeamName[iColor]);
            }

            for( 
0iNumi++ )
            {
                
id iPlayers[i];

                for(
j=0j<iMlNumberj++)
                {
                    
// Set all LANG_PLAYER args to player index ( = id )
                    // so we can format the text for that specific player
                    
setarg(ArrayGetCell(aStoreMLj), _id);
                }

                
// format string for specific player
                
vformat(szMessage[1], charsmax(szMessage)-1szMsg4);

                if( 
iColor )
                {
                    
Send_TeamInfo(idiFoolszFakeTeam);
                    
Send_SayText(idiFoolszMessage);
                    
Send_TeamInfo(idiFoolszTeam);
                }
                else
                {
                    
Send_SayText(idiFoolszMessage);
                }
            }
            
ArrayDestroy(aStoreML);
        }
    }
    return 
1;
}

stock Send_TeamInfo(iReceiveriPlayerIdszTeam[])
{
    static 
iTeamInfo 0;
    if( !
iTeamInfo )
    {
        
iTeamInfo get_user_msgid("TeamInfo");
    }
    
message_begin(iReceiver MSG_ONE_UNRELIABLE MSG_BROADCASTiTeamInfo, .player=iReceiver);
    
write_byte(iPlayerId);
    
write_string(szTeam);
    
message_end();
}

stock Send_SayText(iReceiveriPlayerIdszMessage[])
{
    static 
iSayText 0;
    if( !
iSayText )
    {
        
iSayText get_user_msgid("SayText");
    }
    
message_begin(iReceiver MSG_ONE_UNRELIABLE MSG_BROADCASTiSayText, .player=iReceiver);
    
write_byte(iPlayerId);
    
write_string(szMessage);
    
message_end();
}

stock register_dictionary_colored(const filename[])
{
    if( !
register_dictionary(filename) )
    {
        return 
0;
    }

    new 
szFileName[256];
    
get_localinfo("amxx_datadir"szFileNamecharsmax(szFileName));
    
format(szFileNamecharsmax(szFileName), "%s/lang/%s"szFileNamefilename);
    new 
fp fopen(szFileName"rt");
    if( !
fp )
    {
        
log_amx("Failed to open %s"szFileName);
        return 
0;
    }

    new 
szBuffer[512], szLang[3], szKey[64], szTranslation[256], TransKey:iKey;

    while( !
feof(fp) )
    {
        
fgets(fpszBuffercharsmax(szBuffer));
        
trim(szBuffer);

        if( 
szBuffer[0] == '[' )
        {
            
strtok(szBuffer[1], szLangcharsmax(szLang), szBuffer1']');
        }
        else if( 
szBuffer[0] )
        {
            
strbreak(szBufferszKeycharsmax(szKey), szTranslationcharsmax(szTranslation));
            
iKey GetLangTransKey(szKey);
            if( 
iKey != TransKey_Bad )
            {
                while( 
replace(szTranslationcharsmax(szTranslation), "!g""^4") ){}
                while( 
replace(szTranslationcharsmax(szTranslation), "!t""^3") ){}
                while( 
replace(szTranslationcharsmax(szTranslation), "!n""^1") ){}
                
AddTranslation(szLangiKeyszTranslation[2]);
            }
        }
    }
    
    
fclose(fp);
    return 
1;

--------->

PHP Code:
stock client_print_color(idiColor=DontChange, const szMsg[], any:...)
{
    
// check if id is different from 0
    
if( id && !is_user_connected(id) )
    {
        return 
0;
    }

    if( 
iColor Grey )
    {
        
iColor DontChange;
    }

    new 
szMessage[192];
    if( 
iColor == DontChange )
    {
        
szMessage[0] = 0x04;
    }
    else
    {
        
szMessage[0] = 0x03;
    }

    new 
iParams numargs();
    
// Specific player code
    
if(id)
    {
        if( 
iParams == )
        {
            
copy(szMessage[1], charsmax(szMessage)-1szMsg);
        }
        else
        {
            
vformat(szMessage[1], charsmax(szMessage)-1szMsg4);
        }

        if( 
iColor )
        {
            new 
szTeam[11]; // store current team so we can restore it
            
get_user_team(idszTeamcharsmax(szTeam));

            
// set id TeamInfo in consequence
            // so SayText msg gonna show the right color
            
Send_TeamInfo(ididg_szTeamName[iColor]);

            
// Send the message
            
Send_SayText(ididszMessage);

            
// restore TeamInfo
            
Send_TeamInfo(ididszTeam);
        }
        else
        {
            
Send_SayText(ididszMessage);
        }
    } 
    return 
1;
}

stock Send_TeamInfo(iReceiveriPlayerIdszTeam[])
{
    static 
iTeamInfo 0;
    if( !
iTeamInfo )
    {
        
iTeamInfo get_user_msgid("TeamInfo");
    }
    
message_begin(iReceiver MSG_ONE_UNRELIABLE MSG_BROADCASTiTeamInfo, .player=iReceiver);
    
write_byte(iPlayerId);
    
write_string(szTeam);
    
message_end();
}

stock Send_SayText(iReceiveriPlayerIdszMessage[])
{
    static 
iSayText 0;
    if( !
iSayText )
    {
        
iSayText get_user_msgid("SayText");
    }
    
message_begin(iReceiver MSG_ONE_UNRELIABLE MSG_BROADCASTiSayText, .player=iReceiver);
    
write_byte(iPlayerId);
    
write_string(szMessage);
    
message_end();

Il n'y a pas de dictionary avec ton plugin, donc enlever le : stock register_dictionary_colored(const filename[])

Puis tu ne laisses jamais de message pour tout le monde en mettant 0 pour index, donc ça sert à rien de le laisser.
__________________
bboygrun is offline