Help Systeme ban / kick
#1

hello i search a good code pawn for ban/kick system ; anyone can help me please ?
Reply
#2

Here you go dude:

/kick Command:
Код:
  CMD:kick(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] >= 3) {
            new PID; //define the playerid we wanna kick
            new reason[64]; //the reason, put into a string
            new str[128]; //a new message string
            new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; //defines the function with the playername we wanna get
            GetPlayerName(playerid, Adminname, sizeof(Adminname)); //defines the function with the adminname we wanna get
 	  		GetPlayerName(PID, Playername, sizeof(Playername));
            if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]"); //tell sscanf if the parameters/the syntax is written wrong to return a message (PID and the reason used here)

            if(!IsPlayerConnected(PID)) // if the ID is wrong or not connected, return a message! (PID used here)
                return SendClientMessage(playerid, COLOR_GREY, "Player is not connected!");

            format(str, sizeof(str), "'%s' has been kicked by administrator '%s'. Reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
		SendClientMessageToAll(COLOR_RED, str); //send that message to all
  		Kick(PID); //kick the playerid we've defined

        }
        else //if he has not got the permissions
        {
            SendClientMessage(playerid, COLOR_GREY, "You have to be level 3 to use that command!"); //return this message
        }
        return 1;
    }
And the /ban command:

Код:
CMD:ban(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] >= 3) {
            new PID; //define the playerid we wanna ban
            new reason[64]; //the reason, put into a string
            new str[128]; //a new message string
            new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; //defines the function with the playername we wanna get
            GetPlayerName(playerid, Adminname, sizeof(Adminname)); //defines the function with the adminname we wanna get
 	  		GetPlayerName(PID, Playername, sizeof(Playername));
            if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]"); //tell sscanf if the parameters/the syntax is written wrong to return a message (PID and the reason used here)

            if(!IsPlayerConnected(PID)) // if the ID is wrong or not connected, return a message! (PID used here)
                return SendClientMessage(playerid, COLOR_GREY, "Player is not connected!");

            format(str, sizeof(str), "'%s' has been banned by administrator '%s'. Reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
		SendClientMessageToAll(COLOR_RED, str); //send that message to all
  		Ban(PID); //Ban the playerid we've defined

        }
        else //if he has not got the permissions
        {
            SendClientMessage(playerid, COLOR_GREY, "You have to be level 5 to use that command!"); //return this message
        }
        return 1;
    }
Make sure you add these in either a filterscript or your gamemode at the end. Also make sure that you have ZCMD include.

If I helped you, please REP+ me.
Reply
#3

