I have a problem - 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: I have a problem (
/showthread.php?tid=400421)
I have a problem -
IceBilizard - 18.12.2012
Guys i made a members saving system in .txt with their names with command /setmember in my organization script but when i use /setmember id its only saving my name if i use /setmember 1 then saving my name and if i use /setmember 2 then saving my name
like
IceBilizard
IceBilizard
this this is my code see and tell what is worng
pawn Код:
CMD:setmember(playerid, params[])
{
if (!IsLeader(playerid)) return SendClientMessage(playerid,COLOR_RED,"You are not the leader of an organization");
new ID;
if (sscanf(params, "u", ID)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /setmember [playerid]");
if (!IsPlayerConnected(ID) || ID == playerid) return 1;
new org = PlayerOrg[playerid];
if (PlayerOrg[ID]) return SendClientMessage(playerid, COLOR_RED,"That player already belongs to an organization");
if (Requesting[ID] != org) return SendClientMessage(playerid, COLOR_RED,"That player is not requesting to join your organization!");
new string[120];
format(string,sizeof(string),"%s has set you as a member of %s", PlayerName(playerid), GetOrgName(org));
SendClientMessage(ID, COLOR_YELLOW, string);
format(string,sizeof(string),"You have set %s a member of %s", PlayerName(ID), GetOrgName(org));
SendClientMessage(playerid, COLOR_YELLOW, string);
PlayerOrg[ID] = org;
GiveOrgFeatures(ID);
Requesting[ID] = 0;
if (PlayerOrg[ID] == 1)
{
new pname[24], File:ftw=fopen("GSFMembers.txt", io_append);
if(ftw)
{
GetPlayerName(ID, pname, 24);
format(string, 300, "%s\r\n", pname); // formatting the string with the escape codes
fwrite(ftw, string);
fclose(ftw);
}
}
return 1;
}
Re: I have a problem -
Mike_Peterson - 18.12.2012
You have a problem? Okay....
So, I think you used ****** Translate partly or something like that, anyway
It appears that your code just keeps adding lines everytime u use the command.
That is what io_append does, I believe there are two things you could do.
1. Make a function that will save all your details, using io_write (this clears the file before writing) so basically rewriting everything in the userconfig. Since file.inc is like the slowest reading/writing files method, this will definatelly take some time.
2. Delete the previous line, adding the new one.
Using this function:
https://sampwiki.blast.hk/wiki/Fdelete_code, you are able to delete the line before writing it again.