//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[])
DIALOG:0(playerid,response,listitem,inputtext[])
{
//This will handle OnDialogResponse for dialogid 0!
return 1;
}
#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;
}
if(dialogid > MAX_DIALOGS)
|| dialogid < 0
Nice work.
Looking at pastebin i saw this: Код:
if(dialogid > MAX_DIALOGS) Add also Код:
|| dialogid < 0 |
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.
|
//This will work:
DIALOG:1337(parameters)
{
}
//This wont work:
#define test 1337
DIALOG:test(parameters)
{
}
/*
* 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
stock SD_ShowPlayerDialog(playerid,dialogid) { return ShowPlayerDialog(playerid,dialogid,DialogDetails[dialogid][_style],DialogDetails[dialogid][_caption],DialogDetails[dialogid][_info],DialogDetails[dialogid][_button1],DialogDetails[dialogid][_button2]); }
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? |
How are you doing that? Are you hashing the name to give a unique ID for the dialog, or just allocating IDs in order?
|
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). |
Awesome . It's similiar to my system released some months ago. (Sasi-Dialogs)
|
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
}
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
|
I like it, this will help a lot of new guys who are always having problems with if statements
nice script. |