AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   plugin performance (https://forums.alliedmods.net/showthread.php?t=84133)

zimis 01-21-2009 09:05

plugin performance
 
Hi there :wink:

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
               }
      }


:oops::wink:

xPaw 01-21-2009 09:10

Re: plugin performance
 
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 ;)
    
}


;)

zimis 01-21-2009 09:52

Re: plugin performance
 
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

Sn!ff3r 01-21-2009 10:09

Re: plugin performance
 
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.

Dr.G 01-21-2009 11:24

Re: plugin performance
 
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
 
}
    } 



xPaw 01-21-2009 11:34

Re: plugin performance
 
Dr.G that random thing aint cool.

Dr.G 01-21-2009 11:42

Re: plugin performance
 
lol why not? Cuz its in plugin_init() ??

xPaw 01-21-2009 12:04

Re: plugin performance
 
why need random? if he want register forwards when cvar is 1

Dr.G 01-21-2009 12:16

Re: plugin performance
 
Oh its was just an simple exsample buddy

Exolent[jNr] 01-21-2009 12:20

Re: plugin performance
 
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 }


All times are GMT -4. The time now is 01:45.

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