14.04.2013, 10:45
Good day SAMP Community,
I have the following Problem: I wanted to script a /foff Script where Offline Players are shown. Since I do not have Mysql, I created for all Factions a log File. In this Log File the Player Names are saved when they are being invited. But, when they are getting uninvited they need to be removed from this File and this is my problem. I do not know how to delete a Name from a textfile. For example I /uninvite Name2, then Name 2 should be deleted from the list. If I /uninvite Firstname_Lastname then Firstname_Lastname should be deleted
The names are saved like this
I tried it but it doesnt work. I never get the message Test, only fail and the line wont be deleted
Kind regards,
Lionel
I have the following Problem: I wanted to script a /foff Script where Offline Players are shown. Since I do not have Mysql, I created for all Factions a log File. In this Log File the Player Names are saved when they are being invited. But, when they are getting uninvited they need to be removed from this File and this is my problem. I do not know how to delete a Name from a textfile. For example I /uninvite Name2, then Name 2 should be deleted from the list. If I /uninvite Firstname_Lastname then Firstname_Lastname should be deleted
The names are saved like this
Код:
Name Name1 Name2//this should be removed Name3 Name4 Firstname_Lastname Lastname_Firstname etc
pawn Код:
COMMAND:auninvite(playerid, params[])
{
if(GetAdminLevel(playerid) < 10) return SendClientError(playerid, CANT_USE_CMD);
new iPlayer;
if( sscanf ( params, "u", iPlayer)) return SCP(playerid, "[PlayerID/PartOfName]");
if(!IsPlayerConnected(iPlayer)) return SendClientError(playerid, PLAYER_NOT_FOUND);
// The function itself
new File:gstats; // The file
new string[MAX_STRING];
new pname[24];
new str[256];
new dest[128];
format(dest,sizeof(dest), "fLogs/%s.fam.log",PlayerInfo[iPlayer][PTeamName]);
gstats=fopen(dest, io_append);
GetPlayerName(iPlayer, pname, 24); // The name of the player
format(str, 256, "\n\r"); // format
while(fread(gstats, string)) {
if(strcmp(string, pname, false, strlen(pname))==0) { // To check if the players name is in the file
fdeleteline(dest, string); // delete the line
fwrite(gstats, str); // write the string
SendClientWarning(playerid,"Test");//i never see this message only "Fail"
}
}
fclose(gstats);
SendClientWarning(playerid,"Fail");//this is the message i only see:(
Uninvite(iPlayer,GetPlayerFaction(iPlayer));
SendClientInfo(playerid, "Done.");
return 1;
}
Lionel