Raised This Month: $ Target: $400
 0% 

plugin performance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zimis
Junior Member
Join Date: Dec 2007
Location: Lithuania
Old 01-21-2009 , 09:05   plugin performance
Reply With Quote #1

Hi there

Few small questions about plugin performance

1) Which way is better?

PHP Code:
register_clcmd("say /command","sayCommand"


or


PHP Code:
register_clcmd("say","hook_say_and_search"


2) Why amxmodx default plugins check users access level twice?

in register_clcmd

i.e


PHP Code:
register_clcmd("say /command","sayCommand",ADMIN_KICK,"Whatever"
and then it check again in sayCommand()

i.e

PHP Code:
if (!cmd_access(id,level,cid,1)) 
    return 
PLUGIN_HANDLED 
3) Is it right to do?

PHP Code:
new plugon

public plugin_init(){
      
register_plugin("moo","moo","mooo")
      
plugon register_cvar("amx_whatever","1")
      switch(
plugon){
               case 
1:{
                       if 
plugon is 1 to register events,ham,command etc
               }
      }

__________________
I really like cookies

Last edited by zimis; 01-21-2009 at 09:07.
zimis is offline
Send a message via Skype™ to zimis
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 01-21-2009 , 09:10   Re: plugin performance
Reply With Quote #2

3)
PHP Code:
new plugon

public plugin_init(){
    
register_plugin("moo","moo","mooo")
    
plugon register_cvar("amx_whatever","1")
    
    if( 
get_pcvar_num(plugon) == ) {
        
// amx_whatever is 1 ;)
    
}

;)
__________________
xPaw is offline
zimis
Junior Member
Join Date: Dec 2007
Location: Lithuania
Old 01-21-2009 , 09:52   Re: plugin performance
Reply With Quote #3

about 3) is it okay to do that stuff? i mean to register events only when amx_whatever is 1?

If everything is okay, i think it is good way improve performance.

i.e

case 1: using plugon (similar to 3rd question)

plugin checks amx_whatever value and gets 0, it dose not register any events,messages or whatever, yes? so plugin dose not interact with the game, yes?

case 2: not using plugon

plugin check amx_whaterver value and gets 0, it register couple of events like ResetHUD, or messages of round start.

Every new round or when HUD is reseted, plugin calls defined function and check if amx_whatever is 0 or 1?

QUESTION?

Why force plugin call its function, and check amx_whatever value? when amx_whatever is 0
__________________
I really like cookies
zimis is offline
Send a message via Skype™ to zimis
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 01-21-2009 , 10:09   Re: plugin performance
Reply With Quote #4

Quote:
1) Which way is better?

PHP Code:
register_clcmd("say /command","sayCommand")



or


PHP Code:
register_clcmd("say","hook_say_and_search")
First, because you dont need to read any arguments.

Quote:
2) Why amxmodx default plugins check users access level twice?

in register_clcmd

i.e

PHP Code:
register_clcmd("say /command","sayCommand",ADMIN_KICK,"Whatever")
and then it check again in sayCommand()

i.e

PHP Code:
if (!cmd_access(id,level,cid,1))
return PLUGIN_HANDLED
Really dont know, but sometimes if you create function without checking access, anybody can use it.

3.
PHP Code:
 plugon register_cvar("amx_whatever","1"
Variable "plugon" is only pointer to variable, not a value.
__________________
Join US - custom Zombie Server - Custom Addons:



Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
Dr.G
Senior Member
Join Date: Nov 2008
Old 01-21-2009 , 11:24   Re: plugin performance
Reply With Quote #5

3)

PHP Code:
new plugon 
public plugin_init()

    
register_plugin("moo","moo","mooo"
    
plugon register_cvar("amx_whatever","1"
 
    if( 
get_pcvar_num(plugon)) 
    { 
        
//do_something
    


3) With random case

PHP Code:
new plugon 
public plugin_init()

    
register_plugin("moo","moo","mooo"
    
plugon register_cvar("amx_whatever","1"
 
    if( 
get_pcvar_num(plugon)) 
    { 
     switch(
random_num(0,2))
   {
  case 
0://do_something 0
  
case 1://do_something 1
  
case 2://do_something 2
 
}
    } 

__________________
Dr.G is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 01-21-2009 , 11:34   Re: plugin performance
Reply With Quote #6

Dr.G that random thing aint cool.
__________________
xPaw is offline
Dr.G
Senior Member
Join Date: Nov 2008
Old 01-21-2009 , 11:42   Re: plugin performance
Reply With Quote #7

lol why not? Cuz its in plugin_init() ??
__________________
Dr.G is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 01-21-2009 , 12:04   Re: plugin performance
Reply With Quote #8

why need random? if he want register forwards when cvar is 1
__________________
xPaw is offline
Dr.G
Senior Member
Join Date: Nov 2008
Old 01-21-2009 , 12:16   Re: plugin performance
Reply With Quote #9

Oh its was just an simple exsample buddy
__________________
Dr.G is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-21-2009 , 12:20   Re: plugin performance
Reply With Quote #10

1. If I have more than 1 say command in my plugin, then I hook "say" and check the command.
Otherwise, I just register the 1 command.

2. Just setting the flag in register_*cmd() doesn't enforce the flag.
You have to enforce it yourself with cmd_access(), access(), or (get_user_flags() & ADMIN_*).

3. I think it would be best if you registered the events anyway, then checked to see if the cvar was enabled or disabled when they were called.

Code:
new cvar_on; public plugin_init() {     register_event("HLTV", "EventNewRound", "a", "1=0", "2=0");         cvar_on = register_cvar("plugin_on", "1"); } public EventNewRound() {     if( !get_pcvar_num(plugin_on) ) return;         // code if plugin is on }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 01:45.


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