AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Question] What is more optimized? (https://forums.alliedmods.net/showthread.php?t=294496)

GasmoN 02-28-2017 10:02

[Question] What is more optimized?
 
Hello,
I have a simple question for you a little beter scripters.
I have about 10 plugis that are using colored messages (colorchat)
So my question is what is better to use in all 10 plugins, include or stock version?

klippy 02-28-2017 10:13

Re: [Question] What is more optimized?
 
Depends on what that include file contains.

But if you are experiencing performance problems, it's not colorchat, it's something else.

GasmoN 02-28-2017 11:03

Re: [Question] What is more optimized?
 
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();



klippy 02-28-2017 11:47

Re: [Question] What is more optimized?
 
Doesn't matter.

Bugsy 02-28-2017 17:31

Re: [Question] What is more optimized?
 
No performance impact, but there is a convenience factor. If you include the stock within your plugin, the end user will not need to find and download the include file. It is best to include code within your plugin when possible.

PartialCloning 02-28-2017 17:45

Re: [Question] What is more optimized?
 
1.8.3 has client_print_color. If you're working on optimizing your old plugins you're better off upgrading to 1.8.3 and taking advantage of all the improvements and new natives.


All times are GMT -4. The time now is 20:26.

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