CMD:bugs(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COL_LIGHTRED, "You can't do that.");
new File:handle = fopen("Bugs.txt", io_read);
new string[256];
if(fexist("Bugs.txt"))
{
while(fread(handle, string))
{
format(string,sizeof(string),"%s\n\r", string);
SendClientMessage(playerid, -1, string);
}
}
else
{
SCM(playerid, COLOR_YELLOW, "There are no bugs.");
}
fclose(handle);
return 1;
}
BUG 1
BUG 2
BUG 3
BUG 4
BUG 5
BUG 6
...
BUG 1
BUG 2
BUG 3
BUG 4
/checkbugs 2 for more.
CMD:bugs(playerid, params[]) { if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COL_LIGHTRED, "You can't do that."); new File:handle = fopen("Bugs.txt", io_read); new string[256],lines = 0,pid = strval(params); //Use sscanf , this code is dangerous if(fexist("Bugs.txt")) { while(fread(handle, string)) { if(++lines < pid*MAX_LINES_PER_PAGE) continue; if(lines%MAX_LINES_PER_PAGE) { format(string,sizeof(string),"%s\n\r", string); SendClientMessage(playerid, -1, string); } else break; } } else { SCM(playerid, COLOR_YELLOW, "There are no bugs."); } fclose(handle); return 1; }
Check if the file handle is valid before using fread and fclose otherwise it might crash the server.
Check if the file exists first and then open it to read from it. |