[Include] gDialog - Easyer way of managing dialogs!
#1

gDialog 1.0
Functions
pawn Код:
//Creating a dialog and saving them into memory (usefull when you need to re-use them multiple times)
native CreateDialog(dialogid,style,caption[],info[],button1[],button2[])

//Showing saved dialogs:
native ShowPlayerDialog(playerid,dialogid)

//Showing dialogs normally like the normal ShowPlayerDialog()
native ShowPlayerDialogEx(playerid,dialogid,style,caption[],info[],button1[],button2[])
Callbacks NEW!
You can still use OnDialogResponse, BUT you can also use this method:
pawn Код:
DIALOG:0(playerid,response,listitem,inputtext[])
{
    //This will handle OnDialogResponse for dialogid 0!
    return 1;
}
Example usage
pawn Код:
#include <a_samp>
#include <gDialog>

public OnFilterScriptInit()
{
    /*
        CreateDialog(dialogid,style,caption[],info[],button1[],button2[])
        -Creates a dialog that you can use later again with ShowPlayerDialog()
    */

    CreateDialog(0,DIALOG_STYLE_INPUT,"Spawning a vehicle","Please type a VehicleID here","OK","Cancel");
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/car", cmdtext, true, 10) == 0)
    {
        /*
            ShowPlayerDialog(playerid,dialogid)
            -Shows the dialog created with CreateDialog()
        */

        ShowPlayerDialog(playerid,0);
        return 1;
    }
   
    if (strcmp("/tele", cmdtext, true, 10) == 0)
    {
        /*
            ShowPlayerDialogEx(playerid,dialogid,style,caption[],info[],button1[],button2[])
            -Simular to the normal ShowPlayerDialog(), shows the dialog directly to player without futher saving it.
        */

        ShowPlayerDialogEx(playerid,1,DIALOG_STYLE_LIST,"Select a teleport","San Fierro\r\nLas Venturas\r\nLos Santos","OK","Cancel");
        return 1;
    }
    return 0;
}

/*
    *NEW!*  Method of handling dialogs:
   
    DIALOG:dialogid(playerid,response,listitem,inputtext[])
   
    This will handle everything of the id defined at DIALOG:idhere (simular to OnDialogResponse)
    WILL WORK ON ShowPlayerDialog() AND ShowPlayerDialogEX!!! (you can also still use OnDialogResponse() if you preffer!)
*/

DIALOG:0(playerid,response,listitem,inputtext[])
{
    if(response)
    {
        new Float:x,Float:y,Float:z;GetPlayerPos(playerid,x,y,z);
        new v = AddStaticVehicle(strval(inputtext),x,y,z,0,-1,-1);
        PutPlayerInVehicle(playerid,v,0);
    }
    return 1;
}

DIALOG:1(playerid,response,listitem,inputtext[])
{
    switch(listitem)
    {
        case 0: SetPlayerPos(playerid,0,0,0);
        case 1: SetPlayerPos(playerid,0,0,0);
        case 2: SetPlayerPos(playerid,0,0,0);
    }
    return 1;
}
Special thanks to
Zeex for ZCMD (to spy a bit on the source checking how to define the DIALOG: part)
****** for a little bit help

Download:
Pastebin
SA-MP
Reply
#2

Epic u nub
Reply
#3

NICE! COMPACT AND LIGHT!

- Tank Dempsey

Really useful for me! thanks a lot
Rep++;
Reply
#4

Nice work.
Looking at pastebin i saw this:
Код:
if(dialogid > MAX_DIALOGS)
I don't know if it is possibile as i never tried for a dialog, but with this condition users can CreateDialogs with negative numbers, and obviously won't work in an array.
Add also
Код:
|| dialogid < 0
:P
Reply
#5

Quote:
Originally Posted by Phanto90
Посмотреть сообщение
Nice work.
Looking at pastebin i saw this:
Код:
if(dialogid > MAX_DIALOGS)
I don't know if it is possibile as i never tried for a dialog, but with this condition users can CreateDialogs with negative numbers, and obviously won't work in an array.
Add also
Код:
|| dialogid < 0
:P
Healthy people will not use id's below zero anyway, if they would they should seriously think about following some tutorials about how to script.

