09.04.2013, 17:00
(
Последний раз редактировалось fiki574; 10.04.2013 в 13:04.
)
NEW KICK & BAN
v1.1 - Update on 10.04.2013
INTRODUCTION:Hello!
Since I was inactive for a bit too long here on SAMP, decided to do some release(s) for this comunity! Anyways, this isn't actually something really "new", but eh, you'll see and judge it by yourself! This is also fix for a problem with kicking and baning while sending message to client which wouldn't be displayed to them!
Ever wanted to have a kick and ban function with exteneded parameters? Ever wanted to do something in just one line? Well, this include does that same thing - multiple stuff in one function! Proceed to further explanation down below...
Also, since the v1.1, there are 3 new disconnect reasons - DC_REASON_BAN ( 97 ), DC_REASON_KICK ( 98 ) and DC_REASON_BAN_IP ( 99 )! You can use them under "OnPlayerDisconnect" if you have leave messages system! I have fixed all warnings and errors in v1.1 that were accidentaly caused by my mistake!
__________________________________________________ __________________________________________________
EXPLANATION:
One and only function:
pawn Код:
native Client(...);
1. Step - Determing what you want to actually do with player
Do you want to kick them or ban them? Well, decide!
pawn Код:
Client(CLIENT_ACTION_BAN); //ban all players
pawn Код:
Client(CLIENT_ACTION_BAN_IP); //IP-ban all players
pawn Код:
Client(CLIENT_ACTION_KICK); //kick all players
pawn Код:
Client(CLIENT_ACTION_BAN, playerid); //bans player
pawn Код:
Client(CLIENT_ACTION_BAN_IP, playerid); //bans player IP and then kicks them
pawn Код:
Client(CLIENT_ACTION_KICK, playerid); //kicks player
2. Step - What kind of notification do you want?
There are 2 different choises to pick - notify wit message box or notify with message! Use following (I'll be using CLIENT_ACTION_KICK in all further explanations):
pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG);
pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_DIALOG);
3. Step - Do you want to notify someone about taken action? If yes, who?
Three possible choices - notify all players, notify single player or notify RCON admins (+ console print)! (proceeding with usage of NOTIFICATION_TYPE_MSG)
pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_ALL);
pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_PLAYER);
pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_RCON);
4. Step - Actual notifying
Again, two different choices - depending which NOTIFICATION_TYPE you are using! I'll provide you with 2 possible looks of this function!
pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_PLAYER, "You are kicked from this server!", 0xFF0000); //note the message and color code
pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_DIALOG, NOTIFY_PLAYER, "KICKED!", "You are kicked from this server!", "Close"); //note the 3 strings now - 1st one is dialog caption, 2nd one is info, and 3rd one is a button for a player to click!
pawn Код:
Client(CLIENT_ACTION_KICK, playerid, NOTIFICATION_TYPE_MSG, NOTIFY_PLAYER, "You are kicked from this server!"); //note the message, but color code is missing - therefore, will send a white message
__________________________________________________ _______________________________________________
CREDITS:
fiki574 - Creating this include
LarzI - Helping me understand how getarg() with arrays/strings
__________________________________________________ _______________________________________________
DOWNLOAD:
Code isn't too advanced/big, so I'll just post it here!
pawn Код:
#if defined _newkb_included
#endinput
#endif
#define _newkb_included
#define NOTIFICATION_TYPE_MSG (0)
#define NOTIFICATION_TYPE_DIALOG (1)
#define NOTIFY_ALL (2)
#define NOTIFY_PLAYER (3)
#define NOTIFY_RCON (4)
#define CLIENT_ACTION_KICK (5)
#define CLIENT_ACTION_BAN (6)
#define CLIENT_ACTION_BAN_IP (7)
#define DC_REASON_BAN (97)
#define DC_REASON_KICK (98)
#define DC_REASON_BAN_IP (99)
new KickTimer[MAX_PLAYERS], BanTimer[MAX_PLAYERS];
/*Natives:
native Client(...);
*/
stock Client(...)
{
new action = -1, playerid = INVALID_PLAYER_ID, notification = -1, notify_who = -1;
action = getarg(0);
playerid = getarg(1);
if(numargs() >= 2)
{
notification = getarg(2);
switch(notification)
{
case NOTIFICATION_TYPE_MSG:
{
notify_who = getarg(3);
new msg[100];
for(new k = 0; getarg(4, k) != 0; k++)
{
msg[k] = getarg(4,k);
}
new msgcolor = getarg(5);
switch(notify_who)
{
case NOTIFY_ALL:
{
SendClientMessageToAll(msgcolor, msg);
}
case NOTIFY_PLAYER:
{
SendClientMessage(playerid, msgcolor, msg);
}
case NOTIFY_RCON:
{
if(IsPlayerAdmin(playerid) == 1) SendClientMessage(playerid, msgcolor, msg);
printf("%s", msg);
}
}
}
case NOTIFICATION_TYPE_DIALOG:
{
notify_who = getarg(3);
new caption[20];
for(new k = 0; getarg(4, k) != 0; k++)
{
caption[k] = getarg(4,k);
}
new info[256];
for(new k = 0; getarg(5, k) != 0; k++)
{
info[k] = getarg(5,k);
}
new button[10];
for(new k = 0; getarg(6, k) != 0; k++)
{
button[k] = getarg(6,k);
}
switch(notify_who)
{
case NOTIFY_PLAYER:
{
ShowPlayerDialog(playerid,0,DIALOG_STYLE_MSGBOX,caption,info,button,"");
}
case NOTIFY_ALL, NOTIFY_RCON:
{
return 0;
}
}
}
}
switch(action)
{
case CLIENT_ACTION_BAN:
{
OnPlayerDisconnectEx(playerid, DC_REASON_BAN);
BanTimer[playerid] = SetTimerEx("BanPlayer", 100, false, "d", playerid);
if(numargs() == 1) for(new i = 0; i < MAX_PLAYERS; i++) OnPlayerDisconnectEx(playerid, DC_REASON_BAN), Ban(i);
}
case CLIENT_ACTION_KICK:
{
OnPlayerDisconnectEx(playerid, DC_REASON_KICK);
KickTimer[playerid] = SetTimerEx("KickPlayer", 100, false, "d", playerid);
if(numargs() == 1) for(new i = 0; i < MAX_PLAYERS; i++) OnPlayerDisconnectEx(i, DC_REASON_KICK), Kick(i);
}
case CLIENT_ACTION_BAN_IP:
{
OnPlayerDisconnectEx(playerid, DC_REASON_BAN_IP);
new ip[32];
GetPlayerIp(playerid,ip,sizeof(ip));
new banit[40];
format(banit,sizeof(banit),"banip %s", ip);
SendRconCommand(banit);
if(numargs() == 1)
{
new pip[32];
for(new i = 0; i < MAX_PLAYERS; i++)
{
GetPlayerIp(i,pip,sizeof(pip));
new banit2[40];
format(banit2,sizeof(banit2),"banip %s", ip);
SendRconCommand(banit2);
OnPlayerDisconnectEx(i, DC_REASON_BAN_IP);
}
}
KickTimer[playerid] = SetTimerEx("KickPlayer", 100, false, "d", playerid);
}
}
}
return 1;
}
forward KickPlayer(playerid);
public KickPlayer(playerid)
{
Kick(playerid);
KillTimer(KickTimer[playerid]);
return 0;
}
forward BanPlayer(playerid);
public BanPlayer(playerid)
{
Ban(playerid);
KillTimer(BanTimer[playerid]);
return 0;
}
forward OnPlayerDisconnectEx(playerid, reason);
public OnPlayerDisconnectEx(playerid, reason)
{
return CallLocalFunction("OnPlayerDisconnect", "dd", playerid, reason);
}
Regards,
Fiki!
P.S. I know I've maybe made this include (the include itself + presentation) a bit too complicated! :P