Raised This Month: $ Target: $400
 0% 

[Question] What is more optimized?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
GasmoN
Member
Join Date: Jul 2014
Old 02-28-2017 , 11:03   Re: [Question] What is more optimized?
Reply With Quote #3

No, no I'm don't experiencing performance problems.
I want to know is it better to use this include in every plugin:
PHP Code:
#if defined _colorchat_included
  #endinput
#endif
#define _colorchat_included

enum ChatColor
{
    
CHATCOLOR_NORMAL 1,
    
CHATCOLOR_GREEN,
    
CHATCOLOR_TEAM_COLOR,
    
CHATCOLOR_GREY,     
    
CHATCOLOR_RED,         
    
CHATCOLOR_BLUE,     
};

new 
g_TeamName[][] = 
{
    
"",
    
"TERRORIST",
    
"CT",
    
"SPECTATOR"
};

static 
g_msgSayText,g_msgTeamInfo;

ColorChat(idChatColor:color, const msg[], {Float,Sql,Result,_}:...)
{
    new 
teamindexMSG_Type
    
new bool:teamChanged false
    
static message[192]
    
    if(!
g_msgSayTextg_msgSayText get_user_msgid("SayText");
    if(!
g_msgTeamInfog_msgTeamInfo get_user_msgid("TeamInfo");
    
    switch(
color)
    {
        case 
CHATCOLOR_NORMAL// Normal
        
{
            
message[0] = 0x01;
        }
        case 
CHATCOLOR_GREEN// Green
        
{
            
message[0] = 0x04;
        }
        default: 
// Grey, Red, Blue
        
{
            
message[0] = 0x03;
        }
    }
    
    
vformat(message[1], 190msg4);
    
replace_all(message190"$g""^x04")
    
replace_all(message190"$n""^x01")
    
replace_all(message190"$t""^x03")
    
message[191] = '^0';
    
    if(
id == 0)
    {
        
index findAnyPlayer();
        
MSG_Type MSG_ALL;
    }
    else
    {
        
index id;
        
MSG_Type MSG_ONE;
    }
    if(
index != 0)
    {
        
team get_user_team(index);    
        if(
color == CHATCOLOR_RED && team != 1)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[1])
            
teamChanged true
        
}
        else
        if(
color == CHATCOLOR_BLUE && team != 2)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[2])
            
teamChanged true
        
}
        else
        if(
color == CHATCOLOR_GREY && team != 0)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[0])
            
teamChanged true
        
}
        
messageSayText(indexMSG_Typemessage);
        if(
teamChanged)
        {
            
messageTeamInfo(indexMSG_Typeg_TeamName[team])
        }
    }
}

messageSayText(idtypemessage[])
{
    
message_begin(typeg_msgSayText_id)
    
write_byte(id)        
    
write_string(message)
    
message_end()
}
    
messageTeamInfo(idtypeteam[])
{
    
message_begin(typeg_msgTeamInfo_id)
    
write_byte(id)
    
write_string(team)
    
message_end()
}
    
findAnyPlayer()
{
    static 
players[32], inumpid
    
    get_players
(playersinum"ch")
    
    for (new 
0inuma++)
    {
        
pid players[a]
        if(
is_user_connected(pid))
            return 
pid
    
}
    
    return 
0

or to write this stock in every plugin
PHP Code:
color_print(index, const text[], any:...)
{
new 
szMsg[128];
vformat(szMsgsizeof(szMsg) - 1text3);

replace_all(szMsgsizeof(szMsg) - 1"!g""^x04");
replace_all(szMsgsizeof(szMsg) - 1"!n""^x01");
replace_all(szMsgsizeof(szMsg) - 1"!t""^x03");

message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _index);
write_byte(index);
write_string(szMsg);
message_end();

GasmoN is offline
 



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 20:26.


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