Reading all lines from a file and showing them using (dialog or client message)
#1

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?
Reply
#2

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);
Reply
#3

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.
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)