SA-MP Forums Archive
fxShowPlayerDialog no dialog id event only - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: fxShowPlayerDialog no dialog id event only (/showthread.php?tid=598275)



fxShowPlayerDialog no dialog id event only - diclofoss - 10.01.2016

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
PHP код:
new PlayerDialogFunc[MAX_PLAYERS][90];
new 
PlayerDialogStyle[MAX_PLAYERS];
fxShowPlayerDialog(playeridcallback[], dialogStyleheader[], text[], button1[], button2[]) {
    new 
fxCallback[32];
    
format(fxCallbacksizeof(fxCallback), "%s"callback);
    
PlayerDialogFunc[playerid] = fxCallback;
    
PlayerDialogStyle[playerid] = dialogStyle;
    
ShowPlayerDialog(playeridplayeriddialogStyleheadertextbutton1button2);

Next implement OnDialogResponse
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[]) {
    switch (
PlayerDialogStyle[playerid]) {
        case 
DIALOG_STYLE_MSGBOX: {
            return 
CallLocalFunction(PlayerDialogFunc[playerid], "ii"playeridresponse);
        }
        case 
DIALOG_STYLE_INPUTDIALOG_STYLE_PASSWORD: {
            new 
formatedInput[256];
            
format(formatedInputsizeof(formatedInput), "%s"inputtext);
            if (
isnull(formatedInput)) {
                
printf("FormattedInput is null: |%s|"formatedInput);
                return 
CallLocalFunction(PlayerDialogFunc[playerid], "iis"playeridresponse"\1");
            }
            
printf("Input: |%s|"formatedInput);
            return 
CallLocalFunction(PlayerDialogFunc[playerid], "iis"playeridresponseformatedInput);
        }
        default: {
            return 
CallLocalFunction(PlayerDialogFunc[playerid], "iii"playeridresponselistitem);
        }
    }
    return 
0;

After that in some part of your code you may use fxShowPlayerDialog
PHP код:
...
fxShowPlayerDialog(playerid"sampnet_onDialogAgreement"DIALOG_STYLE_MSGBOXAgreement[CurAgreementPage[playerid]][agreement_title], Agreement[CurAgreementPage[playerid]][agreement_text], "Next""");
...
forward sampnet_onDialogAgreement(playeridresponse);
public 
sampnet_onDialogAgreement(playeridresponse) {
    
CurAgreementPage[playerid]++;
    
sampnet_gamemode_showAgreement(playerid);

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


Re: fxShowPlayerDialog no dialog id event only - PrO.GameR - 10.01.2016

Erm, Do you have some benchmark test ? I would love to see a benchmark on this and the normal callback to see if it would differ much to use your way, It perfectly organizes your code sure, but does it also make it awfully slow or not ?

Also this is posted in wrong place, should be moved under tutorials or code snippets or sth, idk.


Re: fxShowPlayerDialog no dialog id event only - diclofoss - 10.01.2016

Hello!
Thank you for your response. I will create new thread in proper place. As soon as gamemode will be ready I'll update you with results of benchmark. The bottleneck as I may see now is much public callbacks. But I still not sticked on it before.
Moved: https://sampforum.blast.hk/showthread.php?tid=598301