Quote:
Originally Posted by ******
Посмотреть сообщение
One of the major drawbacks to the current dialog system is it's reliance on explicit IDs, instead of creating a dialog and having it return the ID of the slot in which it is created. That would IMHO be the first thing to sort out in a dialog script.
You mean i should automaticly let it create id's so people cannot make mistakes with this anymore ?
Well i tried adding this, but caught a few problems with this since "DIALOG:variable" doesnt work, and if people use filterscripts NOT created by themself it will CREATE conflicting ID's because it isnt allowing users to pick there own id instead of "fixing" this common problem.

Example:
pawn Код:
//This will work:
DIALOG:1337(parameters)
{

}

//This wont work:
#define test 1337
DIALOG:test(parameters)
{

}
Same story with the variables... gotto fix that somehow before getting a id system to work.
Reply
#6

Awesomeeee.
Reply
#7

Epic >.< awasome thanks
Reply
#8

Im using first version of this script, its outdated? o,o
Reply
#9

nice work
Reply
#10

So.. Im using Gamer_Z release, which has same defines at all..

pawn Код:
/*
 *  Fast Dialog Processing System
 *
 *  Version 1.1
 *
 *  By Gamer_Z
 *
 *  for SSI (SA-MP Server Includes)
 *
 *  Released under MPL v1.1
 *
 *  A copy of the license can be obtained at
 *  http://www.mozilla.org/MPL/MPL-1.1.txt
 *
 */


//#define FDLG_NO_DISABLE_CALLBACK
//#define FDLG_USE_YSI_HOOK

#include <a_samp>

#if defined _FAST_DIALOG_INCLUDED_
    #endinput
#else
    #define _FAST_DIALOG_INCLUDED_
#endif

#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif

 //Own Definition Dialog
//Usage:: DIALOG:dialogid(playerid,response,listitem,inputtext[])
#define DIALOG:%1(%2,%3,%4,%5) \
    forward GDialog_%1(%2,%3,%4,%5);\
    public GDialog_%1(%2,%3,%4,%5)

 //FastDialog
//Usage:: fDialog(dialogid)
#define fDialog(%1) \
    forward GDialog_%1(playerid,response,listitem,inputtext[]);\
    public GDialog_%1(playerid,response,listitem,inputtext[])

new g__FDLG_PRIV_CALLBACK[24];
#if defined FDLG_USE_YSI_HOOK
    #include <YSI/y_hooks>

    #if defined FDLG_NO_DISABLE_CALLBACK
        Hook:FastDialog_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
        {
            format(g__FDLG_PRIV_CALLBACK,24,"GDialog_%d",dialogid);
            if(isnull(inputtext))format(inputtext,2,"\1");
            if(funcidx(g__FDLG_PRIV_CALLBACK) != -1)
            {
                return CallLocalFunction(g__FDLG_PRIV_CALLBACK,"iiis",playerid,response,listitem,inputtext);
            }
            return CallLocalFunction("_ALS_OnDialogResponse","iiiis",playerid, dialogid, response, listitem, inputtext);
            //return 1;
        }
    #else
        Hook:FastDialog_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
        {
            format(g__FDLG_PRIV_CALLBACK,24,"GDialog_%d",dialogid);
            if(isnull(inputtext))format(inputtext,2,"\1");
            return CallLocalFunction(g__FDLG_PRIV_CALLBACK,"iiis",playerid,response,listitem,inputtext);
        }
    #endif
