[Include] easyDialog.inc - Dialogs made easier!
#1

This include is originally created by Emmet_ but will be maintained by me.

easyDialog.inc

Introduction
I've released this include a little over a year ago. However, it didn't have many features and it wasn't crash proof, so I've decided to scrap it and rewrite the whole include from scratch.

Purpose
The purpose of this include is to make dialogs easier to use in general.

Imagine having over 100 dialog checks under OnDialogResponse. It's just too messy and most of the time, it's unorganized and harder to look for certain dialogs for future editing, and remembering certain dialog ID's can be a pain in the ass.

However, easyDialog.inc fixes that by introducing a "named dialog feature" which allows scripters to declare a dialog by name, rather than ID.

FeatureOnDialogResponseeasyDialog.inc
Crash ProofNoYes
Named DialogsNoYes
Calling a dialog manuallyNoYes
Custom callback for handlingNoYes
This code:

pawn Код:
#define DIALOG_WEAPON (1337)

CMD:weapons(playerid, params[])
{
    ShowPlayerDialog(playerid, DIALOG_WEAPON, DIALOG_STYLE_LIST, "Weapon Menu", "9mm\nSilenced 9mm\nDesert Eagle\nShotgun\nSawn-off Shotgun\nCombat Shotgun", "Select", "Cancel");
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if (dialogid == DIALOG_WEAPON)
    {
        if (response)
        {
            new str[64];
            format(str, 64, "You have selected the '%s'.", inputtext);

            GivePlayerWeapon(playerid, listitem + 22, 500);
            SendClientMessage(playerid, -1, str);
        }
    }
    return 1;
}
Turns into this code:

pawn Код:
CMD:weapons(playerid, params[])
{
    Dialog_Show(playerid, WeaponMenu, DIALOG_STYLE_LIST, "Weapon Menu", "9mm\nSilenced 9mm\nDesert Eagle\nShotgun\nSawn-off Shotgun\nCombat Shotgun", "Select", "Cancel");
    return 1;
}

Dialog:WeaponMenu(playerid, response, listitem, inputtext[])
{
    if (response)
    {
        new str[64];
        format(str, 64, "You have selected the '%s'.", inputtext);

        GivePlayerWeapon(playerid, listitem + 22, 500);
        SendClientMessage(playerid, -1, str);
    }
    return 1;
}
I think the second example is much more neater, especially for larger scripts.

Callback
This script introduces a new callback:

pawn Код:
public OnDialogPerformed(playerid, dialog[], response, success)
{
    return 1;
}
This callback is called before a dialog is shown to a player (using Dialog_Show, that is). Returning 0 under this callback will prevent the dialog from working.

pawn Код:
public OnDialogPerformed(playerid, dialog[], response, success)
{
    if (!strcmp(dialog, "WeaponMenu") && IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid, -1, "You must be on-foot to spawn a weapon.");
        return 0;
    }
    return 1;
}
Very simple, isn't it?

Functions
This include introduces several new useful functions:

pawn Код:
Dialog_Show(playerid, dialog, style, caption[], info[], button1[], button2[], {Float,_}:...);
Shows a dialog to a player.

pawn Код:
Dialog_Close(playerid);
Closes any opened dialogs.

pawn Код:
Dialog_Opened(playerid);
Returns 1 if the dialog is opened for the specified player.

Download
easyDialog.inc (Github)

If this include doesn't work...

a) Includes and filterscripts
Returning 0 under OnDialogResponse will pass the dialog to other scripts containing the callback. However, certain filterscripts and third-party libraries might return 1 instead. This interferes with the inner workings of easyDialog and causes the dialogs to not work.

Simply return 0 instead to fix the issue.

easyDialog works in parallel with OnDialogResponse, so you can use both at the same time. Older versions do not support this.
Reply
#2

Thanks for reposting!

#PeaceOutToEmmet_
Reply
#3

I hope you will update it and won't let it die, it's one of my favorite includes. I might create some pull requests soon, I've made some changes to the include for my personal use which might come handy for other people.
Reply
#4

Is this still the best dialog system? I saw some others pop up so i don't know which one to use
Reply
#5

noice to see someone maintaining this include
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)