SA-MP Forums Archive
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(playerid6)) return NoAuth(playerid);
    
fremove("bans.cfg");
    new 
File:file fopen("bans.cfg"io_readwrite);
    
fclose(file);
    new 
string[128];
    
format(stringsizeof(string), "AdmCmd: %s %s has cleared the ban list, therefore, everyone have been unbanned."RPARN(playerid), RPN(playerid));
    
Log("unban.log"string);
    
SendAMessage(1string);
    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
View Post
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
View Post
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(playerid6)) 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(stringsizeof(string), "AdmCmd: %s %s has cleared the ban list, therefore everyone has been unbanned."RPARN(playerid), RPN(playerid));
        
Log("unban.log"string);
        
SendAMessage(1string);
    }
    else 
// We must check this, just in case.
    
{
        
format(stringsizeof(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
View Post
PHP Code:
CMD:clearbans(playerid)
{
    if(!
IsAuth(playerid6)) 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(stringsizeof(string), "AdmCmd: %s %s has cleared the ban list, therefore everyone has been unbanned."RPARN(playerid), RPN(playerid));
        
Log("unban.log"string);
        
SendAMessage(1string);
    }
    else 
// We must check this, just in case.
    
{
        
format(stringsizeof(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