AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED]Variable for every player [Help] (https://forums.alliedmods.net/showthread.php?t=144371)

Callesson 12-02-2010 20:20

[SOLVED]Variable for every player [Help]
 
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
    }
}


fysiks 12-02-2010 20:56

Re: Variable for every player [Help]
 
Use an array dimensioned with 33 and use it with id as the index.

Callesson 12-02-2010 21:00

Re: Variable for every player [Help]
 
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
    }
}


fysiks 12-02-2010 21:13

Re: Variable for every player [Help]
 
Yes. However, you can optimize it with a switch

Code:


switch(warning[id])
{
        case 0:
        {
                // stuff
        }
        case 1:
        {
                // stuff
        }
}


drekes 12-02-2010 21:16

Re: Variable for every player [Help]
 
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

Callesson 12-02-2010 21:22

Re: Variable for every player [Help]
 
Ty so much :)
So easy ^^

Can you also explain why i'm gonna use "[33]" ?
What does that mean?

fysiks 12-02-2010 21:22

Re: Variable for every player [Help]
 
Quote:

Originally Posted by drekes (Post 1361798)
EDIT: Hi fysiks

I was thinking about mentioning your second version but really depends on what else he wants to do. :)

Callesson 12-02-2010 21:31

Re: Variable for every player [Help]
 
The second version was nice :P

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

fysiks 12-02-2010 21:34

Re: Variable for every player [Help]
 
Quote:

Originally Posted by Callesson (Post 1361801)
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).

drekes 12-02-2010 21:51

Re: Variable for every player [Help]
 
Quote:

Originally Posted by fysiks (Post 1361803)
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.


All times are GMT -4. The time now is 11:23.

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