Offline Ban Y_INI
#1

Hello, how to make a offline ban command with y_ini? Please give me an example. thats my ban command:

Код:
CMD:ban(playerid,params[])
{
        if(IsPlayerConnected(playerid))
        {
			new targetid,reason[105],string[256];
			if(sscanf(params, "us[105]", targetid,reason)) return SendClientMessage(playerid,-1,""chat" Usage: /ban [playerid] [reason]");
			if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,-1,""chat""COL_RED" Player is not connected/online.");

			format(string, sizeof(string), ""chat""COL_RED" %s %s (%d) has banned %s (%d) | Reason: %s",GetAdminName(playerid),PlayerName(playerid),playerid,PlayerName(targetid),targetid,reason);
			SendClientMessageToAll(-1,string);
			BanPlayer(targetid,reason,PlayerName(playerid));

	return 1;
}
Reply
#2

You will need an int called Banned and also change the name of "/users/" to whatever the name of your folder where you store your players info is.
pawn Код:
CMD:offlineban(playerid, params[])
{
    new targetname[24], filestring[79];
    if(sscanf(params, "s[24]", targetname)) return SendClientMessage(playerid, COLOR_GREY, "[Usage:] /offlineban [playerName]");
    format(filestring, sizeof(filestring), "/users/%s.ini", targetname);
    if(!fexist(filestring)) return SendClientMessage(playerid, COLOR_LIGHTRED, "That player does not exist.");
    else
    {
        new INI:File = INI_Open(filestring);
        INI_SetTag(File, "data");
        INI_WriteInt(File, "Banned", 1);
        INI_Close(File);
        new done[128];
        format(done, sizeof(done), "You have successfully banned player %s.", targetname);
        SendClientMessage(playerid, -1, done);
    }
    return 1;
}
Reply
#3

Thanks, can you do the same with the command unban and so that it unbans and by offlineban that it unban/bans the player ip too?
Reply
#4

You will need to save/load their ip in a string. If you're using Y_INI it should be like this.

In your enum.
pawn Код:
BannedIP[22]
OnPlayerDisconnect.
pawn Код:
INI_WriteString(File, "BannedIP", PlayerInfo[playerid][BannedIP]);
Loading.
pawn Код:
INI_String("BannedIP", PlayerInfo[playerid][BannedIP], 22);
pawn Код:
CMD:unban(playerid, params[])
{
    new tname[24];
    if(sscanf(params, "s[24]", tname)) return SendClientMessage(playerid,-1,"Correct [Usage:] /unban [playerName] ");
    new filestring[79];
    format(filestring, sizeof(filestring), "/users/%s.ini", tname);
    if(!fexist(filestring)) return SendClientMessage(playerid, COLOR_LIGHTRED, "That player does not exist.");
    else
    {
        new INI:File = INI_Open(filestring);
        INI_SetTag(File, "data");
        INI_WriteInt(File, "Banned",0);
        INI_Close(File);
        INI_ParseFile(filestring, "LoadIP_%s", .bExtra = true , .extra = playerid);
        new cmdstring[44];
        format(cmdstring, sizeof(cmdstring), "unbanip %s", PlayerInfo[playerid][BannedIP]);
        SendRconCommand(cmdstring);
        SendRconCommand("reloadbans");
        new done[128];
        format(done, sizeof(done),"AdmCmd: You have successfully unbanned %s.", tname);
        SendClientMessage(playerid, -1, done);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)