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 , 20:20   [SOLVED]Variable for every player [Help]
Reply With Quote #1

Hello guys

I am new to plugin scripting and I have started working on a test plugin.
My plugin is going to kick or ban you if you say a bad word to many times.
My problem is that the variable "warning" is not unique for each player.
So my question is, how can I make it unique for each player?
Code:
new warning = 0

public kick(id)
{
    if(warning == 0)
    {
        client_print(id, print_chat,"[Whatch your lang] Warning: 1/3")
        
        warning++
    }
    else if(warning == 1)
    {
        client_print(id, print_chat,"[Whatch your lang] Warning: 2/3")
        warning++
    }
    else if(warning == 2)
    {
        client_print(id, print_chat,"[Whatch your lang] Warning: 3/3 Next time you will get kicked")
        warning++
    }
    else if(warning == 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++
    }
    else if(warning == 4)
    {
        client_print(id, print_chat,"[Whatch your lang] BANNED!")
        warning = 0
    }
}
__________________

Last edited by Callesson; 12-02-2010 at 21:34. Reason: Typo
Callesson is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-02-2010 , 20:56   Re: Variable for every player [Help]
Reply With Quote #2

Use an array dimensioned with 33 and use it with id as the index.
__________________
fysiks is offline
Callesson
Member
Join Date: Jan 2010
Old 12-02-2010 , 21:00   Re: Variable for every player [Help]
Reply With Quote #3

Like this?
Code:
new warning[33] = 0

public kick(id)
{
    if(warning[id] == 0)
    {
        client_print(id, print_chat,"[Whatch your lang] Warning: 1/3")
        
        warning[id]++
    }
    else if(warning[id] == 1)
    {
        client_print(id, print_chat,"[Whatch your lang] Warning: 2/3")
        warning[id]++
    }
    else if(warning[id] == 2)
    {
        client_print(id, print_chat,"[Whatch your lang] Warning: 3/3 Next time you will get kicked")
        warning[id]++
    }
    else if(warning[id]== 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]++
    }
    else if(warning[id]== 4)
    {
        client_print(id, print_chat,"[Whatch your lang] BANNED!")
        warning[id]= 0
    }
}
__________________

Last edited by Callesson; 12-02-2010 at 21:00. Reason: Miss
Callesson is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-02-2010 , 21:13   Re: Variable for every player [Help]
Reply With Quote #4

Yes. However, you can optimize it with a switch

Code:
switch(warning[id])
{
	case 0:
	{
		// stuff
	}
	case 1:
	{
		// stuff
	}
}
__________________
fysiks is offline
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 #5

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

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

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

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

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

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
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:19.


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