Raised This Month: $ Target: $400
 0% 

[SOLVED]Variable for every player [Help]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 12-02-2010 , 21:16   Re: Variable for every player [Help]
Reply With Quote #1

You have the array right, but you can improve that function.

If comparing the value of a variable to many thing, like you did, suggest using a switch like this:
PHP Code:
public kick(id)
{
    switch(
warning[id])
    {
        case 
0:
        {
            
client_print(idprint_chat,"[Whatch your lang] Warning: 1/3")
            
            
warning[id]++
        }
        
        case 
1:
        {
            
client_print(idprint_chat,"[Whatch your lang] Warning: 2/3")
            
warning[id]++
        }
        
        case 
2:
        {
            
client_print(idprint_chat,"[Whatch your lang] Warning: 3/3 Next time you will get kicked")
            
warning[id]++
        }
        
        case 
3:
        {
            
client_cmd(id,"echo Kicked from server! Next time please mind you language or end up with a ban!")
            
client_cmd(id,"disconnect")
            
warning[id]++
        }
        
        case 
4:
        {
            
client_print(idprint_chat,"[Whatch your lang] BANNED!")
            
warning[id]= 0
        
}
    }

I would make this function like this:
PHP Code:
public kick(id)
{
    
warning++;
    
    if(
warning[id] == 4)
    {
        
client_print(idprint_chat"[Watch your lang] BANNED!");
        
warning[id] = 0;
        
        return 
PLUGIN_HANDLED;
    }
    
    else
        
client_print(idprint_chat"[Watch your lang] %i/4"warning[id]);

    return 
PLUGIN_HANDLED;

EDIT: Hi fysiks
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Callesson
Member
Join Date: Jan 2010
Old 12-02-2010 , 21:22   Re: Variable for every player [Help]
Reply With Quote #2

Ty so much
So easy ^^

Can you also explain why i'm gonna use "[33]" ?
What does that mean?
__________________
Callesson is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-02-2010 , 21:34   Re: Variable for every player [Help]
Reply With Quote #3

Quote:
Originally Posted by Callesson View Post
Can you also explain why i'm gonna use "[33]" ?
What does that mean?
Arrays are indexed starting at zero so when you dimension it with 33 the first index is 0, the second is 1, and so on, leaving the last one at 32. Player ids range from 1 to 32. If you only used 32 for the dimension then there would be no 32 index, the last index would be 31 (aka warning[32] would not exist).
__________________
fysiks is offline
Callesson
Member
Join Date: Jan 2010
Old 12-03-2010 , 14:38   Re: Variable for every player [Help]
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
Arrays are indexed starting at zero so when you dimension it with 33 the first index is 0, the second is 1, and so on, leaving the last one at 32. Player ids range from 1 to 32. If you only used 32 for the dimension then there would be no 32 index, the last index would be 31 (aka warning[32] would not exist).
Auw Cool ^^ Thanks
Quote:
Originally Posted by drekes View Post
cool, thanks for the info.
You learn something new every day

And TY Bugsy
__________________
Callesson is offline
Callesson
Member
Join Date: Jan 2010
Old 12-03-2010 , 15:03   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #5

Sorry for double post!
But I changed the code to this. Now it fits my goal better
Does it look alright ?
Code:
public kick( id )
{
    if( warning[ id ] == 2 )
    {
        client_print( id , print_chat , "[Watch your lang] Next time ban!" );
        warning[ id ] = 3;
    }
    else if( warning[ id ] == 3 )
    {
        client_print( id , print_chat , "[Watch your lang] BANNED!" );
        warning[ id ] = 0;
    }
    else if ( ++warning[ id ] !=2 || warning[ id ] != 3)
    {
        client_print( id , print_chat , "[Watch your lang] %i/3" , warning[ id ] );
    }

    return PLUGIN_HANDLED;
}
__________________
Callesson is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-03-2010 , 16:32   Re: [SOLVED]Variable for every player [Help]
Reply With Quote #6

Would be better to use a switch.

Code:
public kick( id ) {     switch( warning[ id ] )     {         case 2:         {             client_print( id , print_chat , "[Watch your lang] Next time ban!" );             warning[ id ]++;         }         case 3:         {             client_print( id , print_chat , "[Watch your lang] BANNED!" );             warning[ id ] = 0;         }         default:         {             client_print( id , print_chat , "[Watch your lang] %i/3" , warning[ id ] );             warning[ id ]++;         }     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-02-2010 , 21:22   Re: Variable for every player [Help]
Reply With Quote #7

Quote:
Originally Posted by drekes View Post
EDIT: Hi fysiks
I was thinking about mentioning your second version but really depends on what else he wants to do.
__________________
fysiks is offline
Callesson
Member
Join Date: Jan 2010
Old 12-02-2010 , 21:31   Re: Variable for every player [Help]
Reply With Quote #8

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 #9

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