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

Ban all CTs in a loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cader
Senior Member
Join Date: Mar 2007
Old 05-15-2009 , 19:13   Ban all CTs in a loop
Reply With Quote #1

Hello.

How can I "ban" all CTs by their IPs using a loop? And of course with the opposite team, Terrorists.
Cader is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-16-2009 , 15:42   Re: Ban all CTs in a loop
Reply With Quote #2

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))

__________________
Hunter-Digital is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-16-2009 , 15:47   Re: Ban all CTs in a loop
Reply With Quote #3

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))
     }

__________________
joaquimandrade is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-16-2009 , 15:52   Re: Ban all CTs in a loop
Reply With Quote #4

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
__________________
Hunter-Digital is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-16-2009 , 16:54   Re: Ban all CTs in a loop
Reply With Quote #5

Quote:
Originally Posted by Hunter-Digital View Post
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.
__________________
fysiks is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-16-2009 , 17:03   Re: Ban all CTs in a loop
Reply With Quote #6

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]().
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-16-2009 , 17:36   Re: Ban all CTs in a loop
Reply With Quote #7

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

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...
__________________
Hunter-Digital is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-16-2009 , 18:43   Re: Ban all CTs in a loop
Reply With Quote #8

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.
__________________
joaquimandrade is offline
jediZEr0
Member
Join Date: Jan 2009
Location: In the Middle of Nowhere
Old 05-17-2009 , 06:42   Re: Ban all CTs in a loop
Reply With Quote #9

Is there a way to ban an amount of random players from a team?
jediZEr0 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-18-2009 , 02:58   Re: Ban all CTs in a loop
Reply With Quote #10

Quote:
Originally Posted by joaquimandrade View Post
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 View Post
Is there a way to ban an amount of random players from a team?
huh? Why would anyone want to do something like that?
__________________
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 11:48.


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