Reading file problem
#1

Hello samp'ers,

Today I've tried to add a /reports command that let me read all the reports in the game, without checking actual reports.txt

My problem is that once I enter in-game and use /reports command, it doesn't read reports from file.

/reports command

Код:
CMD:reports(playerid, params[])
{
	new string[1000], string2[1000];
	new File: reports = fopen("reports.txt", io_append);
    fread(reports, string);
	fclose(reports);
	format(string2, sizeof(string2), "Reporturi existente: \n %s", string);
	SendClientMessage(playerid, -1, string2);

	return 1;
}
and /report command that writes reports:

Код:
CMD:report(playerid, params[])
{
	new name[MAX_PLAYER_NAME], string[250], adminsreport[250], getdata[100];
	if(isnull(params)) return SendClientMessage(playerid, -1, "Syntax: "COL_GREEN"/report <message to be send>");
	GetPlayerName(playerid, name, sizeof(name));
	strftime("Year: %Y | Month: %B | Day: %d | Weekday: %A", getdata);
	format(string, sizeof(string), "Report by %s, creat in %s, mesaj: %s \r\n ", name, getdata, params);
	new File: fileToWrite = fopen("reports.txt", io_append);
	fwrite(fileToWrite, string);
	fclose(fileToWrite);
	format(adminsreport, sizeof(adminsreport), "%s a trimis un nou /report: %s", name, params);
	SendToAdmins(COLOR_CYAN, adminsreport);
	SendClientMessage(playerid, -1, "Report trimis cu succes! In cel mai scurt timp un admin te va contacta.");
	return 1;
}
Reply
#2

If the /report command works, then the problem is in the /reports command, why don't you try using y_ini? it's way better and faster.
Reply
#3

I actually use y_ini for Register/Login system but I tought that I might not use it for report system.
Reply
#4

Код:
CMD:reports(playerid, params[])
{
	new string[512], string2[512],line[256];
	new File: reports;
        reports = fopen("reports.txt", io_read);
        while(fread(reports,line,sizeof(line),false))
	{
             new idxx;
             string = strtok(line,idxx));
             format(string2, sizeof(string2), "Reporturi existente: \n %s", string);
	     SendClientMessage(playerid, -1, string2);
        }
        fclose(reports);
	return 1;
}
Try this
Reply
#5

Quote:
Originally Posted by VishvaJeet
Посмотреть сообщение
Код:
CMD:reports(playerid, params[])
{
	new string[512], string2[512],line[256];
	new File: reports;
        reports = fopen("reports.txt", io_read);
        while(fread(reports,line,sizeof(line),false))
	{
             new idxx;
             string = strtok(line,idxx));
             format(string2, sizeof(string2), "Reporturi existente: \n %s", string);
	     SendClientMessage(playerid, -1, string2);
        }
        fclose(reports);
	return 1;
}
Try this
That worked, thanks very much!
Reply
#6

lol strtok and fread in 2014

hah still good even if u will get yelled at by others if they see this code just dont tell anyone its fine
Reply
#7

Quote:
Originally Posted by Yochui
Посмотреть сообщение
That worked, thanks very much!
If i helped you please Rep+ me
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)