Raised This Month: $51 Target: $400
 12% 

Admin Listen Optimization


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tcPane
Senior Member
Join Date: Sep 2010
Old 09-09-2012 , 13:06   Admin Listen Optimization
Reply With Quote #1

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.
tcPane is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 09-09-2012 , 13:37   Re: Admin Listen Optimization
Reply With Quote #2

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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
tcPane
Senior Member
Join Date: Sep 2010
Old 09-09-2012 , 13:53   Re: Admin Listen Optimization
Reply With Quote #3

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[] ?

Last edited by tcPane; 09-09-2012 at 13:54.
tcPane is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 09-09-2012 , 14:04   Re: Admin Listen Optimization
Reply With Quote #4

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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
tcPane
Senior Member
Join Date: Sep 2010
Old 09-09-2012 , 14:39   Re: Admin Listen Optimization
Reply With Quote #5

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)...
tcPane is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-09-2012 , 15:08   Re: Admin Listen Optimization
Reply With Quote #6

Quote:
Originally Posted by tcPane View Post
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 . . .
__________________
fysiks is offline
tcPane
Senior Member
Join Date: Sep 2010
Old 09-09-2012 , 15:21   Re: Admin Listen Optimization
Reply With Quote #7

I read everything which Yami posted, but nothing...
tcPane is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 09-09-2012 , 15:38   Re: Admin Listen Optimization
Reply With Quote #8

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.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-09-2012 , 15:55   Re: Admin Listen Optimization
Reply With Quote #9

In his first post (that was in request forum) he ask for someone to make the modification
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
tcPane
Senior Member
Join Date: Sep 2010
Old 09-10-2012 , 05:06   Re: Admin Listen Optimization
Reply With Quote #10

Quote:
Originally Posted by YamiKaitou View Post
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)  

tcPane 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 07:13.


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