y_ini help
#5

pawn Код:
dcmd_unban(playerid, params[])
{
    if(!PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid, COLOR_WHITE,"Server: Unrecognized command, type /commands to see the commands available for you.");
    if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playerid, COLOR_ADMINBLUE, "ERROR: This command is unavailable for your admin rank.");
    if(!admduty[playerid]) return SendClientMessage(playerid, COLOR_ADMINBLUE, "ERROR: You must be on duty to use this command.");
    new pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s[24]", pName)) return SendClientMessage(playerid, COLOR_ADMINBLUE, "Correct usage: /unban [username]");
    new fstr[50];
    format(fstr, sizeof(fstr), "Users/%s.ini", pName);
    if(!fexist(fstr)) return SendClientMessage(playerid, COLOR_ADMINBLUE, "ERROR: This user does not exist.");
    SetPVarString(playerid, "UnbanName", pName);
    SetPVarInt(playerid, "BanCheck", 0);
    INI_ParseFile(fstr, "LoadBan_%s", .bExtra = true, .extra = playerid);
    if(!GetPVarInt(playerid, "BanCheck")) return SendClientMessage(playerid, COLOR_ADMINBLUE, "This user is not banned.");
    new INI:File = INI_Open(fstr);
    INI_SetTag(File, "data");
    INI_WriteInt(File, "Banned", 0);
    INI_Close(File);
    format(fstr, sizeof(fstr), "User %s has been unbanned.", pName);
    SendClientMessage(playerid, COLOR_ADMINBLUE, fstr);
    return 1;
}

forward LoadBan_data(playerid, name[], value[]);
public LoadBan_data(playerid, name[], value[])
{
    new var = 0;
    INI_Int("Banned", var);
    SetPVarInt(playerid, "BanCheck", var);
    return 1;
}
pawn Код:
SetPVarInt(playerid, "BanCheck", 0);
I have used PVars here, because creating new variables might make you confuse yourself. This line sets the 'BanCheck' to automatically be 0. 0 = Player is not banned, 1 = Player is banned. This sets a player variable called 'BanCheck' to 0 before checking whether the player is banned or not.

pawn Код:
INI_ParseFile(fstr, "LoadBan_%s", .bExtra = true, .extra = playerid);
Call the function 'LoadBan' and pass the parameter 'playerid', which belongs to the admin using the command.

pawn Код:
forward LoadBan_data(playerid, name[], value[]);
public LoadBan_data(playerid, name[], value[])
{
    new var = 0;
    INI_Int("Banned", var);
    SetPVarInt(playerid, "BanCheck", var);
    return 1;
}
The function 'LoadBan' will create a new variable, and it will then load the value of the "Banned" line within the unbanning user's file. This value is then saved to the variable 'var', and from there we can simply set the new value of 'BanCheck' to either 0 or 1 depending on whether the player is banned or not.

pawn Код:
if(!GetPVarInt(playerid, "BanCheck")) return SendClientMessage(playerid, COLOR_ADMINBLUE, "This user is not banned.");
If the player is not banned, AKA 'BanCheck' will be 0, then you return an error message.
Reply


Messages In This Thread
y_ini help - by ATGOggy - 06.01.2015, 12:54
Re: y_ini help - by ATGOggy - 06.01.2015, 13:09
Re: y_ini help - by ATGOggy - 06.01.2015, 14:48
Re: y_ini help - by ATGOggy - 07.01.2015, 09:09
Re: y_ini help - by Threshold - 07.01.2015, 09:56
Re: y_ini help - by ATGOggy - 07.01.2015, 10:18

Forum Jump:


Users browsing this thread: 1 Guest(s)