AlliedModders

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

Storas1337 05-25-2014 14:40

Optimizing
 
Hey guys anybody can give me an example how to optimize these part of code (with switch statement)

Code:

else if(equali(arg_cmd, "slay"))
        {
                if(!(get_user_flags(id) & ADMIN_SLAY))
                {
                        ColorChat(id, NORMAL, "^4Only ADMINS can use the command!^4", Prefix)
                        return
                }
               
                if(equali(arg2, ""))
                {
                        ColorChat(id, NORMAL, "^4You should enter some name!^4", Prefix)
                        return
                }
               
                if(!target)
                {
                        ColorChat(id, NORMAL, "^4There is not a player wit this name!^4", Prefix, arg2)
                        return
                }
               
                client_cmd(id, "amx_slay ^"%s^"", arg2)
        }


Torge 05-25-2014 14:48

Re: Optimizing
 
PHP Code:

switch(get_user_flags(id))
{
    case 
blabla:


?

Storas1337 05-25-2014 15:34

Re: Optimizing
 
I need more detailed example there is more code for ex

PHP Code:

  if(equali(arg_cmd"/hp")) 
    { 
   
        if(!(
get_user_flags(id) & ADMIN_BAN)) 
        { 
            
ColorChat(idNORMAL"%s^1Only ^3admins^1 can use the command^4!"Prefix
            return 
        } 
         
  
        if(
equali(arg2"")) 
        { 
            
ColorChat(idNORMAL"%s^1You should enter some name^4!"Prefix
            return 
        } 


GuskiS 05-25-2014 17:57

Re: Optimizing
 
This can't be done with switch statement. Your code is fine.

Storas1337 05-25-2014 18:35

Re: Optimizing
 
Quote:

Originally Posted by GuskiS (Post 2142434)
This can't be done with switch statement. Your code is fine.

Yes i know that fine, i just want to load less cpu :)

Flick3rR 05-25-2014 18:59

Re: Optimizing
 
Well, I have already thought about that, when sent it to you, but there is no other way to make it. Only way, I guess, is by these 'if' statements to check the conditions.

Storas1337 05-25-2014 19:26

Re: Optimizing
 
ok thank you guys i was curious ;)


All times are GMT -4. The time now is 09:48.

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