#else
    #if defined FDLG_NO_DISABLE_CALLBACK
        public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
        {
            format(g__FDLG_PRIV_CALLBACK,24,"GDialog_%d",dialogid);
            if(isnull(inputtext))format(inputtext,2,"\1");
            if(funcidx(g__FDLG_PRIV_CALLBACK) != -1)
            {
                return CallLocalFunction(g__FDLG_PRIV_CALLBACK,"iiis",playerid,response,listitem,inputtext);
            }
            return CallLocalFunction("FDLG_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,inputtext);
        }
        forward FDLG_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
        #define OnDialogResponse FDLG_OnDialogResponse
    #else
        public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
        {
            format(g__FDLG_PRIV_CALLBACK,24,"GDialog_%d",dialogid);
            if(isnull(inputtext))format(inputtext,2,"\1");
            return CallLocalFunction(g__FDLG_PRIV_CALLBACK,"iiis",playerid,response,listitem,inputtext);
        }
        forward DisabledPublicByFastDialog(playerid, dialogid, response, listitem, inputtext[]);
        #define OnDialogResponse DisabledPublicByFastDialog
    #endif
#endif
Im using DIALOG:id(..); "way" to create dialogs, so probably I just need

ctrl + h

ShowPlayerDialog(

to

ShowPlayerDialogEx(

and yes to all?
Reply
#11

Basicly yes, and hmm i heard from a friend on msn that there was already something like this... but i never found it/watched the source and it looks a lot the same 0,o even the name "GDialog"... a bit scary lol
Reply
#12

So, which one is faster? Yours or Gamer_Z?
Reply
#13

Well we would need to compare them (however i think mine is faster cuz it doesn't use such variables?, well we will see) and em
would
inputtext[] == "\0" not crash the server using your script?

soon I'm going to release a new system where you can use ShowDialogn("dialog name") (well will not be as fast as my GDialog but ok lol)

Very nice feature of this script is:
Код:
stock SD_ShowPlayerDialog(playerid,dialogid)
{
        return ShowPlayerDialog(playerid,dialogid,DialogDetails[dialogid][_style],DialogDetails[dialogid][_caption],DialogDetails[dialogid][_info],DialogDetails[dialogid][_button1],DialogDetails[dialogid][_button2]);
}
Heh pre saved dialogs
Reply
#14

Quote:
Originally Posted by Gamer_Z
Посмотреть сообщение
Well we would need to compare them (however i think mine is faster cuz it doesn't use such variables?, well we will see) and em
would
inputtext[] == "\0" not crash the server using your script?
About the "\0", can you give me more details about that "bug" ?
And well about the speed, you dont have to save it (you can still use ShowPlayerDialogEx()) which equals to the regular ShowPlayerDialog (only also handling the custom callback).
Reply
#15

It would be a very very good include but there is one problem...
You can't use defines for Dialogs. Without defines i wouldn't find any Dialog in my script :P

But for scripts, which don't use defines it is a very good solution to speed up it. Good Work !
Reply
#16

Quote:
Originally Posted by ******
Посмотреть сообщение
How are you doing that? Are you hashing the name to give a unique ID for the dialog, or just allocating IDs in order?
CSTL Data Containers
Reply
#17

A little feature request:

"GetDialogInfo(dialogid)" would be a very handy function.
Reply
#18

Quote:
Originally Posted by gamer931215
Посмотреть сообщение
About the "\0", can you give me more details about that "bug" ?
And well about the speed, you dont have to save it (you can still use ShowPlayerDialogEx()) which equals to the regular ShowPlayerDialog (only also handling the custom callback).
CallLocalFunction - if any string parameter is NULL - server crashes.

Also I made the first version of named dialogs, hope you enjoy it.
Reply
#19

Awesome . It's similiar to my system released some months ago. (Sasi-Dialogs)
Reply
#20

Quote:
Originally Posted by [GF]Sasino97
Посмотреть сообщение
Awesome . It's similiar to my system released some months ago. (Sasi-Dialogs)
well for input text I check that :P

but This script doesn't..
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
        new function[32];format(function,sizeof function,"dlg_%i",dialogid);
        CallLocalFunction(function,"iiis",playerid,response,listitem,inputtext);//here
        return CallLocalFunction("SD_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,inputtext);//here too
}
Also ******, as you see the script is there (Named Dialogs),
what do you think of it?
_
Quote:
Originally Posted by gamer931215
Посмотреть сообщение
Basicly yes, and hmm i heard from a friend on msn that there was already something like this... but i never found it/watched the source and it looks a lot the same 0,o even the name "GDialog"... a bit scary lol
Quote:
Originally Posted by gamer931215
Посмотреть сообщение
I like it, this will help a lot of new guys who are always having problems with if statements
nice script.
If it gets to your brain you are not the best in remembering things xD
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)