Kick cmd:
PHP код:
CMD:kick(playeridparams[])
{
    if(
PlayerInfo[playerid][AdminLevel] < 1) return 0;
       new 
targetplayerreason[50];
    if(
sscanf(params"u"targetplayer)) return SendClientMessage(playeridCOLOR_ORANGE"Usage: /kick [ID] (Reason)");
    
sscanf(params"us[50]"targetplayerreason);
    if(!
IsPlayerConnected(targetplayer)) return SendClientMessage(playeridCOLOR_RED"Error: Player is not connected!");
    
    if(
targetplayer == playerid)
    return 
SendClientMessage(playeridCOLOR_RED"Error: You cannot kick yourself!");

    new 
string[150], pName[MAX_PLAYER_NAME], pName2[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
    
GetPlayerName(targetplayerpName2MAX_PLAYER_NAME);
    
format(stringsizeof string"~ %s has been kicked from the server for '%s'"pNamereason);
    
SetTimerEx("DelayedKick"50false"i"targetplayer);
       
printf("[KICK] %s has kicked %s from the server"pNamepName2);
    
SendClientMessageToAll(COLOR_REDstring);
       return 
1;
}
forward DelayedKick(playerid);
public 
DelayedKick(playeridKick(playerid); 
Ban cmd:
PHP код:
CMD:ban(playeridparams[])
{
    if(
PlayerInfo[playerid][AdminLevel] < 1) return 0;
    if(
PlayerInfo[playerid][AdminLevel] < 2) return SendClientMessage(playeridCOLOR_YELLOWGREEN"Error: You are not authorized to use this command.");
       new 
targetplayerreason[50];
       if(
sscanf(params"u"targetplayer)) return SendClientMessage(playeridCOLOR_ORANGE"Usage: /ban [ID] (Reason)");
       
sscanf(params"us[50]"targetplayerreason);
       if(!
IsPlayerConnected(targetplayer)) return SendClientMessage(playeridCOLOR_RED"Error: Player is not connected!");

       if(
targetplayer == playerid)
       return 
SendClientMessage(playeridCOLOR_RED"Error: You cannot ban yourself!");

       new 
string[150], pName[MAX_PLAYER_NAME], pName2[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
       
GetPlayerName(targetplayerpName2MAX_PLAYER_NAME);
       
format(stringsizeof string"~ %s has been banned from the server for '%s'"pNamereason);
       
SetTimerEx("DelayedBan"50false"i"targetplayer);
       
printf("[BAN] %s has banned %s from the server"pNamepName2);
       
SendClientMessageToAll(COLOR_REDstring);
       return 
1;
}
forward DelayedBan(playerid);
public 
DelayedBan(playeridBan(playerid); 
Note: The cmds I gave, includes SetTimerEx so the banned/kicked player receives a message. and it icnludes a printf(); that means, you will get a message if the cmd is executed by any other admin.
Reply
#4

Quote:
Originally Posted by VoltMeter
Посмотреть сообщение
Here you go dude:

/kick Command:
Код:
  CMD:kick(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] >= 3) {
            new PID; //define the playerid we wanna kick
            new reason[64]; //the reason, put into a string
            new str[128]; //a new message string
            new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; //defines the function with the playername we wanna get
            GetPlayerName(playerid, Adminname, sizeof(Adminname)); //defines the function with the adminname we wanna get
 	  		GetPlayerName(PID, Playername, sizeof(Playername));
            if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]"); //tell sscanf if the parameters/the syntax is written wrong to return a message (PID and the reason used here)

            if(!IsPlayerConnected(PID)) // if the ID is wrong or not connected, return a message! (PID used here)
                return SendClientMessage(playerid, COLOR_GREY, "Player is not connected!");

            format(str, sizeof(str), "'%s' has been kicked by administrator '%s'. Reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
		SendClientMessageToAll(COLOR_RED, str); //send that message to all
  		Kick(PID); //kick the playerid we've defined

        }
        else //if he has not got the permissions
        {
            SendClientMessage(playerid, COLOR_GREY, "You have to be level 3 to use that command!"); //return this message
        }
        return 1;
    }
And the /ban command:

Код:
CMD:ban(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] >= 3) {
            new PID; //define the playerid we wanna ban
            new reason[64]; //the reason, put into a string
            new str[128]; //a new message string
            new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; //defines the function with the playername we wanna get
            GetPlayerName(playerid, Adminname, sizeof(Adminname)); //defines the function with the adminname we wanna get
 	  		GetPlayerName(PID, Playername, sizeof(Playername));
            if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /kick [playerid] [reason]"); //tell sscanf if the parameters/the syntax is written wrong to return a message (PID and the reason used here)

            if(!IsPlayerConnected(PID)) // if the ID is wrong or not connected, return a message! (PID used here)
                return SendClientMessage(playerid, COLOR_GREY, "Player is not connected!");

            format(str, sizeof(str), "'%s' has been banned by administrator '%s'. Reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
		SendClientMessageToAll(COLOR_RED, str); //send that message to all
  		Ban(PID); //Ban the playerid we've defined

        }
        else //if he has not got the permissions
        {
            SendClientMessage(playerid, COLOR_GREY, "You have to be level 5 to use that command!"); //return this message
        }
        return 1;
    }
Make sure you add these in either a filterscript or your gamemode at the end. Also make sure that you have ZCMD include.

If I helped you, please REP+ me.
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 81) : warning 203: symbol is never used: "ban"
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 81) : warning 203: symbol is never used: "kick"
Reply
#5

#Define ban

#define kick
Reply
#6

If you use mine cmds, you won't get errors tho..
Reply
#7

Quote:
Originally Posted by 59GVR6
Посмотреть сообщение
#Define ban

#define kick
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 34) : error 010: invalid function or declaration
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 35) : error 010: invalid function or declaration
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 37) : error 010: invalid function or declaration
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 39) : error 010: invalid function or declaration
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 41) : error 010: invalid function or declaration
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 42) : error 010: invalid function or declaration
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 45) : error 021: symbol already defined: "GetPlayerName"
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 51) : error 010: invalid function or declaration
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 55) : warning 203: symbol is never used: "pName"
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 55) : warning 203: symbol is never used: "pName2"
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 55) : warning 203: symbol is never used: "reason"
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 55) : warning 203: symbol is never used: "string"
C:\gamemodes\monscript\gamemodes\DeathPlanet.pwn(3 55) : warning 203: symbol is never used: "targetplayer"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


9 Errors.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)