AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ban all CTs in a loop (https://forums.alliedmods.net/showthread.php?t=92476)

Cader 05-15-2009 19:13

Ban all CTs in a loop
 
Hello.

How can I "ban" all CTs by their IPs using a loop? And of course with the opposite team, Terrorists.

Hunter-Digital 05-16-2009 15:42

Re: Ban all CTs in a loop
 
PHP Code:

new maxPlayers get_maxplayers()
 
for(new 
1<= maxPlayersp++)
{
     if(!
is_user_connected(p) || get_user_team(p) != 2)
           continue
 
     
server_cmd("amx_banip #%d ^"because you are a CT^""get_user_userid(p))


:lol:

joaquimandrade 05-16-2009 15:47

Re: Ban all CTs in a loop
 
I don't understand why everybody use continues and returns instead of making the code to be read like what it does:

PHP Code:

new maxPlayers get_maxplayers()
 
for(new 
1<= maxPlayersp++)
{
     if(
is_user_connected(p) && get_user_team(p) == 2
     {
        
server_cmd("amx_banip #%d ^"because you are a CT^""get_user_userid(p))
     }



Hunter-Digital 05-16-2009 15:52

Re: Ban all CTs in a loop
 
To avoid the damn brackets xD and also if the code in the loop is big and I just want suddenly to add a check to the whole code, like if the user is alive or something

tell me one good reason why I shouldn't use return and continue instead of brackets and I'll understand :)

fysiks 05-16-2009 16:54

Re: Ban all CTs in a loop
 
Quote:

Originally Posted by Hunter-Digital (Post 828743)
To avoid the damn brackets xD and also if the code in the loop is big and I just want suddenly to add a check to the whole code, like if the user is alive or something

tell me one good reason why I shouldn't use return and continue instead of brackets and I'll understand :)

Is it big? I think you answered it yourself.

Exolent[jNr] 05-16-2009 17:03

Re: Ban all CTs in a loop
 
If I want to do one action with that loop, then I use continue.
If I want to do 2 different actions that depend on something about the individual index of the loop, then I use if() and else[ if]().

Hunter-Digital 05-16-2009 17:36

Re: Ban all CTs in a loop
 
Quote:

Originally Posted by fysiks (Post 828792)
Is it big? I think you answered it yourself.

I wasn't talking about this code, I said IF my code inside the loop WOULD BE big... :)

Still, I like the code to be in a row... not too far off pushed to the right, if I do an if() with brackets on everything I get to have 5-10 open brackets (again, generaly speaking, not this code, this is small but I'm used to use continue and return, I also do this in php :P)

I use continue whenever I need to skip everything else... if I need to choose between two or more things I use if(), else if(), switch() etc...

joaquimandrade 05-16-2009 18:43

Re: Ban all CTs in a loop
 
PHP Code:

 
for(new 1<= maxPlayersp++)
{
     if(!
is_user_connected(p) || get_user_team(p) != 2)
           continue
 
     
server_cmd("amx_banip #%d ^"because you are a CT^""get_user_userid(p))


For each player: if he is not connected or his team is not the number 2, continue. Ban him.

PHP Code:

for(new 1<= maxPlayersp++)
{
     if(
is_user_connected(p) && get_user_team(p) == 2
     {
        
server_cmd("amx_banip #%d ^"because you are a CT^""get_user_userid(p))
     }


For each player: if he is connected and his team is the number 2 ban him.

__

And i don't know why do you want to avoid braces. Braces make that different code blocks look like different code blocks.

jediZEr0 05-17-2009 06:42

Re: Ban all CTs in a loop
 
Is there a way to ban an amount of random players from a team?

fysiks 05-18-2009 02:58

Re: Ban all CTs in a loop
 
Quote:

Originally Posted by joaquimandrade (Post 828849)
And i don't know why do you want to avoid braces. Braces make that different code blocks look like different code blocks.

I agree, I love braces, they are my only friends :). lol

Quote:

Originally Posted by jediZEr0 (Post 829142)
Is there a way to ban an amount of random players from a team?

huh? Why would anyone want to do something like that?


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

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