10.01.2016, 16:01
(
Последний раз редактировалось diclofoss; 10.01.2016 в 19:25.
)
Hello!
The is too much complex for me to create DIALOG_ID for each dialog in my mode. So wrapped Showplayedialog with some trick.
The main idea is that player can't view more than 1 dialog at the same time.
Just want to share. Comments are welcome:
First declare fxShowPlayerDialog
Next implement OnDialogResponse
After that in some part of your code you may use fxShowPlayerDialog
So you don't need to create DIALOG_ID for each dialog. You don't need to add code into OnDialogResponse too.
Just call dialog and implement callback.
BTW:
For different styles of dialog you should implement different type of callbacks.
Hope it helps somebody.
UPDATE: Fix issue with empty input
The is too much complex for me to create DIALOG_ID for each dialog in my mode. So wrapped Showplayedialog with some trick.
The main idea is that player can't view more than 1 dialog at the same time.
Just want to share. Comments are welcome:
First declare fxShowPlayerDialog
PHP код:
new PlayerDialogFunc[MAX_PLAYERS][90];
new PlayerDialogStyle[MAX_PLAYERS];
fxShowPlayerDialog(playerid, callback[], dialogStyle, header[], text[], button1[], button2[]) {
new fxCallback[32];
format(fxCallback, sizeof(fxCallback), "%s", callback);
PlayerDialogFunc[playerid] = fxCallback;
PlayerDialogStyle[playerid] = dialogStyle;
ShowPlayerDialog(playerid, playerid, dialogStyle, header, text, button1, button2);
}
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
switch (PlayerDialogStyle[playerid]) {
case DIALOG_STYLE_MSGBOX: {
return CallLocalFunction(PlayerDialogFunc[playerid], "ii", playerid, response);
}
case DIALOG_STYLE_INPUT, DIALOG_STYLE_PASSWORD: {
new formatedInput[256];
format(formatedInput, sizeof(formatedInput), "%s", inputtext);
if (isnull(formatedInput)) {
printf("FormattedInput is null: |%s|", formatedInput);
return CallLocalFunction(PlayerDialogFunc[playerid], "iis", playerid, response, "\1");
}
printf("Input: |%s|", formatedInput);
return CallLocalFunction(PlayerDialogFunc[playerid], "iis", playerid, response, formatedInput);
}
default: {
return CallLocalFunction(PlayerDialogFunc[playerid], "iii", playerid, response, listitem);
}
}
return 0;
}
PHP код:
...
fxShowPlayerDialog(playerid, "sampnet_onDialogAgreement", DIALOG_STYLE_MSGBOX, Agreement[CurAgreementPage[playerid]][agreement_title], Agreement[CurAgreementPage[playerid]][agreement_text], "Next", "");
...
forward sampnet_onDialogAgreement(playerid, response);
public sampnet_onDialogAgreement(playerid, response) {
CurAgreementPage[playerid]++;
sampnet_gamemode_showAgreement(playerid);
}
Just call dialog and implement callback.
BTW:
For different styles of dialog you should implement different type of callbacks.
Hope it helps somebody.
UPDATE: Fix issue with empty input