AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Admin Listen Optimization (https://forums.alliedmods.net/showthread.php?t=195622)

tcPane 09-09-2012 13:06

Admin Listen Optimization
 
Hello,
can u optimize me this code?

PHP Code:


#include <amxmodx> 
#include <amxmisc> 
#include <engine> 

#define PLUGIN "Admin Listen"
#define VERSION "2.3x"

new Count[32][32], g_Voice_Status[2

public 
plugin_modules()
{
    
require_module("engine")  


public 
plugin_init()

       
register_plugin(PLUGINVERSION"/dev/ urandom"
       
       
register_event("SayText""CatchSay""b"
       
     
register_srvcmd("amx_voice""VoiceStatus")


public 
CatchSay(id

      new 
Reciever read_data(0
        new 
Sender   read_data(1)  
        new 
Message[151], Channel[151], SenderName[32

        if(
is_running("cstrike")) 
        { 
        
read_data(2Channel150
        
read_data(4Message150
        
get_user_name(SenderSenderName31
    } 
    else 
    { 
        
read_data(2Message150
    } 
    
    
Count[Sender][Reciever] = 1           

    
if(Sender == Reciever
     {       
        new 
Players[32
        new 
PlayerCount get_playersnum()  
        
get_players(PlayersPlayerCount"c"
        
          for(new 
0PlayerCounti++)  
        { 
            if(
get_user_flags(Players[i]) & ADMIN_IMMUNITY
            {      
                        if(
Count[Sender][Players[i]] != 1
                        {               
                              
message_begin(MSG_ONEget_user_msgid("SayText"), { 00}, Players[i]) 
                    
write_byte(Sender)  
                    
                    if(
is_running("cstrike")) 
                    { 
                                    
write_string(Channel
                                    
write_string(SenderName
                    }
                    
                              
write_string(Message
                              
message_end() 
                } 
            } 
            
            
Count[Sender][Players[i]] = 0
         

    } 


public 
VoiceStatus()

    
read_argv(1g_Voice_Status1
    
       new 
Players[32
       new 
PlayerCount get_playersnum() 
    
get_players(PlayersPlayerCount"c"
    
    for(new 
0PlayerCounti++) 
    { 
        if((
get_user_flags(Players[i]) & ADMIN_IMMUNITY))
        {          
            if(
equal(g_Voice_Status"0")) 
            {
                
set_speak(Players[i], 0
            }
            if(
equal(g_Voice_Status"1")) 
            {
                
set_speak(Players[i], 4
            }
        } 
    } 


public 
client_infochanged(id

       if((
get_user_flags(id) & ADMIN_IMMUNITY) && equal(g_Voice_Status"1")) set_speak(id4


public 
client_connect(id

       if((
get_user_flags(id) & ADMIN_IMMUNITY) && equal(g_Voice_Status"1")) set_speak(id4


Thank you.

YamiKaitou 09-09-2012 13:37

Re: Admin Listen Optimization
 
Remove plugin_modules
Cache is_running
Convert g_Voice_Status to an int and then use a ifelse
Cache the id in your Players array instead of reindexing it

Thread moved

tcPane 09-09-2012 13:53

Re: Admin Listen Optimization
 
1. Ok
2. what to put instead is_running, because there is if and else?
3. how to convert and what is int?
4. Players[i] ---> Players[] ?

YamiKaitou 09-09-2012 14:04

Re: Admin Listen Optimization
 
2. Cache the value to a global variable in plugin_init and then just check the value whenever you need it
3. http://hg.alliedmods.net/amxmodx-cen...string.inc#l78
4. http://wiki.alliedmods.net/Optimizin...e-index_Arrays

tcPane 09-09-2012 14:39

Re: Admin Listen Optimization
 
I can't make this things...
It is more difficult when somebody explain me how to make it. I will understand easier when you give me ready code (optimized)...

fysiks 09-09-2012 15:08

Re: Admin Listen Optimization
 
Quote:

Originally Posted by tcPane (Post 1795401)
I can't make this things...
It is more difficult when somebody explain me how to make it. I will understand easier when you give me ready code (optimized)...

You were just given optimized code if you happened to read what Yami posted . . .

tcPane 09-09-2012 15:21

Re: Admin Listen Optimization
 
I read everything which Yami posted, but nothing...

YamiKaitou 09-09-2012 15:38

Re: Admin Listen Optimization
 
The only way you will become a better scripter is if you start to figure this out on your own. I gave you enough information to get started, now go figure it out and then come back with your modified script.

ConnorMcLeod 09-09-2012 15:55

Re: Admin Listen Optimization
 
In his first post (that was in request forum) he ask for someone to make the modification :)

tcPane 09-10-2012 05:06

Re: Admin Listen Optimization
 
Quote:

Originally Posted by YamiKaitou (Post 1795449)
The only way you will become a better scripter is if you start to figure this out on your own. I gave you enough information to get started, now go figure it out and then come back with your modified script.

Check it:
PHP Code:

#include <amxmodx>  
#include <amxmisc>  
#include <engine>  

#define PLUGIN "Admin Listen" 
#define VERSION "2.3x" 

new Count[32][32], g_Voice_Status[2]

public 
plugin_init() 
{  
    
register_plugin(PLUGINVERSION"/dev/ urandom")  
 
    
register_event("SayText""CatchSay""b")  
        
    
register_srvcmd("amx_voice""VoiceStatus"
    
    
cstrike is_running("cstrike")
}  

public 
CatchSay(id)  
{  
     new 
Reciever read_data(0)  
    new 
Sender   read_data(1)   
    new 
Message[151], Channel[151], SenderName[32]  

    if(
cstrike)  
     {  
          
read_data(2Channel150)  
         
read_data(4Message150)  
        
get_user_name(SenderSenderName31)  
    }  
    else  
    {  
        
read_data(2Message150)  
    }  
     
    
Count[Sender][Reciever] = 1            

    
if(Sender == Reciever)  
     {        
        new 
Player
        
new PlayerCount get_playersnum()   
        
get_players(PlayerPlayerCount"c")  
         
        for(new 
0PlayerCounti++)   
        {  
            
Player Players[i]
            if(
get_user_flags(Player) & ADMIN_IMMUNITY)  
             {       
                  if(
Count[Sender][Player] != 1)  
                    {                
                         
message_begin(MSG_ONEget_user_msgid("SayText"), { 00}, Player)  
                        
write_byte(Sender)   
                     
                        if(
cstrike)  
                        {  
                              
write_string(Channel)  
                             
write_string(SenderName)  
                        } 
                     
                            
write_string(Message)  
                         
message_end()  
                    }  
            } 
             
            
Count[Sender][Player] = 
        
}  
    }  
}  

public 
VoiceStatus() 
{  
    
read_argv(1g_Voice_Status1
    
    new 
Player  
    
new PlayerCount get_playersnum()  
    
get_players(PlayerPlayerCount"c")  
     
    for(new 
0PlayerCounti++)  
    {  
        
Player Players[i]
         if((
get_user_flags(Player) & ADMIN_IMMUNITY)) 
        {           
              if(
equal(g_Voice_Status[0])  
              { 
                   
set_speak(Player0)  
                } 
                else
                { 
                    
set_speak(Player4)  
                } 
            }  
        }  
}  

public 
client_infochanged(id)  
{  
    if((
get_user_flags(id) & ADMIN_IMMUNITY) && equal(g_Voice_Status"1")) set_speak(id4)  
}  

public 
client_connect(id)  
{  
      if((
get_user_flags(id) & ADMIN_IMMUNITY) && equal(g_Voice_Status"1")) set_speak(id4)  




All times are GMT -4. The time now is 08:20.

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