#include <sscanf2> // include the sscanf file
#include <zcmd> // include the zcmd file
new Warns[MAX_PLAYERS]; // global variable to check if a player is muted
forward KickTimer(playerid); // a kick timer we will use, since the update of 0.3x secures something that means the player can't see why he got kicked
public KickTimer(playerid)
{
Kick(playerid); // this will kick the player that we will be forwarding the ID of once we do the /warn command and the warn level is 3
return 1;
}
public OnPlayerConnect(playerid)
{
Warns[playerid] = 0; // this will reset the warns to 0, so if the previous player who logged out with the same ID had a warn, the new player won't get it
return 1; // don't add this if you've already got it at the bottom of your OnPlayerConnect
}
CMD:warn(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return 0; // this will return "SERVER: Unknown command." if the player who entered the command is not an RCON admin, change this with your own variable of course
new giveplayerid, reason[50]; // make 2 new variables that we'll use with sscanf, we can do the rest later because if we don't use the rest now, it'll go to waste
if(sscanf(params, "us[50]", giveplayerid, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /warn [playerid/name] [reason]"); // will return with this message if the player entered a wrong syntax
if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFFF, "Player not connected."); // will return this message if the player's not connected
new string[150], sender[MAX_PLAYER_NAME], receiver[MAX_PLAYER_NAME]; // creates the rest of the variables, as we'll be needing them now
GetPlayerName(playerid, sender, sizeof(sender)); // get the player's name
GetPlayerName(giveplayerid, receiver, sizeof(receiver)); // get the other player's name
format(string, sizeof(string), "%s (%d) was warned by %s (%d), reason: %s (%d/3)", receiver, giveplayerid, sender, playerid, reason, Warns[giveplayerid]+1); // sets the string
SendClientMessageToAll(0x00FFFFFF, string); // will send the formatted message
if(Warns[playerid] == 2) // this will check if the player's warns are equal to 2, because adding 1 will result in 3 which is a kick, of course
{
format(string, sizeof(string), "%s (%d) was automatically kicked, reason: had 3 warnings", receiver, giveplayerid); // sets the string once again
SendClientMessageToAll(0x00FFFFFF, string); // will send the formatted message
SetTimerEx("KickTimer", 1000, false, "i", giveplayerid); // forwards the giveplayerid to be kicked, with regards to the KickTimer that we created earlier
}
else // otherwise, if the player's warn level is less than 2
{
Warns[giveplayerid] ++; // warn up
GameTextForPlayer(giveplayerid, "~r~warned~n~~w~check the chat", 5000, 6); // sends a game text so the player will notice
}
return 1;
}
CMD:unwarn(playerid, params[], help)
{
if(!IsPlayerAdmin(playerid)) return 0; // this will return "SERVER: Unknown command." if the player who entered the command is not an RCON admin, change this with your own variable of course
new giveplayerid, reason[50]; // make 2 new variables that we'll use with sscanf, we can do the rest later because if we don't use the rest now, it'll go to waste
if(sscanf(params, "us[50]", giveplayerid, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /unwarn [playerid/name] [reason]"); // will return with this message if the player entered a wrong syntax
if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFFF, "Player not connected."); // will return this message if the player's not connected
if(Warns[giveplayerid] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "That player already has 0 warnings."); // this will check if the player's warnings are equal to 0, and if so it will return this message
new string[150], sender[MAX_PLAYER_NAME], receiver[MAX_PLAYER_NAME]; // creates the rest of the variables, as we'll be needing them now
GetPlayerName(playerid, sender, sizeof(sender)); // get the player's name
GetPlayerName(giveplayerid, receiver, sizeof(receiver)); // get the other player's name
format(string, sizeof(string), "%s (%d) was unwarned by %s (%d), reason: %s (%d/3)", receiver, giveplayerid, sender, playerid, reason, Warns[giveplayerid]-1); // sets the string
SendClientMessageToAll(0x00FFFFFF, string); // will send the formatted message
GameTextForPlayer(giveplayerid, "~g~unwarned~n~~w~check the chat", 5000, 6); // sends a game text so the player will notice
Warns[giveplayerid] --; // unwarn the player by 1 point
return 1;
}
Warns[giveplayerid] = +1;
Warns[giveplayerid]++;
Kick(gaveplayerid);
why did you use timer to kick the receiver, can't you replace it with:
pawn Code:
|
Important Note: As of SA-MP 0.3x, any action taken before Kick() (such as sending a message with SendClientMessage) will not work. A timer must be used to delay the kick. |
well another question!
what if you removed the: Warns == 0 from OnPlayerConnect, what would be happen ? does this cause of saving the warns to the player till he reconnect ? i mean if he quit the game with (2/3) of warnings, would he have 2 warnings if he rejoined ? |