CMD:ban(playerid, params[]) { if(pInfo[playerid][Adminlevel] < 2) return SCM(playerid, red, "[ERROR] You are not allowed to use this command!"); new player1, string[128], reason[64]; if(sscanf(params, "us[64]", player1, reason)) return SCM(playerid, red,"[USAGE]: /ban (ID/Name) (reason)"); if(player1 == INVALID_PLAYER_ID) return SCM(playerid, red, "[ERROR]: No player!"); if(player1 == playerid) return SCM(playerid, red, "[ERROR]: You cannot ban yourself."); format(string, sizeof(string), "{FFFFFF}%s (ID: %d) has been banned %s %s", pName(player1), player1, pName(playerid), reason); SendClientMessageToAll(-1, string); BanEx(player1, string); return 1; }
He is using Y_ini. Well it`s easy. First of all, create global player variable in your enum or just classic one. Then place it in load account function, also in save function, I haven`t learned Y_ini but I am telling you just steps how I would do it. So next, when player get banned, you just set variable (ban variable) to 1 and save it inside account txt file, after that when banned player tried to login on your server you just check that ban var, if it`s 1, player is banned and you kick him, if it`s 0 then just continue with code. That`s all.
|
Ok, Tanks for reply. I will post here if this one will work and +REP you
![]() |
#include <a_samp>
#include <YSI\y_ini>
#define BAN_PATH "/Bans/%s.ini"
BanPath(playerid){
new
str[36],
name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(str, sizeof(str), BAN_PATH, name);
return str;
}
enum E_BAN_DATA {
Ban,
Reason[24]
};
new PlayerInfo[MAX_PLAYER_NAME][E_BAN_DATA];
//now go to OnPlayerConnect and past this
PlayerInfo[playerid][Ban] = 0;
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
TogglePlayerSpectating(playerid, true);
if(fexist(BanData(playerid))) {
if(PlayerInfo[playerid][Ban] == 1) {
INI_ParseFile(UserPath(playerid), "LoadPlayerData_BanData", .bExtra = true, .extra = playerid);
SendClientMessage(playerid, 0xFF0000, "You are banned from this server");
Kick(playerid);
}
}
// now right underneath the OnPlayerConnect add this
forward LoadPlayerData_BanData(playerid, name[], value []);
public LoadPlayerData_BanData(playerid, name[], value []) {
INI_Int("Ban", PlayerInfo[playerid][Ban]);
INI_String("Reason", PlayerInfo[playerid][Reason], 24);
return 1;
}
//now change our command to this
CMD:ban(playerid, params[])
{
if(pInfo[playerid][Adminlevel] < 2)
return SCM(playerid, red, "[ERROR] You are not allowed to use this command!");
new player1, string[128], reason[64];
if(sscanf(params, "us", player1, reason))
return SCM(playerid, red,"[USAGE]: /ban (ID/Name) (reason)");
if(player1 == INVALID_PLAYER_ID)
return SCM(playerid, red, "[ERROR]: No player!");
if(player1 == playerid)
return SCM(playerid, red, "[ERROR]: You cannot ban yourself.");
format(string, sizeof(string), "{FFFFFF}%s (ID: %d) has been banned %s %s", pName(player1), player1, pName(playerid), reason);
SendClientMessageToAll(-1, string);
new INI:File = INI_Open(BanPath(player1));
INI_SetTga(File, "BanData");
INI_WriteInt(File, "Ban", 1);
INI_WriteString(File, "Reason", reason);
INI_Close(File);
Kick(playeri1);
return 1;
}