fremove bug - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: fremove bug (
/showthread.php?tid=610125)
fremove bug -
NeXoR - 20.06.2016
File is not deleted after executing the command
no clue why
Anyone ?
PHP Code:
CMD:clearbans(playerid)
{
if(!IsAuth(playerid, 6)) return NoAuth(playerid);
fremove("bans.cfg");
new File:file = fopen("bans.cfg", io_readwrite);
fclose(file);
new string[128];
format(string, sizeof(string), "AdmCmd: %s %s has cleared the ban list, therefore, everyone have been unbanned.", RPARN(playerid), RPN(playerid));
Log("unban.log", string);
SendAMessage(1, string);
return 1;
}
Re: fremove bug -
Gammix - 20.06.2016
Maybe the file "ban.cfg" isn't existing in your scriptfiles.
You can only remove files from the scriptfiles folder.
Re: fremove bug -
Slawiii - 20.06.2016
maybe you need to remove this
PHP Code:
new File:file = fopen("bans.cfg", io_readwrite);
fclose(file);
Re: fremove bug -
Dayrion - 20.06.2016
Quote:
Originally Posted by Slawiii
maybe you need to remove this
PHP Code:
new File:file = fopen("bans.cfg", io_readwrite);
fclose(file);
|
No. If fremove doesn't work, maybe the file doesn't exist or the path is wrong.
Re: fremove bug -
NeXoR - 20.06.2016
Quote:
Originally Posted by Dayrion
No. If fremove doesn't work, maybe the file doesn't exist or the path is wrong.
|
The file surely exists, the script checks it under OnFilterScriptInit and creates it if it's not
I also checked the scriptfiles folders step by step when I tested this command
the fopen is meant to create it back, since I only want to delete the content, not the file itself
Re: fremove bug -
Jf - 20.06.2016
PHP Code:
CMD:clearbans(playerid)
{
if(!IsAuth(playerid, 6)) return NoAuth(playerid);
// Create the file on OnGameModeInit() using io_append instead of io_write. By doing this you don't need to check if the file exist before this command executes.
new
File:handle = fopen("bans.cfg", io_write), // io_write deletes the entire data in the file. No need to use fremove.
string[128];
if(handle) // Valid handle
{
fclose(handle); // Close the file. Data has been deleted.
format(string, sizeof(string), "AdmCmd: %s %s has cleared the ban list, therefore everyone has been unbanned.", RPARN(playerid), RPN(playerid));
Log("unban.log", string);
SendAMessage(1, string);
}
else // We must check this, just in case.
{
format(string, sizeof(string), "Admin %s %s tried to erase the data of ban.cfg. There's been an error while deleting the data.", RPARN(playerid), RPN(playerid));
Log("unban.log", string);
print(string);
SendClientMessage(playerid, -1, ">> There has been an error while deleting the ban file. Report the server's owner.");
}
return 1;
}
Re: fremove bug -
NeXoR - 20.06.2016
Quote:
Originally Posted by Jf
PHP Code:
CMD:clearbans(playerid)
{
if(!IsAuth(playerid, 6)) return NoAuth(playerid);
// Create the file on OnGameModeInit() using io_append instead of io_write. By doing this you don't need to check if the file exist before this command executes.
new
File:handle = fopen("bans.cfg", io_write), // io_write deletes the entire data in the file. No need to use fremove.
string[128];
if(handle) // Valid handle
{
fclose(handle); // Close the file. Data has been deleted.
format(string, sizeof(string), "AdmCmd: %s %s has cleared the ban list, therefore everyone has been unbanned.", RPARN(playerid), RPN(playerid));
Log("unban.log", string);
SendAMessage(1, string);
}
else // We must check this, just in case.
{
format(string, sizeof(string), "Admin %s %s tried to erase the data of ban.cfg. There's been an error while deleting the data.", RPARN(playerid), RPN(playerid));
Log("unban.log", string);
print(string);
SendClientMessage(playerid, -1, ">> There has been an error while deleting the ban file. Report the server's owner.");
}
return 1;
}
|
Modified it a bit but works, thanks