Help with "INI_WriteInt"
#1

Ok i making an offline ban system which works good the only issue is i want it not to edit the line which says "Banned = 1"(the blue arrow) in the player file, but instead of that it just creates another line saying "Banned = 1"(the red arrow) so the file would have two lines with "Banned = 1".

Код:
CMD:obanacc(playerid, params[])
{
   	if(IsPlayerAdmin(playerid) || pInfo[playerid][Admin] >= 4)
	{
		new Name,reason[100],year,month,day,hour,minute,second,file[100];
		if(sscanf(params, "s[25]", Name,reason)) return SendClientMessage(playerid, error, "Usage: /Obanacc <Player Name> <Reason>");
   		format(file, 100, PATH, Name);
        if (!fexist(file)) return SendClientMessage(playerid,error,"Error: This player doesn't have an account!");
        CommandToAdmins(playerid,"obanacc");
        getdate(year, month, day);
		gettime(hour,minute,second);
    	new INI:ACCOUNT = INI_Open(file);
		INI_WriteInt(ACCOUNT, "Banned", 1);
		INI_Close(ACCOUNT);
	    format(astring, sizeof(astring),"Account '%s has been successfully banned!",Name);
        SendClientMessage(playerid,-1,astring);
        format(astring, sizeof(astring),"AdmCmd: Administrator '%s' has Banned Account '%s'",GetName(playerid),Name);
        SendClientMessageToAll(red,astring);
        format(astring,sizeof(astring),"[OBAN]: %s has banned account name %s.[Reason: %s] || [Date: %d/%d/%d at %d:%d:%d] ",GetName(playerid),Name,reason,day, month, year ,hour, minute, second);
		WriteToLog(astring,"oBans");
		return 1;
	}
	else return ShowMessage(playerid, error, 1);
}
Reply
#2

You forgot to set the [data] tag.

Код:
INI_SetTag(ACCOUNT, "data");
EDIT: If you did not know, in your case it goes right before INI_WriteInt, right after the opening of the file.
Reply
#3

Quote:
Originally Posted by Troydere
Посмотреть сообщение
You forgot to set the [data] tag.

Код:
INI_SetTag(ACCOUNT, "data");
EDIT: If you did not know, in your case it goes right before INI_WriteInt, right after the opening of the file.
Ok i solve the issue , but now i would like to add reason to the obanacc command but each time i try to /obanacc IG is returns an error saying the player name is not registered.

Код:
CMD:obanacc(playerid, params[])
{
   	if(IsPlayerAdmin(playerid) || pInfo[playerid][Admin] >= 4)
	{
		new Name,file[100],reason[100];
		if(sscanf(params, "us[50]", Name, reason)) return SendClientMessage(playerid, error, "Usage: /obanacc <Player Name> <Reason>");
   		format(file, 100, PATH, Name);
        if (!fexist(file)) return SendClientMessage(playerid,error,"Error: This player doesn't have an account!");
      	new INI:ACCOUNT = INI_Open(file);
        INI_SetTag(ACCOUNT,"data");
		INI_WriteInt(ACCOUNT, "Banned", 1);
		INI_Close(ACCOUNT);
	    format(astring, sizeof(astring),"Account '%s has been successfully banned!",Name);
        SendClientMessage(playerid,-1,astring);
        format(astring, sizeof(astring),"AdmCmd: An Administrator has Banned Account '%s'. [Reason: %s]",Name,reason);
        SendClientMessageToAll(red,astring);
        format(astring,sizeof(astring),"[OBAN]: %s has banned account name %s. [Reason: %s] ",GetName(playerid),Name,reason);
		WriteToLog(astring,"oBans");
        CommandToAdmins(playerid,"obanacc");
		return 1;
	}
	else return ShowMessage(playerid, error, 1);
}
Reply
#4

Maybe you should get the player name before formatting the path.

your PATH define should be something like "users/%s.ini" , then you're trying to insert an integer in that %s, which is not going to happen.

Get the player's name before formatting:

Код:
new playname[24];
GetPlayerName(name,playname,sizeof playname);
format(file, 100, PATH, playname);
EDIT: Unless you want to use that command with offline players aswell, if that's the case, make name a string
Код:
Name[24];
and replace the 'u' for the string in sscanf.

Код:
if(sscanf(params, "s[24]s[50]", Name, reason)) return SendClientMessage(playerid, error, "Usage: /obanacc <Player Name> <Reason>");
And leave everything else as it is
Reply
#5

Quote:
Originally Posted by Troydere
Посмотреть сообщение
Maybe you should get the player name before formatting the path.

your PATH define should be something like "users/%s.ini" , then you're trying to insert an integer in that %s, which is not going to happen.

Get the player's name before formatting:

Код:
new playname[24];
GetPlayerName(name,playname,sizeof playname);
format(file, 100, PATH, playname);
EDIT: Unless you want to use that command with offline players aswell, if that's the case, make name a string
Код:
Name[24];
and replace the 'u' for the string in sscanf.

Код:
if(sscanf(params, "s[24]s[50]", Name, reason)) return SendClientMessage(playerid, error, "Usage: /obanacc <Player Name> <Reason>");
And leave everything else as it is
Thank you VERY much. rep+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)