Raised This Month: $ Target: $400
 0% 

[SOLVED]Variable for every player [Help]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Callesson
Member
Join Date: Jan 2010
Old 12-02-2010 , 21:31   Re: Variable for every player [Help]
Reply With Quote #1

The second version was nice

EDIT:
I would love a little bit more help. But now i gotta go to sleep!
Night
And thank you again!
__________________

Last edited by Callesson; 12-02-2010 at 21:35.
Callesson is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 12-02-2010 , 21:51   Re: Variable for every player [Help]
Reply With Quote #2

Quote:
Originally Posted by fysiks View Post
I was thinking about mentioning your second version but really depends on what else he wants to do.
Yeah, i wrote it from the code he has made now. So he can see if that fits him well or not.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-02-2010 , 23:10   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #3

In the switch method/version, you should put warning[id]++ outside of the switch because you want to avoid duplicate code whenever possible. switch ( ++warning[ id ] ) would probably be best for that type of usage.

For the OP's particular case, your second code is best:
PHP Code:
//be sure to set warning[ id ] = 0 at client_disconnect

public kickid )
{
    if( ++
warningid ] == )
    {
        
client_printid print_chat "[Watch your lang] BANNED!" );
        
warningid ] = 0;
    }
    else
    {
        
client_printid print_chat "[Watch your lang] %i/4" warningid ] );
    }

    return 
PLUGIN_HANDLED;

__________________

Last edited by Bugsy; 12-02-2010 at 23:58.
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 12-03-2010 , 10:52   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #4

Quote:
Originally Posted by Bugsy View Post
In the switch method/version, you should put warning[id]++ outside of the switch because you want to avoid duplicate code whenever possible. switch ( ++warning[ id ] ) would probably be best for that type of usage.

For the OP's particular case, your second code is best:
PHP Code:
//be sure to set warning[ id ] = 0 at client_disconnect

public kickid )
{
    if( ++
warningid ] == )
    {
        
client_printid print_chat "[Watch your lang] BANNED!" );
        
warningid ] = 0;
    }
    else
    {
        
client_printid print_chat "[Watch your lang] %i/4" warningid ] );
    }

    return 
PLUGIN_HANDLED;

So (++warning[id] == 4) will add 1 to warning[id] even if the if statement isn't executed ?
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-03-2010 , 13:36   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #5

Quote:
Originally Posted by drekes View Post
So (++warning[id] == 4) will add 1 to warning[id] even if the if statement isn't executed ?
The conditional is always checked. Also, ++ before the variable means that it will use the value after being incremented to compare to 4, FYI.
__________________
fysiks is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 12-03-2010 , 11:14   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #6

Yes.
__________________
hleV is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 12-03-2010 , 12:34   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #7

cool, thanks for the info.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 12-03-2010 , 13:58   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #8

Thanks, i never was sure about what the ++ before it did.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-03-2010 , 13:59   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #9

You may see something similar in conditional/while statements.

This will do both assign the return value to iVar and check the condition (check if return value != 0 in this case). You can then use iVar in the if code block.
PHP Code:
new iVar
if ( ( iVar get_user_fragsid ) ) )
{
    
//iVar != 0 
__________________
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 12-03-2010 , 14:10   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #10

Cool, I got one more question.
I've found this kind of loop in some blockmaker code.
PHP Code:
for(new 1<= g_iMaxPlayers; ++i
Does that make any difference with this one :
PHP Code:
for(new 1<= g_iMaxPlayersi++) 
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
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:23.


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