Line removing problem
#1

I'm trying to remove player name from file but it doesn't getting removed!! I dont understand i did everything to the samp wiki tutorial and yet, its there when the code executed.. -.-

I'm writing to a line names this way: "Firstname_Lastname\r\n". (Getting playername and just writing it inside)

removeline function:
Код:
stock fremoveline( filename[ ], line[ ] )
{
	if( fexist( filename ) )
	{
		new
		szTmp[ 256 ],
		File: fHandle = fopen( filename, io_read ),
		File: fBullshit = fopen( "loltmp.ini", io_write )
		;
		while( fread( fHandle, szTmp ) )
		{
			if( strfind( szTmp, line ) == -1 )
			{
				fwrite( fBullshit, szTmp );
			}
		}
		fclose( fHandle );
		fclose( fBullshit );
		fremove( filename );
		
		fHandle = fopen( filename, io_append );
		fBullshit = fopen( "loltmp.ini", io_read );
		
		while( fread( fBullshit, szTmp ) ) {
			fwrite( fHandle, szTmp );
		}
		fclose( fHandle );
		fclose( fBullshit );
		fremove( "loltmp.ini" );
		
		return 1;
	}
	return 0;
}
here is the code which should remove the line:
pawn Код:
new playerName[24];
new str[128], pname[24];
new File:gstats=fopen("passed.ini", io_append);
GetPlayerName(playerid, pname, 24); // The name of the player
format(str, sizeof(str), "%s\r\n",pname); // format
while(fread(gstats, string))
{
    if(strcmp(string, pname, false, strlen(pname))==0)
    {
        fremoveline("passed.ini", str);
    }
}
What happens in the file afterwards? noting. please help.
Reply
#2

I tested it, and it works fine.

Although I can only recommend changing this part:
pawn Код:
new pname[24];
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME); // The name of the player
    fremoveline("passed.ini", pname);
EDIT:
All so, make sure the name in the file and the player's name are case sensitive. Otherwise, you can change the 'strfind' line to this:
pawn Код:
if( strfind( szTmp, line, true ) == -1 )
Reply
#3

Quote:
Originally Posted by Threshold
Посмотреть сообщение
I tested it, and it works fine.

Although I can only recommend changing this part:
pawn Код:
new pname[24];
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME); // The name of the player
    fremoveline("passed.ini", pname);
EDIT:
All so, make sure the name in the file and the player's name are case sensitive. Otherwise, you can change the 'strfind' line to this:
pawn Код:
if( strfind( szTmp, line, true ) == -1 )
Didnt work :/

here is the full rework of the code tell me why its not working :
Код:
if(GetPVarInt(playerid, "Denied") == 1 && PlayerInfo[playerid][pPosted] == 1)
{
	new playerName[24], Reason[128];
	new str[128], pname[24];
	GetPlayerName(playerid, pname, MAX_PLAYER_NAME); // The name of the player
	format(str, sizeof(str), "%s\r\n", pname); // format
	new File:handle = fopen("passed.ini", io_append);
	if(handle)
	{
		while(fread(handle, str))
		{
			if(strcmp(string, pname, false, strlen(pname))==0)
			{
				fremoveline("passed.ini", str);
			}
		}
		fclose(handle);
	}
	format(string, sizeof(string), "users/%s.ini", PlayerName(playerid));
	DOF2_RemoveFile(string);
	KickEx(playerid);
}
It doesn't remove the player name from the file!
Reply
#4

Stop looping the file... it already does that in the 'removeline' function...

pawn Код:
if(GetPVarInt(playerid, "Denied") == 1 && PlayerInfo[playerid][pPosted] == 1)
{
    new pname[MAX_PLAYER_NAME], string[35];
    GetPlayerName(playerid, pname, sizeof(pname)); // The name of the player
    fremoveline("passed.ini", pname);
    format(string, sizeof(string), "users/%s.ini", pname);
    DOF2_RemoveFile(string);
    KickEx(playerid);
}
If that doesn't work, then I dunno what to say...
Reply
#5

it doesn't work.. The player spawns it should remove his name from the file and yet.. the name is there and not gone anywhere..
Reply
#6

Give me an example, what is the player's name, what does it say in the file?
Reply
#7

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Give me an example, what is the player's name, what does it say in the file?
Okay once again, i'll show the full codes okay? here it is:
Saving the name in the file (notice im doing %s\r\n):
Код:
stock SavePlayerList(playerid)
{
    new str[50], pname[MAX_PLAYER_NAME];
    new File:gstats=fopen("passed.txt", io_append);
    GetPlayerName(playerid, pname, sizeof(pname));
    if(!gstats) fcreate("passed.txt");
    format(str, sizeof(str), "%s\r\n",pname);
    fwrite(gstats, str);
    fclose(gstats);
}
This is the fremoveline function:
Код:
fremoveline(file[],line[])
{
	new string[256], File:Temp = fopen("Temp.ini",io_append), File:Main = fopen(file,io_read);
	while(fread(Main,string))
	{
	    if(strcmp(string,line,false) != 0) fwrite(Temp,string);
	}
	fclose(Main);
	fclose(Temp);
	fremove(file);
	Main = fopen(file, io_append);
	Temp = fopen("Temp.ini",io_read);
	while(fread(Temp,string)) fwrite(Main,string);
	fclose(Main);
	fclose(Temp);
	fremove("Temp.ini");
	return 1;
}
This is the actual remove which doesn't remove the name from the file:
Код:
new playerName[MAX_PLAYER_NAME], pname[31], string[256];
if(GetPVarInt(playerid, "Denied") == 1 && PlayerInfo[playerid][pPosted] == 1)
{
	GetPlayerName(playerid, pname, sizeof(pname));
	fremoveline("passed.txt", pname);
	new Reason[128];
	format(string, sizeof(string), "users/%s.ini", PlayerName(playerid));
	DOF2_RemoveFile(string);
	GetPVarString(playerid, "DeniedBy" ,playerName, sizeof(playerName));
	SendClientMessage(playerid, 0xCCEEFF96, "Status: {F81414}Denied");
	format(string, sizeof(string), "Your account was denied by %s.", playerName);
	SendClientMessage(playerid,COLOR_LIGHTRED,string);
	GetPVarString(playerid, "DeniedReason" ,Reason, sizeof(Reason));
	format(string, sizeof(string), "Reason: %s.", Reason);
	SendClientMessage(playerid,COLOR_LIGHTRED,string);
	KickEx(playerid);
}
The name is written in the file, the removefile executed checking again, the name is still there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)