Advertisement
Guest User

easyDialog update by TonY

a guest
Feb 10th, 2020
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.26 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.     Updated by Southclaws 2017-10-13 to add include guard.
  13.  
  14.     Updated by TonY 2020-02-10 to speed up the code execution
  15. */
  16.  
  17. #if defined _easyDialog_included
  18.     #endinput
  19. #endif
  20. #define _easyDialog_included
  21.  
  22. #include <YSI_Coding\y_hooks>
  23. #include <YSI_Coding\y_va>
  24.  
  25. #define Dialog:%0(%1) \
  26.     forward dialog_%0(%1); public dialog_%0(%1)
  27.  
  28. #define Dialog_Show(%0,%1, \
  29.     Dialog_Open(%0, #%1,
  30.  
  31. static
  32.     s_DialogName[MAX_PLAYERS][32 char];
  33.  
  34.  
  35. /// ---
  36. /// API
  37. /// ---
  38.  
  39. forward OnDialogPerformed(playerid, const dialog[], response, success);
  40.  
  41.  
  42. /// ---
  43. /// Functions
  44. /// ---
  45.  
  46. stock Dialog_Close(playerid)
  47. {
  48.     s_DialogName[playerid]{0} = 0;
  49.  
  50.     return ShowPlayerDialog(playerid, -1, DIALOG_STYLE_MSGBOX, " ", " ", " ", "");
  51. }
  52.  
  53. stock Dialog_Open(playerid, const function[], style, const caption[], const info[], const button1[], const button2[], {Float,_}:...)
  54. {
  55.     static
  56.         string[4096];
  57.  
  58.     if (info[0] == EOS) {
  59.         return 0;
  60.     }
  61.  
  62.     if (numargs() > 7)
  63.     {
  64.         va_format(string, sizeof(string), info, ___(7));
  65.  
  66.         ShowPlayerDialog(playerid, 32700, style, caption, string, button1, button2);
  67.     }
  68.     else
  69.     {
  70.         ShowPlayerDialog(playerid, 32700, style, caption, info, button1, button2);
  71.     }
  72.  
  73.     strpack(s_DialogName[playerid], function, 32 char);
  74.  
  75.     return 1;
  76. }
  77.  
  78. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  79. {
  80.     static
  81.         s_Public;
  82.  
  83.     s_Public = funcidx("OnDialogPerformed");
  84.  
  85.     // Sanitize inputs.
  86.     /*for (new i = 0, l = strlen(inputtext); i < l; i ++)
  87.     {
  88.         if (inputtext[i] == '%')
  89.         {
  90.             inputtext[i] = '#';
  91.         }
  92.     }*/
  93.    
  94.     if (dialogid == 32700)
  95.     {
  96.         new
  97.             string[40]; // 7 + 32 + \0
  98.  
  99.         strcat(string, "dialog_");
  100.         strcat(string, s_DialogName[playerid]);
  101.  
  102.         Dialog_Close(playerid);
  103.  
  104.         if ((s_Public == -1) || (CallLocalFunction("OnDialogPerformed", "dsdd", playerid, string[7], response, funcidx(string) != -1)))
  105.         {
  106.             CallLocalFunction(string, "ddds", playerid, response, listitem, (!inputtext[0]) ? ("\1") : (inputtext));
  107.         }
  108.     }
  109.     return Y_HOOKS_CONTINUE_RETURN_0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement