SA-MP Forums Archive
Delete custom name from files - 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: Delete custom name from files (/showthread.php?tid=310931)



Delete custom name from files - Zcelo12 - 14.01.2012

Hey guy's,
I've a file with a few names:
Код:
Zcelo12
ProGamer
HardCore
And with a command i ant to remove the name "HardCore".
But i don't know how to make that. I tried taht one:

Код:
CMD:removebl(playerid,params[])
{
if (PlayerOrg[playerid] == 0) return SendError(playerid," You aren't in any faction!");
if(IsLeader(playerid) || IsPlayerRank(playerid) > 2)
{
new id;
if(sscanf(params,"u",id)) return SendUsage(playerid," /removebl [playerid]");
if(!IsPlayerConnected(id) || IsPlayerNPC(id)) return SendError(playerid," Player is not connected!");
if(Org_Blacklist(id,GetOrgID(oPlayerName(id))))
{
new name[64];
format(name,sizeof(name),"%s.ini",GetOrgName(PlayerOrg[playerid]));
new File: file = fopen(name, io_read);
if(file)
{
new valtmp[MAX_PLAYER_NAME];
while (fread(file, valtmp))
{
StripNewLine(valtmp);
if (!strcmp(valtmp, oPlayerName(playerid), true, strlen(oPlayerName(playerid))))
{
strdel(valtmp,0,24);
fclose(file);
return 1;
}
}
}
}
}
return 1;
}
I hope anyone can help me.
Greetings


AW: Delete custom name from files - Zcelo12 - 14.01.2012

I tried fdeleteline, but this function removes everything from the file?!


AW: Delete custom name from files - Nero_3D - 14.01.2012

deleting a line is quite an annoying process but basically you just read the file and write everything expect the line in another file, afterwards you just put the whole data from the temp file in the original one

pawn Код:
new
    File: oFile,
    filename[32];
format(filename, sizeof filename, "tmp%s.ini", GetOrgName(PlayerOrg[playerid]));
if((oFile = fopen(filename[3], io_read))) { // open the original file
    new
        File: tFile;
    if((tFile = fopen(filename, io_write))) { // opens the temp file, "tmpORIGINAL.ini"
        new
            tmp[MAX_PLAYER_NAME + 2],
            name[sizeof tmp];
        strcat(name, oPlayerName(playerid)); // save the name into a variable
        strcat(name, "\r\n"); // needed to prevent to call StripNewLine
        while(fread(oFile, tmp)) {
            if(strcmp(tmp, name, false) == 0) { // we found the line
                while(fread(oFile, tmp)) { // skips the check, since we already found it
                    fwrite(tFile, tmp);
                }
                break;
            }
            fwrite(tFile, tmp);
        }
        fclose(oFile);
        fclose(tFile);
        tFile = fopen(filename, io_read);
        oFile = fopen(filename[3], io_write);
        while(fread(tFile, tmp)) { // put the data back into the original
            fwrite(oFile, tmp);
        }
        fclose(tFile);
        fremove(filename); // removes the temp file
    }
    fclose(oFile);
}



AW: Delete custom name from files - Zcelo12 - 16.01.2012

Big Thanks to you
But 'filename' does not remove with fremove();


AW: Delete custom name from files - Nero_3D - 20.01.2012

Quote:
Originally Posted by Zcelo12
Посмотреть сообщение
Big Thanks to you
But 'filename' does not remove with fremove();
Ah, sure because it is still opend while the code executes fremove (I edited my last post)