How to next list ? (Dialogs)
#1

Hi guys, I have a little problem with the pagination dialog. I have a file rules.txt and it got a long text, the text will not fit into dialogs as I do other pages in dialogs?

Код:
#include <a_samp>
#include <zcmd>

CMD:help(playerid) {
        new output[2048], line[512];
        output[0] = EOS;
        new File:tmp=fopen("Rules/rules.txt");
        if(tmp) {
            while(fread(tmp, line, 512)) strins(output, line, strlen(output), sizeof(output));
            fclose(tmp);
        }
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "aaaaa", output, "Cancel", "Next");
        return 1;
}
Code is O.K



Files rules.txt

Код:
1. Rule
2. Rule
3. Rule
4. Rule
5. Rule
6. ...
Reply
#2

Why do you want it to load the rules from a file? If you lose that file (I always clean out scriptfiles), then you will have to re-make it. You can just put it inside the gamemode.

Also, it won't be that optimized with large files. You cannot skip to a certain spot, you would have to read the previous content as well.
Reply
#3

I want it when loading files into the game. I will be scripfiles edit rules, and then appear in the game.

Viz. /help
Reply
#4

Something like this
pawn Код:
#include <a_samp>
#define FILTERSCRIPT
#include <zcmd>
new PlayerPage[MAX_PLAYERS];
new PlayerLinePos[MAX_PLAYERS];

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 11111)
    {
        if(response || PlayerPage[playerid] < 0) return 1;

        new output[2048 char], line[128], flen, len;
        new File:tmp = fopen("Rules/rules.txt");
        if(tmp)
        {
            flen = flength(tmp);
            PlayerPage[playerid] = 0;
            fseek(tmp, PlayerLinePos[playerid]);
            while(++PlayerPage[playerid] < 10 && (len = fread(tmp, line, sizeof(line), true)))
            {
                PlayerLinePos[playerid] += len;
                strcat(output, line);
            }
            fclose(tmp);
        }
        PlayerPage[playerid]++;
        len = PlayerLinePos[playerid];
        if(len >= flen)
            PlayerPage[playerid] = -1;

        ShowPlayerDialog(playerid, 11111, DIALOG_STYLE_MSGBOX, "aaaaa", output, (len >= flen) ? ("Ok") : ("Cancel"), (len >= flen) ? ("") : ("Next"));
        return 1;
    }
    return 0;
}


CMD:help(playerid)
{
    new output[2048 char], line[128], len;
    new File:tmp = fopen("Rules/rules.txt");
    if(tmp)
    {
        PlayerPage[playerid] = 0;
        PlayerLinePos[playerid] = 0;
        fseek(tmp, PlayerLinePos[playerid]);
        while(++PlayerPage[playerid] < 10 && (len = fread(tmp, line, sizeof(line), true)))
        {
            PlayerLinePos[playerid] += len;
            strcat(output, line);
        }

        fclose(tmp);
    }
    ShowPlayerDialog(playerid, 11111, DIALOG_STYLE_MSGBOX, "aaaaa", output, "Cancel", "Next");
    return 1;
}
but will be better if you load full rules into array and then sort by pages
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)