Raised This Month: $ Target: $400
 0% 

[Question] What is more optimized?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GasmoN
Member
Join Date: Jul 2014
Old 02-28-2017 , 10:02   [Question] What is more optimized?
Reply With Quote #1

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?
GasmoN is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-28-2017 , 10:13   Re: [Question] What is more optimized?
Reply With Quote #2

Depends on what that include file contains.

But if you are experiencing performance problems, it's not colorchat, it's something else.
klippy is offline
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
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-28-2017 , 11:47   Re: [Question] What is more optimized?
Reply With Quote #4

Doesn't matter.
klippy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-28-2017 , 17:31   Re: [Question] What is more optimized?
Reply With Quote #5

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.
__________________

Last edited by Bugsy; 02-28-2017 at 17:31.
Bugsy is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 02-28-2017 , 17:45   Re: [Question] What is more optimized?
Reply With Quote #6

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


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