Raised This Month: $32 Target: $400
 8% 

[TUT] SourcePawn Scripting - Tips, Basics to Advanced


Post New Thread Reply   
 
Thread Tools Display Modes
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-28-2022 , 09:19   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #71

strcopy has less logic, should be faster.
Also, if you need stringbuilder functionality, use strCat; it doesn't re-create string buffer unlike Format.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
plug344
Member
Join Date: Dec 2021
Old 03-29-2022 , 04:41   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #72

Thank you very much,

the various "handle.method" of the new syntax seems to be just the wrapper of the old syntax, is there a difference in their speed? Such as "ClearArray (ArrayList)" and "ArrayList.Clear()", etc.
plug344 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 03-29-2022 , 07:21   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #73

You can use either-or. The speed is irrelevant. It’s more a matter of preference rather than which one is slightly faster.

If you’re really curious about it, you can use the profiler. Pre-optimizing your plugin is a waste of time. Unless you’re actually experiencing performance issues with your plugin, don’t worry so much about choosing the fastest method/function for every part of your code. You may end up sacrificing readability, maintainability, and simplicity for a negligible difference in speed.

Optimizing Plugins (SourceMod Scripting)
__________________
Psyk0tik is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 03-29-2022 , 10:47   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #74

For something like this optimizing is negligible but I wouldn't advise against optimizing especially if the plugin will be made publicly available. Many public ones have huge performance hits due to bad practices and some servers running many plugins will feel the degradation in performance due to certain unoptimized plugins.
__________________
Silvers is offline
iaNanaNana
Member
Join Date: Sep 2020
Location: Two-dimensional
Old 04-13-2022 , 03:50   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #75

I have a question: int i[N][33] or ArrayList i[33] Which is better? The before cause too many plugin file size after compiled

Last edited by iaNanaNana; 04-13-2022 at 03:55.
iaNanaNana is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 04-13-2022 , 15:00   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #76

"Which is better" most of the time depends on the situation and the use case.
You should share an example and mention the "before" and "after" sizes as well.
__________________
Marttt is offline
iaNanaNana
Member
Join Date: Sep 2020
Location: Two-dimensional
Old 04-15-2022 , 09:03   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #77

Quote:
Originally Posted by Marttt View Post
"Which is better" most of the time depends on the situation and the use case.
You should share an example and mention the "before" and "after" sizes as well.
PHP Code:
int iConfig[100][MAXPLAYERS]

public 
OnClientPutInServer(a)
{
    
iConfig[0][a] = 1
}

public 
OnClientDisconnect(a)
{
    
iConfig[0][a] = 0

or
PHP Code:
ArrayList hConfig[MAXPLAYERS]

public 
OnClientPutInServer(a)
{
    
ArrayList hConfig[a] = new ArrayList(1,100)
    
hConfig[a].Set(01)
}

public 
OnClientDisconnect(a)
{
    
delete hConfig[a]

I wanna use to store clients configures when in game, reset values or delete ArrayList when disconenct.

Last edited by iaNanaNana; 04-15-2022 at 09:05.
iaNanaNana is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 04-15-2022 , 09:30   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #78

Should be: MAXPLAYERS+1 not just MAXPLAYERS
__________________
Silvers is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 04-15-2022 , 11:13   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #79

iaNanaNana, you don't need array of lists, it is already an "array" of blocks.
Also, alloc/release handles is a heavy operation.
See:
PHP Code:
ArrayList     hConfig;

public 
void OnPluginStart()
{
    
hConfig = new ArrayList(ByteCountToCells(4), MAXPLAYERS+1); // 4 bytes (int or float)
    
    // or
    // hConfig = new ArrayList(ByteCountToCells(4));
    // hConfig.Resize(MAXPLAYERS+1);
}

public 
void OnClientPutInServer(int client)
{
    
hConfig.Set(client10); // write 1 at block 0
}

public 
void OnClientDisconnect(int client)
{
    
hConfig.Set(client00); // write 0 at block 0

or write multiple values, e.g. int + float using different arraylist's blocks:
PHP Code:
ArrayList    hList;

public 
void OnPluginStart()
{
    
hList = new ArrayList(ByteCountToCells(8)); // 8 bytes (int + float)
}

public 
Action SomeCommand(int clientint argc)
{
    
int countattacker;
    
float hpfPercent[MAXPLAYERS+1] = ......
    
    for( 
int i 1<= MaxClientsi++ )
    {
        if( 
SomeCondition )
        {
            
hList.Resize(count 1);
            
hList.Set(cntfPercent[i], 0);     // block 0 - float (e.g. % HP)
            
hList.Set(cnti1);                // block 1 - int (client index)
            
++ count;
        }
    }

    
hList.Sort(Sort_DescendingSort_Float);
    
    for( 
int i 0hList.Lengthi++ )
    {
        
attacker al.Get(i1); // read block 1
        
hp al.Get(i0);         // read block 0
    
}
    
// ...

But, for simple tasks the simple arrays is much more faster.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
sorallll
Senior Member
Join Date: Oct 2018
Old 04-16-2022 , 00:21   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #80

I would like to ask, how to calculate the number of bytes occupied by the string in IntToString, FloatToString
sorallll is offline
Reply


Thread Tools
Display Modes

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


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