Need help in io_read -
IceBilizard - 15.12.2012
hello all today i made a function for saving my server organization members but it cant read in dialog List here
is my function code
this is for saving members
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[playerid] == 1)
{
new pname[24], File:ftw=fopen("GSFMembers.txt", io_append);
if(ftw)
{
GetPlayerName(playerid, pname, 24);
format(string, 300, "%s\r\n", pname); // formatting the string with the escape codes
fwrite(ftw, string);
fclose(ftw);
}
}
return 1;
}
this is for read members
pawn Код:
if (PlayerOrg[playerid] == 1)
{
new string[300];
new File:ftw = fopen("GSFMembers.txt", io_read); // Open the file
while(fread(ftw, string)) //reads the file line-by-line
{
format(string,300,"%s\r\n", string);
ShowPlayerDialog(playerid, 757, DIALOG_STYLE_LIST, "Organization Members",string,"Close","");
}
fclose(ftw);
return 1;
}
with this code it only showing 1 not all members i add 4 members but only showing 1 if i put
pawn Код:
SendClientMessage(playerid, COLOR_YELLOW, string);
then showing me all tell me how to fix this
and +rep for helper
Re: Need help in io_read -
RajatPawar - 15.12.2012
Try using a for loop. Or foreach, instead of if(PlayerOrg[playerid]. I am not a master of file functions, but try, who knows.
Re: Need help in io_read -
Babul - 15.12.2012
i got a suggestion:
why now simply let your script check if a playername's file exists in a certain directory? if its existing, consider the player in that faction. if not, well...
instead of writing "Babul" into 1 single file (maybe multiple times?), i would create a file like "groups/ESC/Babul.txt", and close it. it will contain nothing BUT the information that its there, indicating "Babul is ESC member".
to delete an account, you could do that by deleting the file (use the FileManager plugin for scanning for (all) files) while being ingame, or however you can get access to the files...
in case you find it some diffucult to scan group-directories like ("groups/ESC") to tell the script that all players in that directory are part of the group formed by the directory NAME, why not create a file "Babul", and write the group into the file "ESC" ?
in case you only allow a player to be in ONE group, this way could work even better