SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 15/11/2013, 11:52 AM   #1
Emmet_
Guest
 
Posts: n/a
Default easyDialog.inc - Dialogs made easier!

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 Code:
#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 Code:
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 Code:
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 Code:
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 Code:
Dialog_Show(playerid, dialog, style, caption[], info[], button1[], button2[]);

Shows a dialog to a player.

pawn Code:
Dialog_Close(playerid);

Closes any opened dialogs.

pawn Code:
Dialog_Opened(playerid);

Returns 1 if the dialog is opened for the specified player.

Download
easyDialog.inc (Pastebin)
easyDialog.inc (Solidfiles)

Example Script (Pastebin)
Example Script (Solidfiles)

This include doesn't work...

a) Update to the newest version
easyDialog was originally released in 2012, and the latest stable version was released on March 31, 2015. You must update to the latest version for the latest features and bug fixes.

pawn Code:
// easyDialog v1.0 Syntax:
ShowDialog(playerid, Show:MyDialog, DIALOG_STYLE_LIST, "List", "Items", "Select", "Cancel");

// easyDialog v2.0 Syntax:
Dialog_Show(playerid, MyDialog, DIALOG_STYLE_LIST, "List", "Items", "Select", "Cancel");

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

b) 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.

Last edited by Emmet_; 05/04/2015 at 12:23 AM.
  Reply With Quote
Old 15/11/2013, 12:24 PM   #2
iZN
High-roller
 
Join Date: Jun 2010
Posts: 2,376
Reputation: 569
Default Re: easyDialog.inc - Dialogs made easier!

Decent work Emmet_. It is good for the scripters who easily gets confused with the dialogs.
__________________
iZN is offline   Reply With Quote
Old 15/11/2013, 12:32 PM   #3
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,844
Reputation: 1399
Default Re: easyDialog.inc - Dialogs made easier!

I used the old include and it was really useful. Of course, I'm going to use the new version of it! Everything is great and the new callback, then only thing I don't get is how/where to use Dialog_Call function. Would you mind to give an example?

Thanks and great job!
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 15/11/2013, 12:33 PM   #4
xSiiLenTx
Huge Clucker
 
xSiiLenTx's Avatar
 
Join Date: Dec 2011
Location: United Kingdom
Posts: 338
Reputation: 77
Default Re: easyDialog.inc - Dialogs made easier!

Sent this to my scripter for my server, thank you very much +rep
xSiiLenTx is offline   Reply With Quote
Old 15/11/2013, 12:42 PM   #5
Emmet_
Guest
 
Posts: n/a
Default Re: easyDialog.inc - Dialogs made easier!

Thanks guys!

Quote:
Originally Posted by Konstantinos View Post
I used the old include and it was really useful. Of course, I'm going to use the new version of it! Everything is great and the new callback, then only thing I don't get is how/where to use Dialog_Call function. Would you mind to give an example?

Thanks and great job!
Thanks for the feedback!

It's for explicitly calling a dialog. For example, if I had this dialog in my script:

pawn Code:
Dialog:MyDialog(playerid, response, listitem, inputtext[])
{
    if (response)
    {
        // Some code here.
    }
}

And I wanted to execute the code after if (response) then I would do this:

pawn Code:
Dialog_Call("MyDialog", playerid, 1, 0, "\1");

However, the last parameter must be "\1" or " " instead of "" due to a glitch with the "CallLocalFunction" function. The explanation might be a bit difficult at first; sorry about that.
  Reply With Quote
Old 15/11/2013, 01:17 PM   #6
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,844
Reputation: 1399
Default Re: easyDialog.inc - Dialogs made easier!

It's alright, I understood it. Thanks for the explanation.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 15/11/2013, 05:14 PM   #7
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,893
Reputation: 1321
Default Re: easyDialog.inc - Dialogs made easier!

I think this look pretty good one thing I think could have been done differently is this.

Doing this looks ugly to me and doesn't really make sense given the way dialogs are organized with your include in this manner.

pawn Code:
public OnDialogReceived(playerid, dialog[], success)
{
    if (!strcmp(dialog, "WeaponMenu") && IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid, -1, "You must be on-foot to spawn a weapon.");
        return 0;
    }
    return 1;
}

This makes a lot more sense to me

pawn Code:
DialogRecieved:WeaponMenu(playerid, success)
Pottus is offline   Reply With Quote
Old 15/11/2013, 05:28 PM   #8
Emmet_
Guest
 
Posts: n/a
Default Re: easyDialog.inc - Dialogs made easier!

Quote:
Originally Posted by [uL]Pottus View Post
I think this look pretty good one thing I think could have been done differently is this.

Doing this looks ugly to me and doesn't really make sense given the way dialogs are organized with your include in this manner.

pawn Code:
public OnDialogReceived(playerid, dialog[], success)
{
    if (!strcmp(dialog, "WeaponMenu") && IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid, -1, "You must be on-foot to spawn a weapon.");
        return 0;
    }
    return 1;
}

This makes a lot more sense to me

pawn Code:
DialogRecieved:WeaponMenu(playerid, success)
That's a better concept than mine, thanks!

I was thinking that "WeaponMenu" for example could be a real constant ID rather than a disguised string, so then I can do something like:

pawn Code:
public OnDialogReceived(playerid, dialog, response)
{
    if (dialog == WeaponMenu)
    {
        // code
    }
    return 1;
}
  Reply With Quote
Old 15/11/2013, 05:38 PM   #9
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,893
Reputation: 1321
Default Re: easyDialog.inc - Dialogs made easier!

I think it's best to keep consistent with the established style it makes it easier to group code because who knows where OnDialogReceived() is going to be in location.
Pottus is offline   Reply With Quote
Old 15/11/2013, 07:14 PM   #10
Swedky
Banned
 
Join Date: Jun 2013
Location: Argentina.
Posts: 2,042
Reputation: 827
Default Respuesta: easyDialog.inc - Dialogs made easier!

Nice!

Last edited by Swedky; 07/11/2015 at 07:21 AM.
Swedky is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
easydialog.inc Beckett Scripting Help 6 29/12/2016 12:13 PM
What do you hate to do when making a gamemode, and how can it be made easier? Slice Scripting Help 16 31/07/2012 08:37 AM
Simple way to make tabling easier in dialogs? BlackBank Scripting Help 1 02/09/2011 05:59 PM
Quiz made with dialogs Matej_ Help Archive 9 15/09/2010 07:12 PM


All times are GMT. The time now is 02:27 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.