y_ini help
#1

This is my code for /unban [username].

PHP код:
// /unban[dcmd]
dcmd_unban(playeridparams[])
{
    new 
pName[128], string[128];
    if(
PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playeridCOLOR_WHITE,"Server: Unrecognized command, type /commands to see the commands available for you.");
    if(
PlayerInfo[playerid][pAdmin]<4) return SendClientMessage(playeridCOLOR_ADMINBLUE"ERROR: This command is unavailable for your admin rank.");
    if(
admduty[playerid]==0) return SendClientMessage(playeridCOLOR_ADMINBLUE"ERROR: You must be on duty to use this command.");
    if(
sscanf(params"s"pName)) return SendClientMessage(playeridCOLOR_ADMINBLUE"Correct usage: /unban [username]");
     
format(pNamesizeof(pName), "Users/%s.ini"pName);
    if(!
fexist(string)) return SendClientMessage(playeridCOLOR_ADMINBLUE"ERROR: This user does not exists.");
    new 
INI:File INI_Open(string);
    
SetTag(File"data");
    
INI_WriteInt(File"Banned"0);
    
INI_Close(File);
    
SendClientMessage(playeridCOLOR_ADMINBLUE"User %s has been unbanned."pName);
    return 
1;

I need to add a line that checks if that user is banned or not and if he is banned, then it returns a message SendClientMessage(playerid, COLOR_ADMINBLUE, "ERROR: This user is not banned.");

I don't know the y_ini function for it. Can anyone please tell me how to do it?
Reply
#2

Help, please.
Reply
#3

Any help?
Reply
#4

Bump
Reply
#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
#6

Thanks man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)