1
0

easyDialog.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. easyDialog.inc - Dialogs made easier!
  3. With this useful include, scripters can easily create
  4. dialogs and show them to players.
  5. This include will prevent dialog spoofing, ID collision
  6. and a lot more.
  7. Created by Emmet on Friday, January 24, 2014.
  8. */
  9. #define Dialog:%0(%1) \
  10. forward dialog_%0(%1); public dialog_%0(%1)
  11. #define Dialog_Show(%0,%1,%2) \
  12. Dialog_Open(%0, #%1, %2)
  13. #if !defined isnull
  14. #define isnull(%1) \
  15. ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  16. #endif
  17. static stock
  18. g_DG_DialogFunction[MAX_PLAYERS][32 char]
  19. ;
  20. forward OnDialogPerformed(playerid, dialog[], response, success);
  21. forward @dialog_format(); @dialog_format() {
  22. format("", 1, "");
  23. }
  24. stock Dialog_Opened(playerid)
  25. return (GetPVarInt(playerid, "DIALOG_OPENED"));
  26. stock Dialog_Close(playerid)
  27. {
  28. DeletePVar(playerid, "DIALOG_OPENED");
  29. g_DG_DialogFunction[playerid]{0} = 0;
  30. ShowPlayerDialog(playerid, -1, DIALOG_STYLE_MSGBOX, " ", " ", " ", "");
  31. return 0;
  32. }
  33. stock Dialog_Open(playerid, function[], style, caption[], info[], button1[], button2[], {Float,_}:...)
  34. {
  35. static
  36. string[1024],
  37. start,
  38. end;
  39. if (numargs() > 7)
  40. {
  41. #emit ADDR.pri button2
  42. #emit STOR.pri start
  43. for (end = start + (numargs() << 2) - 28; end > start; end -= 4)
  44. {
  45. #emit LREF.pri end
  46. #emit PUSH.pri
  47. }
  48. #emit PUSH.S info
  49. #emit PUSH.C 1024
  50. #emit PUSH.C string
  51. #emit LOAD.S.pri 8
  52. #emit CONST.alt 16
  53. #emit SUB
  54. #emit PUSH.pri
  55. #emit SYSREQ.C format
  56. #emit LCTRL 5
  57. #emit SCTRL 4
  58. ShowPlayerDialog(playerid, 32700, style, caption, string, button1, button2);
  59. }
  60. else
  61. {
  62. ShowPlayerDialog(playerid, 32700, style, caption, info, button1, button2);
  63. }
  64. SetPVarInt(playerid, "DIALOG_OPENED", 1);
  65. strpack(g_DG_DialogFunction[playerid], function);
  66. return 1;
  67. }
  68. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  69. {
  70. new
  71. input[128];
  72. strcat(input, inputtext);
  73. for (new i = 0, len = strlen(input); i != len; i ++)
  74. {
  75. if (input[i] != '%')
  76. continue;
  77. input[i] = '#';
  78. }
  79. if ((dialogid == 32700 && g_DG_DialogFunction[playerid]{0}))
  80. {
  81. new
  82. func[40];
  83. strcat(func, "dialog_");
  84. strcat(func, g_DG_DialogFunction[playerid]);
  85. Dialog_Close(playerid);
  86. if (funcidx("OnDialogPerformed") == -1 || CallLocalFunction("OnDialogPerformed", "dsdd", playerid, func[7], response, funcidx(func) != -1) != 0) {
  87. CallLocalFunction(func, "ddds", playerid, response, listitem, (!input[0]) ? ("\1") : (input));
  88. }
  89. }
  90. #if defined DG_OnDialogResponse
  91. DG_OnDialogResponse(playerid, dialogid, response, listitem, input);
  92. #endif
  93. return 0;
  94. }
  95. #if defined _ALS_OnDialogResponse
  96. #undef OnDialogResponse
  97. #else
  98. #define _ALS_OnDialogResponse
  99. #endif
  100. #define OnDialogResponse DG_OnDialogResponse
  101. #if defined DG_OnDialogResponse
  102. forward DG_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  103. #endif