/seebugs cmd
#1

I'm having a small problem with my cmd.

PHP код:
CMD:bugs(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playeridCOL_LIGHTRED"You can't do that.");
    
    new 
File:handle fopen("Bugs.txt"io_read);
     new 
string[256];
     
     if(
fexist("Bugs.txt"))
    {
        while(
fread(handlestring))
        {
            
format(string,sizeof(string),"%s\n\r"string);
            
SendClientMessage(playerid, -1string);
        }
    }
    else
    {
        
SCM(playeridCOLOR_YELLOW"There are no bugs.");
    }
    
     
fclose(handle);
     return 
1;

If this command is being performed by anyone, it will be shown like this.

PHP код:
BUG 1 
BUG 2
BUG 3
BUG 4
BUG 5
BUG 6
... 
It will continue to show all bugs. So, well, my question is: is there any way to split the bugs into more pages? Actually, I think there is, but I can't figure this out for myself.

Here's an example (my idea).

PHP код:
BUG 1 
BUG 2
BUG 3
BUG 4
/checkbugs 2 for more
Reply
#2

I have given an idea.It is now left to you to improve the code.
Код:
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;
}
Reply
#3

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.

I find using dialogs for such things much better instead of spamming the chat and with the possibility of not being able to read all of them because online players chat.
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
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.
Can you give me an example?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)