SA-MP Forums Archive
Reading all lines from a file and showing them using (dialog or client message) - 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: Reading all lines from a file and showing them using (dialog or client message) (/showthread.php?tid=529759)



Reading all lines from a file and showing them using (dialog or client message) - Stinged - 03.08.2014

I've been searching for hours and I couldn't find a topic that helped me.
I'm sure someone already answered this, but I can't find it.

So I'm trying to make a file which logs all the warns a player got.
Everything was working well, until I wanted to load them and show them using dialogs or client messages.


How can I load each line with their \n and use them in a msgbox dialog?


Re: Reading all lines from a file and showing them using (dialog or client message) - Jefff - 03.08.2014

pawn Code:
new File:Warns = fopen("filename.txt",io_read);
if(!Warns) return 0;
new str[128],warndstr[500],len;
while((len = fread(Warns,str)))
{
str[len - 1] = 0;
strcat(warnstr,str);
}
fclose(Warns);
if(warnstr[0] != EOS)
{
// ShowPlayerDialog(...);
}
or

pawn Code:
while((len = fread(Warns,str)))
{
str[len - 2] = 0;
SendClientMessage(playerid,-1,str);
}
fclose(Warns);



Re: Reading all lines from a file and showing them using (dialog or client message) - SickAttack - 03.08.2014

Quote:
Originally Posted by Stinged
View Post
I've been searching for hours and I couldn't find a topic that helped me.
I'm sure someone already answered this, but I can't find it.

So I'm trying to make a file which logs all the warns a player got.
Everything was working well, until I wanted to load them and show them using dialogs or client messages.


How can I load each line with their \n and use them in a msgbox dialog?
You're trying to do something that isn't efficient at all. Once you have a mass file and everytime you attempt to list the results the server will lag (for everyone), imagine a player that's spamming the command or a player that requests results at a fast speed, the server would be in lag mode. It's not worth it.

Anyways, the code that Jefff posted will get the job done.


Re: Reading all lines from a file and showing them using (dialog or client message) - Stinged - 03.08.2014

Thanks for the help Jefff.

SickAttack, I was actually thinking about a way to stop the creation of a massive file full of warns... I might just make a max warns and ban after that.

EDIT: It was removing the last 2 characters of the last line, so I removed the - 2 from str[len - 2] and it worked.