[Tutorial] Making /KickAll, /MuteAll & /UnMuteAll Commands.
#1

Introduction

Hello my fellows, today i decided to learn you or obviously give you a tutorial about this commands, /KickAll, /MuteAll, /Unmuteall, Maybe they are useless for real scripters, but will help beginner scripter's alot.


Requirements
-zcmd include
-a_samp include

Let we start,

Add this codes into your gamemode,filterscript.

PHP Code:
enum pInfo {
Level,
Muted,
MuteWarnings,
}; 
,

PHP Code:
new PNAME[MAX_PLAYER_NAME]; 
,

PHP Code:
enum ServerData
{
    
MaxMuteWarnings,
    
MaxAdminLevel,

,

PHP Code:
new ServerInfo[ServerData]; 

these enum's job is to define the MaxMuteWarnings, and MaxAdminLevel, And to see if this player has level, and if yes, which one, and also to see him if he is muted.



Step 1 - Kickall

Full Code
PHP Code:
CMD:kickall(playerid,params[]) {
    if(
PlayerInfo[playerid][Level] >= ||  IsPlayerAdmin(playerid))
        {
           for(new 
0MAX_PLAYERSi++) {
            if(
IsPlayerConnected(i) && (!= playerid) && != ServerInfo[MaxAdminLevel]) {
                
PlayerPlaySound(i,1057,0.0,0.0,0.0); Kick(i);
            }
        }
        new 
string[128]; format(string,sizeof(string),"Administrator '%s' has kicked all players"PNAME);
        
//SaveToFile("KickLog",string);
        
return SendClientMessageToAll(COLOR_LIGHTBLUEstring);
    } else return 
SendClientMessage(playeridred,"-Error You ain't high enough level to use this command");

Explaination:


The first line
PHP Code:
if(PlayerInfo[playerid][Level] >= ||  IsPlayerAdmin(playerid)) 
job's is to check if this player who used the command is admin level 5 or not, if you wont it for level 5 you can change it by replacing the level number instead of number 5, also it will work with Rcon admins.
----

the second couple of lines
PHP Code:
     for(new 0MAX_PLAYERSi++) {
            if(
IsPlayerConnected(i) && (!= playerid) && != ServerInfo[MaxAdminLevel]) 
is to check if player(s) is/are connected nor, also the max admin level.
----



the third line
PHP Code:
PlayerPlaySound(i,1057,0.0,0.0,0.0); Kick(i); 
job's is to kick the player(S).
----


the fours couple of lines
PHP Code:
new string[128]; format(string,sizeof(string),"Administrator %s has kicked all players"PNAME);
        
//SaveToFile("KickLog",string);
        
return SendClientMessageToAll(COLOR_LIGHTBLUEstring); 
job's is to send a message for all that admin (Name) has kicked all the players.
----


This line:
PHP Code:
} else return SendClientMessage(playeridred,"-Error You ain't high enough level to use this command");

job's is to deny the command if its used from a normal player, so it will send for him a dialog, telling him that you aint allowed to use this command.
----

This line's job is to save the kick-command in the server log file, so if you want it, remove the two slash's (//) and change the name of this file "KickLog" to your log file name, and if you wont it, dont do anything.
PHP Code:
//SaveToFile("KickLog",string); 


Step 2 - MuteAll

Full Code
PHP Code:
CMD:muteall(playerid,params[]) {
    if(
PlayerInfo[playerid][Level] >= ||  IsPlayerAdmin(playerid))
        {
           for(new 
0MAX_PLAYERSi++) {
            if(
IsPlayerConnected(i) && (!= playerid) && != ServerInfo[MaxAdminLevel]) {
                
PlayerPlaySound(i,1057,0.0,0.0,0.0); PlayerInfo[i][Muted] = 1PlayerInfo[i][MuteWarnings] = 0;
            }
        }
        new 
string[128]; format(string,sizeof(string),"Administrator '%s' has muted all players",PNAME);
        return 
SendClientMessageToAll(COLOR_LIGHTBLUEstring);
    } else return 
SendClientMessage(playeridred,"-Error You ain't high enough level to use this command");

Explaination:


It's all the same, just 1 thing different,
PHP Code:
PlayerPlaySound(i,1057,0.0,0.0,0.0); PlayerInfo[i][Muted] = 1PlayerInfo[i][MuteWarnings] = 0
And it's job is to mute, (so mute instead of kick, but it's abit the same code)
-----

Step 3 - UnMuteAll

Full Code
PHP Code:
CMD:unmuteall(playerid,params[]) {
    if(
PlayerInfo[playerid][Level] >= ||  IsPlayerAdmin(playerid))
        {
           for(new 
0MAX_PLAYERSi++) {
            if(
IsPlayerConnected(i) && (!= playerid) && != ServerInfo[MaxAdminLevel]) {
                
PlayerPlaySound(i,1057,0.0,0.0,0.0); PlayerInfo[i][Muted] = 0PlayerInfo[i][MuteWarnings] = 0;
            }
        }
        new 
string[128]; format(string,sizeof(string),"Administrator '%s' has unmuted all players",PNAME);
        return 
SendClientMessageToAll(COLOR_LIGHTBLUEstring);
    } else return 
SendClientMessage(playeridred,"-Error You ain't high enough level to use this command");

Explaination:


It's all the same, just 1 thing different,
PHP Code:
PlayerPlaySound(i,1057,0.0,0.0,0.0); PlayerInfo[i][Muted] = 0PlayerInfo[i][MuteWarnings] = 0
And it's job is to un mute all, (so unmute instead mute, but it's abit the same code)
-----



Full Code, with commands:
PHP Code:
#include <a_samp>
#include <zcmd>
#define COLOR_LIGHTBLUE 0x33CCFFAA
new PNAME[MAX_PLAYER_NAME];
enum pInfo {
Level,
Muted,
MuteWarnings,
};
new 
PlayerInfo[MAX_PLAYERS][pInfo];
enum ServerData
{
    
MaxMuteWarnings,
    
MaxAdminLevel,
}
new 
ServerInfo[ServerData];
CMD:kickall(playerid,params[]) {
    if(
PlayerInfo[playerid][Level] >= ||  IsPlayerAdmin(playerid))
        {
           for(new 
0MAX_PLAYERSi++) {
            if(
IsPlayerConnected(i) && (!= playerid) && != ServerInfo[MaxAdminLevel]) {
                
PlayerPlaySound(i,1057,0.0,0.0,0.0); Kick(i);
            }
        }
        new 
string[128]; format(string,sizeof(string),"Administrator '%s' has kicked all players"PNAME);
        
//SaveToFile("KickLog",string);
        
return SendClientMessageToAll(COLOR_LIGHTBLUEstring);
    } else return 
SendClientMessage(playeridred,"-Error You ain't high enough level to use this command");
}
CMD:muteall(playerid,params[]) {
    if(
PlayerInfo[playerid][Level] >= ||  IsPlayerAdmin(playerid))
        {
           for(new 
0MAX_PLAYERSi++) {
            if(
IsPlayerConnected(i) && (!= playerid) && != ServerInfo[MaxAdminLevel]) {
                
PlayerPlaySound(i,1057,0.0,0.0,0.0); PlayerInfo[i][Muted] = 1PlayerInfo[i][MuteWarnings] = 0;
            }
        }
        new 
string[128]; format(string,sizeof(string),"Administrator '%s' has muted all players",PNAME);
        return 
SendClientMessageToAll(COLOR_LIGHTBLUEstring);
    } else return 
SendClientMessage(playeridred,"-Error You ain't high enough level to use this command");
}
CMD:unmuteall(playerid,params[]) {
    if(
PlayerInfo[playerid][Level] >= ||  IsPlayerAdmin(playerid))
        {
           for(new 
0MAX_PLAYERSi++) {
            if(
IsPlayerConnected(i) && (!= playerid) && != ServerInfo[MaxAdminLevel]) {
                
PlayerPlaySound(i,1057,0.0,0.0,0.0); PlayerInfo[i][Muted] = 0PlayerInfo[i][MuteWarnings] = 0;
            }
        }
        new 
string[128]; format(string,sizeof(string),"Administrator '%s' has unmuted all players",PNAME);
        return 
SendClientMessageToAll(COLOR_LIGHTBLUEstring);
    } else return 
SendClientMessage(playeridred,"-Error You ain't high enough level to use this command");

This is my first tutorial, maybe there's some mistakes, if there's just appoint me. Thanks for reading my tutorial hope i helped you guys .
Reply
#2

Nice one, but here are some bad practices.

- Creating a dialog for the error ? You could use SendClientMessage.
- Define the dialogs, don't use random numbers.
Reply
#3

Thanks alot, but i used random numbers because there's some people migh be copying the code and paste it, so, as they are beginners, maybe they had another dialogs with the real-real-integer numbers like 1 2 3, so i used randomly due to that, as also, i dont see a problem with making it a dialog function, But anyways i changed it to be a sendclientmessage, just for you
Reply
#4

Quote:
Originally Posted by xXRevolverXx
View Post
Thanks alot, but i used random numbers because there's some people migh be copying the code and paste it, so, as they are beginners, maybe they had another dialogs with the real-real-integer numbers like 1 2 3, so i used randomly due to that, as also, i dont see a problem with making it a dialog function, But anyways i changed it to be a sendclientmessage, just for you
Thanks, but defining the dialog is good too.


EDIT: This not a tutorial WITHOUT explaining anything.
Reply
#5

Didn't explained stuffs well.

Didnt explained about loops.

"Job" is to do this, that.

Nah.
Reply
#6

oh okay, i told you guys that this is my first tutorial, i will try to obvious explain more.. sorry about that, @Karan007, and [ND]xXZeusXx..
Reply
#7

1. Why loop with MAX_PLAYERS?
From 0.3.7 we have GetPlayerPoolSize that get the highest playerid in use on the server.
2. You haven't defined "red" color.
3. PNAME is a blank variable because you haven't assigned nothing with GetPlayerName
4. You can use opposite condition instead of use a lots of brackets
5. "Level" variable in pInfo enum is never used
6. I don't understand this condition "i != ServerInfo[MaxAdminLevel]"
7. For a concept of order and code reading, uses a line for each instruction.

This is the correct script:
pawn Code:
CMD:kickall(playerid, params[]) {
    if(PlayerInfo[playerid][eLevel] < 5 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "-Error You ain't high enough level to use this command");
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) {
        PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
        Kick(i);
    }
    new szString[128];
    format(szString, sizeof szString, "Administrator '%s' has kicked all players", GetPlayerNameEx(playerid));
    SendClientMessage(playerid, COLOR_LIGHTBLUE, szString);
    return 1;
}
CMD:muteall(playerid, params[]) {
    if(PlayerInfo[playerid][eLevel] < 5 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "-Error You ain't high enough level to use this command");
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) {
        if(IsPlayerConnected(i) && (i != playerid)) {
            PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
            PlayerInfo[i][Muted] = 1;
            PlayerInfo[i][MuteWarnings] = 0;
        }
    }
    new szString[128];
    format(szString, sizeof szString, "Administrator '%s' has muted all players", GetPlayerNameEx(playerid));
    SendClientMessage(playerid, COLOR_LIGHTBLUE, szString);
    return 1;
}
CMD:unmuteall(playerid, params[]) {
    if(PlayerInfo[playerid][eLevel] < 5 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "-Error You ain't high enough level to use this command");
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) {
        if(IsPlayerConnected(i) && (i != playerid)) {
            PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
            PlayerInfo[i][Muted] = PlayerInfo[i][MuteWarnings] = 0;
        }
    }
    new szString[128];
    format(szString, sizeof szString, "Administrator '%s' has unmuted all players", GetPlayerNameEx(playerid));
    SendClientMessage(playerid, COLOR_LIGHTBLUE, szString);
    return 1;
}
GetPlayerNameEx(playerid) {
    new szName[MAX_PLAYER_NAME + 1];
    GetPlayerName(playerid, szName, sizeof szName);
    return szName;
}
Reply
#8

Quote:
Originally Posted by J4Rr3x
View Post
1. Why loop with MAX_PLAYERS?
From 0.3.7 we have GetPlayerPoolSize that get the highest playerid in use on the server.
2. You haven't defined "red" color.
3. PNAME is a blank variable because you haven't assigned nothing with GetPlayerName
4. You can use opposite condition instead of use a lots of brackets
5. "Level" variable in pInfo enum is never used
6. I don't understand this condition "i != ServerInfo[MaxAdminLevel]"
7. For a concept of order and code reading, uses a line for each instruction.

This is the correct script:
pawn Code:
CMD:kickall(playerid, params[]) {
    if(PlayerInfo[playerid][eLevel] < 5 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "-Error You ain't high enough level to use this command");
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) {
        PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
        Kick(i);
    }
    new szString[128];
    format(szString, sizeof szString, "Administrator '%s' has kicked all players", GetPlayerNameEx(playerid));
    SendClientMessage(playerid, COLOR_LIGHTBLUE, szString);
    return 1;
}
CMD:muteall(playerid, params[]) {
    if(PlayerInfo[playerid][eLevel] < 5 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "-Error You ain't high enough level to use this command");
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) {
        if(IsPlayerConnected(i) && (i != playerid)) {
            PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
            PlayerInfo[i][Muted] = 1;
            PlayerInfo[i][MuteWarnings] = 0;
        }
    }
    new szString[128];
    format(szString, sizeof szString, "Administrator '%s' has muted all players", GetPlayerNameEx(playerid));
    SendClientMessage(playerid, COLOR_LIGHTBLUE, szString);
    return 1;
}
CMD:unmuteall(playerid, params[]) {
    if(PlayerInfo[playerid][eLevel] < 5 || !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, red, "-Error You ain't high enough level to use this command");
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) {
        if(IsPlayerConnected(i) && (i != playerid)) {
            PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
            PlayerInfo[i][Muted] = PlayerInfo[i][MuteWarnings] = 0;
        }
    }
    new szString[128];
    format(szString, sizeof szString, "Administrator '%s' has unmuted all players", GetPlayerNameEx(playerid));
    SendClientMessage(playerid, COLOR_LIGHTBLUE, szString);
    return 1;
}
GetPlayerNameEx(playerid) {
    new szName[MAX_PLAYER_NAME + 1];
    GetPlayerName(playerid, szName, sizeof szName);
    return szName;
}
No, Level, is definitely used, see in every command, if player info, level = 5 , so .. anyways, it's okay as i dont see much problems to correct, Red? i dont need to define colors as you (target whatever who) are going to change it, and you didnt appointed any other thing, completly a useless reply.
Reply
#9

Use GetPlayerPoolSize, way better.
Reply
#10

Quote:
Originally Posted by xXRevolverXx
View Post
No, Level, is definitely used, see in every command, if player info, level = 5 , so .. anyways, it's okay as i dont see much problems to correct, Red? i dont need to define colors as you (target whatever who) are going to change it, and you didnt appointed any other thing, completly a useless reply.
r u serious? You need to define color or insted just put it in the instruction.
Then, do what you want, i was only advice you.

I can only imagine gm will come out.
Good luck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)