Raised This Month: $ Target: $400
 0% 

Optimization


Post New Thread Reply   
 
Thread Tools Display Modes
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-23-2017 , 17:13   Re: Optimization
Reply With Quote #11

With simple words - if you use get_user_flags() more than once, cache its value in a variable and use it as much as you want. Making a stock for just one function won't improve the code. Create a stock if you are using multiple equivalent lines of code more than once, so you won't have to copy/paste them.

Storing the flags in a global variable is a bad idea. They can change in any given moment of the game.
__________________

Last edited by OciXCrom; 01-23-2017 at 17:14.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-23-2017 , 17:18   Re: Optimization
Reply With Quote #12

Still it a bad idea if I re-store the global variable in client_infochanged()?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 01-23-2017 at 17:48.
EFFx is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 01-23-2017 , 17:24   Re: Optimization
Reply With Quote #13

Quote:
Originally Posted by EFFx View Post
I'm curious now, what "hard menu" are you talking about?

I want optimize it because I think I will post this here, you know. And optimization is the most important thing on plugins you know. But I understand you side and I'll continue with the current format. If someone told me to change, i'll do it.
I'm not sure if this is what you're doing. The text just seemed to fit some kind of buymenu system.
Here's a good example of a pretty static buymenu being converted to a dynamic one. It's old but it's very short in code which makes it easier to grasp.
https://forums.alliedmods.net/showthread.php?t=223322
__________________
Black Rose is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-23-2017 , 17:28   Re: Optimization
Reply With Quote #14

Hm, I know it a little bit but thats not what i'm talking about.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 01-23-2017 at 17:35.
EFFx is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-23-2017 , 17:49   Re: Optimization
Reply With Quote #15

Quote:
Originally Posted by EFFx View Post
Still it a bad idea if I re-store the global variable in client_infochanged()?
I meant

PHP Code:
new iUserFlag 

public function1(id)
{
     
iUserFlag get_user_flags(id)
     if(....
}

public 
function2(id)
{
     
iUserFlag get_user_flags(id)
     if(... 
In this case, a global is really needed or haven't problem I re-create that variable on both of functions?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 01-23-2017 , 17:52   Re: Optimization
Reply With Quote #16

What he wants is to check for ADMIN_KICK / ADMIN_SLAY in more than one function and send a message to the player depending on his admin flag

So it is perfectly fine to go with a stock/function for that instead of writing it in every function

Just create a function/stock like this and call it from any function you need it

And no, it's not advised to check and store the flags every time the client info changed, just check when it is needed and store in a local variable, example below

PHP Code:

public SendPlayerMessage(id)
{
       new 
PlayerFlags get_user_flags(id)

       if(
PlayerFlags ADMIN_SLAY)
       {
            
// print message
            
return
       }
       if(
PlayerFlags ADMIN_KICK)
       { 
              
// print message
              
return 
       }

__________________

Last edited by Depresie; 01-23-2017 at 17:53.
Depresie is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-23-2017 , 17:59   Re: Optimization
Reply With Quote #17

Finally someone understood what I said.

Yea dude, thats what I wanted to know, ty.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-23-2017 , 23:03   Re: Optimization
Reply With Quote #18

Depresie: Multiple times you refer to making a 'stock/function' to do things. It's always a function, defining it as a 'stock' simply makes it only compile the function in the binary/.amxx if it is used within the plugin. This is why stocks are typically only used in include files since a person can include a file but not use many functions within the file--'stock' prevents the unused functions/variables from being compiled into in the binary. There is more detail in the pawn language guide.
__________________
Bugsy is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-24-2017 , 06:16   Re: Optimization
Reply With Quote #19

'stock' just disables warning about unused function, so 'func' aren't compiled in binary in both codes:
PHP Code:
#include <amxmodx>

public plugin_init()
{
}

// Isn't compiled in binary, but prints warning
func() {
   
server_print("trololo");

PHP Code:
#include <amxmodx>

public plugin_init()
{
}

// Not compiled, no warning
stock func() {
   
server_print("trololo");

Variables have the same behaviour:
PHP Code:
#include <amxmodx>

// Not compiled, but warning
new g;

public 
plugin_init()
{

PHP Code:
#include <amxmodx>

// Not compiled, no warning
new stock g;

public 
plugin_init()
{

__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-24-2017 , 09:43   Re: Optimization
Reply With Quote #20

What point are you trying to make? Ok.. Within a plugin you should not define a function or variable as stock. This way the compiler tells you what you are not using which you can then remove from your code. Stocks should only be used in includes since it is ok to not use all defined variables/functions.
__________________
Bugsy 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:50.


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