Guest User

easyDialog.inc

a guest
May 6th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.17 KB | None | 0 0
  1. /*
  2.     easyDialog.inc - Dialogs made easier!
  3.  
  4.     With this useful include, scripters can easily create
  5.     dialogs and show them to players.
  6.  
  7.     This include will prevent dialog spoofing, ID collision
  8.     and a lot more.
  9.  
  10.     Created by Emmet on Friday, January 24, 2014.
  11. */
  12.  
  13. #if !defined isnull
  14.     #define isnull(%1) \
  15.         ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  16. #endif
  17.  
  18. #define Dialog:%0(%1) \
  19.     forward dialog_%0(%1); public dialog_%0(%1)
  20.  
  21. #define Dialog_Show(%0,%1, \
  22.     Dialog_Open(%0, #%1,
  23.  
  24. #define Dialog_Opened(%0) \
  25.     (CallRemoteFunction("Dialog_IsOpened", "i", (%0)))
  26.  
  27. static
  28.     s_DialogName[MAX_PLAYERS][32 char],
  29.     s_DialogOpened[MAX_PLAYERS]
  30. ;
  31.  
  32. forward OnDialogPerformed(playerid, dialog[], response, success);
  33.  
  34. forward @dialog_format(); @dialog_format() {
  35.     format("", 0, "");
  36. }
  37.  
  38. forward Dialog_IsOpened(playerid);
  39. public Dialog_IsOpened(playerid)
  40. {
  41.     return (s_DialogOpened[playerid]);
  42. }
  43.  
  44. stock Dialog_Close(playerid)
  45. {
  46.     s_DialogName[playerid]{0} = 0;
  47.     s_DialogOpened[playerid] = 0;
  48.  
  49.     return ShowPlayerDialog(playerid, -1, DIALOG_STYLE_MSGBOX, " ", " ", " ", "");
  50. }
  51.  
  52. stock Dialog_Open(playerid, function[], style, caption[], info[], button1[], button2[], {Float,_}:...)
  53. {
  54.     static
  55.         string[4096],
  56.         args
  57.     ;
  58.  
  59.     if (!strlen(info))
  60.     {
  61.         return 0;
  62.     }
  63.     if ((args = numargs()) > 7)
  64.     {
  65.         while (--args >= 7)
  66.         {
  67.             #emit LCTRL 5
  68.             #emit LOAD.alt args
  69.             #emit SHL.C.alt 2
  70.             #emit ADD.C 12
  71.             #emit ADD
  72.             #emit LOAD.I
  73.             #emit PUSH.pri
  74.         }
  75.         #emit PUSH.S info
  76.         #emit PUSH.C 4096
  77.         #emit PUSH.C string
  78.  
  79.         #emit LOAD.S.pri 8
  80.         #emit CONST.alt 16
  81.         #emit SUB
  82.         #emit PUSH.pri
  83.  
  84.         #emit SYSREQ.C format
  85.         #emit LCTRL 5
  86.         #emit SCTRL 4
  87.  
  88.         ShowPlayerDialog(playerid, 32700, style, caption, string, button1, button2);
  89.     }
  90.     else
  91.     {
  92.         ShowPlayerDialog(playerid, 32700, style, caption, info, button1, button2);
  93.     }
  94.     s_DialogOpened[playerid] = 1;
  95.  
  96.     strpack(s_DialogName[playerid], function, 32 char);
  97.  
  98.     return 1;
  99. }
  100.  
  101. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  102. {
  103.     static
  104.         s_Public = cellmax;
  105.  
  106.     if (s_Public == cellmax)
  107.     {
  108.         s_Public = funcidx("OnDialogPerformed");
  109.     }
  110.  
  111.     // Sanitize inputs.
  112.     for (new i = 0, l = strlen(inputtext); i < l; i ++)
  113.     {
  114.         if (inputtext[i] == '%')
  115.         {
  116.             inputtext[i] = '#';
  117.         }
  118.     }
  119.     if (dialogid == 32700 && strlen(s_DialogName[playerid]) > 0)
  120.     {
  121.         new
  122.             string[40];
  123.  
  124.         strcat(string, "dialog_");
  125.         strcat(string, s_DialogName[playerid]);
  126.  
  127.         Dialog_Close(playerid);
  128.  
  129.         if ((s_Public == -1) || (CallLocalFunction("OnDialogPerformed", "dsdd", playerid, string[7], response, funcidx(string) != -1)))
  130.         {
  131.             CallLocalFunction(string, "ddds", playerid, response, listitem, (!inputtext[0]) ? ("\1") : (inputtext));
  132.         }
  133.     }
  134.     #if defined DR_OnDialogResponse
  135.         return DR_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
  136.     #else
  137.         return 0;
  138.     #endif
  139. }
  140.  
  141. #if defined _ALS_OnDialogResponse
  142.     #undef OnDialogResponse
  143. #else
  144.     #define _ALS_OnDialogResponse
  145. #endif
  146.  
  147. #define OnDialogResponse DR_OnDialogResponse
  148.  
  149. #if defined DR_OnDialogResponse
  150.     forward DR_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  151. #endif
Add Comment
Please, Sign In to add comment