Raised This Month: $ Target: $400
 0% 

Loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 05-11-2010 , 23:46   Loop
Reply With Quote #1

I Have done a part of my new mixmaker,and i make something like that....

PHP Code:
new const CanSay[][] = 
{
         
"name",
         
"name1",
         
"name2"

PHP Code:
//init
 

//Func

Loop's here
switch(get_pcvar_num(cvar))
{
        case 1 :
      {
                 containi(name,CanSay[i])
       }
        case 2:
      {
              containi(name,CanSay[i])
        }
         case 3: 
        {
              containi(name,CanSay[i])
          }


But i can use name (of the const) but,no name1 and name2,i don't wan't to make a loop per case.
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-11-2010 , 23:57   Re: Loop
Reply With Quote #2

Please describe better of what you want to do.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 05-12-2010 , 00:08   Re: Loop
Reply With Quote #3

This is the complete code
PHP Code:
/*    
    mixm_nosaytype :
                         * 0 : Hablan los admins y muestra say /pausa.
                         * 1 : Hablan los admins y no muestra say /pausa.
                         * 2 : Hablan los TL's/Admins y muestra say /pausa.
                         * 3 : Hablan los TL's/Admins y no muestra say /pausa.
                         * 4 : Hablan los admins,permite hablar por freezetime y muestra say /pausa.
                         * 5 : Hablan los admins,permite hablar por freezetime y no muestra say /pausa.
                         * 6 : Hablan los TL's/Admins,permite hablar por freezetime y muestra say /pausa.
                         * 7 : Hablan los TL's/Admins,permite Hablar por freezetime y no muestra say /pausa.
*/

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Chat Blocker"
#define VERSION "1.0"
#define AUTHOR "#8 SickneSS"

/* Chat Blocker */

new const CanSay[][] = 
{     
    
"[TL]",
    
"[CPT]",
    
"[CAPTAIN]" 
}

new 
NoSay
new NoSayType
new pFreezetime

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
NoSay register_cvar("mixm_nosay","0")
    
NoSayType register_cvar("mixm_nosaytype","0")
    
pFreezetime get_cvar_pointer("mp_freezetime")
    
    
register_clcmd("say","HookSay")
    
register_clcmd("say /nosay","cmdSayNoSay",ADMIN_CVAR,"<Lock/Unlock the chat>")
}

public 
cmdSayNoSay(id,level,cid) {
    
    if(!
cmd_access(id,level,cid,1))  
        return 
PLUGIN_HANDLED
    
    
new adminname[32]
    
get_user_name(idadminname31)
    
    
set_pcvar_num(NoSay,get_pcvar_num(NoSay) == 0)
    
client_print(0,print_chat,"El Admin %s %sbloqueo el chat",adminnameget_pcvar_num(NoSay) ? "" "des")
    
    return 
PLUGIN_HANDLED
}

public 
HookSay(id) {
    
    if(!
get_pcvar_num(NoSay))
        return 
PLUGIN_CONTINUE
    
    
if(get_user_flags(id) & ADMIN_CHAT)
        return 
PLUGIN_CONTINUE
    
    
new name[32]
    
get_user_name(id,name,31)
    
    new 
said[192]
    
read_args(said,191)
    
    for(new 
i;sizeof CanSay;i++)
    
    switch(
get_pcvar_num(NoSayType))
    {    
        case 
:
        {        
            if(
containi(said,"/pausa") != -1)
            {
                
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                return 
PLUGIN_HANDLED
            
}
            
client_print(id,print_chat,"Say Bloqueado")
            
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
            return 
PLUGIN_HANDLED
        
}
        case 
:
        {
            
client_print(id,print_chat,"Say Bloqueado")
            return 
PLUGIN_HANDLED
        
}
        case 
:
        {
            if(
containi(name,CanSay[i]) != -1)
            return 
PLUGIN_CONTINUE
                
            
if(containi(said,"/pausa") != -1)
            {
                
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                return 
PLUGIN_HANDLED
            
}
            
client_print(id,print_chat,"Say Bloqueado")
            
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
            return 
PLUGIN_HANDLED
        
}
        case 
:
        {
            if(
containi(name,CanSay[i]) != -1)
            return 
PLUGIN_CONTINUE
            
            client_print
(id,print_chat,"Say Bloqueado")
            return 
PLUGIN_HANDLED
        
}
        case 
4:
        {
            if(
get_pcvar_float(pFreezetime) <= 0)
            {
                if(
containi(said,"/pausa") != -1)
                {
                    
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                    return 
PLUGIN_HANDLED
                
}
                
client_print(id,print_chat,"Say Bloqueado")
                
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
        case 
5:
        {
            if(
get_pcvar_float(pFreezetime) <= 0)
            {
                
client_print(id,print_chat,"Say Bloqueado")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
        case 
6:
        {
            if(
containi(name,CanSay[i]) != -1)
            return 
PLUGIN_CONTINUE
            
            
if(get_pcvar_float(pFreezetime) <= 0)
            {
                if(
containi(said,"/pausa") != -1)
                {
                    
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                    return 
PLUGIN_HANDLED
                
}
                
client_print(id,print_chat,"Say Bloqueado")
                
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
        case 
:
        {
            if(
containi(name,CanSay[i]) != -1)
            return 
PLUGIN_CONTINUE
            
            
if(get_pcvar_float(pFreezetime) <= 0)
            {
                
client_print(id,print_chat,"Say Bloqueado")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
    }        
    return 
PLUGIN_HANDLED

Sorry for the english
I Want to optimize the code
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-12-2010 , 00:29   Re: Loop
Reply With Quote #4

EDIT: Wow, this is confusing.

EDIT2:

I would do something like this to not have the loop when I don't need it:

PHP Code:
/*    
    mixm_nosaytype :
                        * 0 : Hablan los admins y muestra say /pausa.
                        * 1 : Hablan los admins y no muestra say /pausa.
                        * 2 : Hablan los TL's/Admins y muestra say /pausa.
                        * 3 : Hablan los TL's/Admins y no muestra say /pausa.
                        * 4 : Hablan los admins,permite hablar por freezetime y muestra say /pausa.
                        * 5 : Hablan los admins,permite hablar por freezetime y no muestra say /pausa.
                        * 6 : Hablan los TL's/Admins,permite hablar por freezetime y muestra say /pausa.
                        * 7 : Hablan los TL's/Admins,permite Hablar por freezetime y no muestra say /pausa.
*/

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Chat Blocker"
#define VERSION "1.0"
#define AUTHOR "#8 SickneSS"

/* Chat Blocker */

new const CanSay[][] = 
{     
    
"[TL]",
    
"[CPT]",
    
"[CAPTAIN]" 
}

new 
NoSay
new NoSayType
new pFreezetime

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
NoSay register_cvar("mixm_nosay","0")
    
NoSayType register_cvar("mixm_nosaytype","0")
    
pFreezetime get_cvar_pointer("mp_freezetime")
    
    
register_clcmd("say","HookSay")
    
register_clcmd("say /nosay","cmdSayNoSay",ADMIN_CVAR,"<Lock/Unlock the chat>")
}

public 
cmdSayNoSay(id,level,cid) {
    
    if(!
cmd_access(id,level,cid,1))  
        return 
PLUGIN_HANDLED
    
    
new adminname[32]
    
get_user_name(idadminname31)
    
    
set_pcvar_num(NoSay,get_pcvar_num(NoSay) == 0)
    
client_print(0,print_chat,"El Admin %s %sbloqueo el chat",adminnameget_pcvar_num(NoSay) ? "" "des")
    
    return 
PLUGIN_HANDLED
}

public 
HookSay(id) {
    
    if(!
get_pcvar_num(NoSay))
        return 
PLUGIN_CONTINUE
    
    
if(get_user_flags(id) & ADMIN_CHAT)
        return 
PLUGIN_CONTINUE
    
    
new name[32]
    
get_user_name(id,name,31)
    
    new 
said[192]
    
read_args(said,191)
    
    switch(
get_pcvar_num(NoSayType))
    {    
        case 
:
        {        
            if(
containi(said,"/pausa") != -1)
            {
                
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                return 
PLUGIN_HANDLED
            
}
            
client_print(id,print_chat,"Say Bloqueado")
            
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
            return 
PLUGIN_HANDLED
        
}
        case 
:
        {
            
client_print(id,print_chat,"Say Bloqueado")
            return 
PLUGIN_HANDLED
        
}
        case 
:
        {
            if( 
does_containi_tag(name) )
                return 
PLUGIN_CONTINUE
                
            
if(containi(said,"/pausa") != -1)
            {
                
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                return 
PLUGIN_HANDLED
            
}
            
client_print(id,print_chat,"Say Bloqueado")
            
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
            return 
PLUGIN_HANDLED
        
}
        case 
:
        {
            if( 
does_containi_tag(name) )
                return 
PLUGIN_CONTINUE
            
            client_print
(id,print_chat,"Say Bloqueado")
            return 
PLUGIN_HANDLED
        
}
        case 
4:
        {
            if(
get_pcvar_float(pFreezetime) <= 0)
            {
                if(
containi(said,"/pausa") != -1)
                {
                    
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                    return 
PLUGIN_HANDLED
                
}
                
client_print(id,print_chat,"Say Bloqueado")
                
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
        case 
5:
        {
            if(
get_pcvar_float(pFreezetime) <= 0)
            {
                
client_print(id,print_chat,"Say Bloqueado")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
        case 
6:
        {
            if( 
does_containi_tag(name) )
                return 
PLUGIN_CONTINUE
            
            
if(get_pcvar_float(pFreezetime) <= 0)
            {
                if(
containi(said,"/pausa") != -1)
                {
                    
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                    return 
PLUGIN_HANDLED
                
}
                
client_print(id,print_chat,"Say Bloqueado")
                
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
        case 
:
        {
            if( 
does_containi_tag(name) )
                return 
PLUGIN_CONTINUE
            
            
if(get_pcvar_float(pFreezetime) <= 0)
            {
                
client_print(id,print_chat,"Say Bloqueado")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
    }        
    return 
PLUGIN_HANDLED
}  

bool:does_containi_tag(name_to_search[])
{
    for(new 
0sizeof(CanSay); i++)
    {
        if( 
containi(name_to_searchCanSay[i]) != -)
        {
            return 
true
        
}
    }
    return 
false

But, then I was thinking that it would be even more efficient if you hook infochanged and check there if they have the tag and have an boolean array for whether or not they have the appropriate tag and only checking the bool instead of looping everytime to search for it.
__________________

Last edited by fysiks; 05-12-2010 at 01:25.
fysiks is offline
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 05-12-2010 , 02:00   Re: Loop
Reply With Quote #5

I used this metod per case...
PHP Code:
for(new i;sizeof CanSay;i++)
containi(name,CanSay[i])
continue 
and this other...
PHP Code:
/*    
    mixm_nosaytype :
                         * 0 : Hablan los admins y muestra say /pausa.
                         * 1 : Hablan los admins y no muestra say /pausa.
             * 2 : Hablan los admins,permite hablar por freezetime y muestra say /pausa.
                         * 3 : Hablan los admins,permite hablar por freezetime y no muestra say /pausa
*/

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Chat Blocker"
#define VERSION "1.0"
#define AUTHOR "#8 SickneSS"

/* Chat Blocker */

new const CanSay[][] = 
{     
    
"[TL]",
    
"[CPT]",
    
"[CAPTAIN]" 
}

new 
NoSay
new CptCanSay
new NoSayType
new pFreezetime

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
NoSay register_cvar("mixm_nosay","0")
    
CptCanSay register_cvar("mixm_cptcansay","0")
    
NoSayType register_cvar("mixm_nosaytype","0")
    
pFreezetime get_cvar_pointer("mp_freezetime")
    
    
register_clcmd("say","HookSay")
    
register_clcmd("say /nosay","cmdSayNoSay",ADMIN_CVAR,"<Lock/Unlock the chat>")
}

public 
cmdSayNoSay(id,level,cid) {
    
    if(!
cmd_access(id,level,cid,1))  
        return 
PLUGIN_HANDLED
    
    
new adminname[32]
    
get_user_name(idadminname31)
    
    
set_pcvar_num(NoSay,get_pcvar_num(NoSay) == 0)
    
client_print(0,print_chat,"El Admin %s %sbloqueo el chat",adminnameget_pcvar_num(NoSay) ? "" "des")
    
    return 
PLUGIN_HANDLED
}

public 
HookSay(id) {
    
    if(!
get_pcvar_num(NoSay))
        return 
PLUGIN_CONTINUE
    
    
if(get_user_flags(id) & ADMIN_CHAT)
        return 
PLUGIN_CONTINUE
    
    
new name[32]
    
get_user_name(id,name,31)
    
    new 
said[192]
    
read_args(said,191)
    
    if(
get_pcvar_num(CptCanSay))
    {
        for(new 
i;sizeof CanSay;i++)
        if(
containi(name,CanSay[i]) != -1)
            return 
PLUGIN_CONTINUE
    
}
    
    switch(
get_pcvar_num(NoSayType))
    {    
        case 
:
        {        
            if(
containi(said,"/pausa") != -1)
            {
                
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                return 
PLUGIN_HANDLED
            
}
            
client_print(id,print_chat,"Say Bloqueado")
            
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
            return 
PLUGIN_HANDLED
        
}
        case 
:
        {
            
client_print(id,print_chat,"Say Bloqueado")
            return 
PLUGIN_HANDLED
        
}
        case 
2:
        {
            if(
get_pcvar_float(pFreezetime) <= 0)
            {
                if(
containi(said,"/pausa") != -1)
                {
                    
client_print(0,print_chat,"El jugador %s,esta pidiendo pausa",name)
                    return 
PLUGIN_HANDLED
                
}
                
client_print(id,print_chat,"Say Bloqueado")
                
client_print(id,print_chat,"Solo puedes escribir /pausa,para pedir pausear el juego")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
        case 
3:
        {
            if(
get_pcvar_float(pFreezetime) <= 0)
            {
                
client_print(id,print_chat,"Say Bloqueado")
                return 
PLUGIN_HANDLED
            
}
            return 
PLUGIN_CONTINUE
        
}
    }        
    return 
PLUGIN_HANDLED

about infochanged,I don't like them,because have some delay to check name
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-12-2010 , 02:06   Re: Loop
Reply With Quote #6

Quote:
Originally Posted by #8 SickneSS View Post
about infochanged,I don't like them,because have some delay to check name
There is no delay.

Code:
public client_infochanged( iPlayer ) {     new szNewName[ 32 ], szOldName[ 32 ];     get_user_info( iPlayer, "name", szNewName, charsmax( szNewName ) );     get_user_name( iPlayer, szOldName, charsmax( szOldName ) );         if( !equal( szOldName, szNewName ) )     {         // changed from 'szOldName' to 'szNewName'     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 05-12-2010 , 02:10   Re: Loop
Reply With Quote #7

I See,and understand, but,i wan't that ppl with [TL] - [CPT] - [CAPTAIN] in the name can use say..

Last edited by #8 SickneSS; 05-12-2010 at 02:16.
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-12-2010 , 02:17   Re: Loop
Reply With Quote #8

Quote:
Originally Posted by #8 SickneSS View Post
I See,and understand, but,i wan't that ppl with [TL] - [CPT] - [CAPTAIN] in the name can use say..
You already have the code for that.

PHP Code:
    if(get_pcvar_num(CptCanSay))
    {
        for(new 
i;sizeof CanSay;i++)
        if(
containi(name,CanSay[i]) != -1)
            return 
PLUGIN_CONTINUE
    

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
#8 SickneSS
BANNED
Join Date: Sep 2008
Location: Here
Old 05-12-2010 , 02:25   Re: Loop
Reply With Quote #9

Yes,but i wan't to make all in one cvar (ecept mixm_nosay (This block the chat)) putting the mixm_cptcansay in mixm_nosaytype

I wanted to know if I use a loop for each case using CanSay, would use more memory or something?

Last edited by #8 SickneSS; 05-12-2010 at 02:34.
#8 SickneSS is offline
Send a message via MSN to #8 SickneSS Send a message via Skype™ to #8 SickneSS
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-12-2010 , 14:37   Re: Loop
Reply With Quote #10

Quote:
Originally Posted by #8 SickneSS View Post
I wanted to know if I use a loop for each case using CanSay, would use more memory or something?
It shouldn't because only one case is executed.
__________________
fysiks 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 03:35.


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