Advertisement
Vince0789

SA-MP Dialog Extension

Sep 13th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.43 KB | None | 0 0
  1. #if defined EXTENSION_DIALOG_INCLUDED
  2.   #endinput
  3. #endif
  4. #define EXTENSION_DIALOG_INCLUDED
  5.  
  6. #define DIALOG: Dialog
  7.  
  8. // -----------------------------------------------------------------------------
  9. // Global to store current open dialog id
  10. // -----------------------------------------------------------------------------
  11.  
  12. static
  13.     gCurrentlyOpenDialog[MAX_PLAYERS] = {cellmin, ...};
  14.  
  15. // -----------------------------------------------------------------------------
  16. // OnPlayerConnect
  17. // -----------------------------------------------------------------------------
  18.  
  19. public OnPlayerConnect(playerid)
  20. {
  21.     gCurrentlyOpenDialog[playerid] = cellmin;
  22.     #if defined ex_OnPlayerConnect
  23.         ex_OnPlayerConnect(playerid);
  24.     #endif
  25.     return 1;
  26. }
  27. #if defined _ALS_OnPlayerConnect
  28.     #undef OnPlayerConnect
  29. #else
  30.     #define _ALS_OnPlayerConnect
  31. #endif
  32. #define OnPlayerConnect ex_OnPlayerConnect
  33. #if defined ex_OnPlayerConnect
  34.     forward ex_OnPlayerConnect(playerid);
  35. #endif
  36.  
  37. // -----------------------------------------------------------------------------
  38. // OnPlayerDisconnect
  39. // -----------------------------------------------------------------------------
  40.  
  41. public OnPlayerDisconnect(playerid, reason)
  42. {
  43.     gCurrentlyOpenDialog[playerid] = cellmin;
  44.     #if defined ex_OnPlayerDisconnect
  45.         ex_OnPlayerDisconnect(playerid, reason);
  46.     #endif
  47.     return 1;
  48. }
  49. #if defined _ALS_OnPlayerDisconnect
  50.     #undef OnPlayerDisconnect
  51. #else
  52.     #define _ALS_OnPlayerDisconnect
  53. #endif
  54. #define OnPlayerDisconnect ex_OnPlayerDisconnect
  55. #if defined ex_OnPlayerDisconnect
  56.     forward ex_OnPlayerDisconnect(playerid, reason);
  57. #endif
  58.  
  59. // -----------------------------------------------------------------------------
  60. // OnDialogResponse
  61. // -----------------------------------------------------------------------------
  62.  
  63. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  64. {
  65.     // spoof check
  66.     if(dialogid != gCurrentlyOpenDialog[playerid] && !IsPlayerAdmin(playerid))
  67.         return Kick(playerid);
  68.  
  69.     gCurrentlyOpenDialog[playerid] = cellmin;
  70.  
  71.     #if defined ex_OnDialogResponse
  72.         ex_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
  73.     #endif
  74.     return 0;
  75. }
  76. #if defined _ALS_OnDialogResponse
  77.     #undef OnDialogResponse
  78. #else
  79.     #define _ALS_OnDialogResponse
  80. #endif
  81. #define OnDialogResponse ex_OnDialogResponse
  82. #if defined ex_OnDialogResponse
  83.     forward ex_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  84. #endif
  85.  
  86. // -----------------------------------------------------------------------------
  87. // ShowPlayerDialog Hook
  88. // -----------------------------------------------------------------------------
  89.  
  90. stock ex_ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[])
  91. {
  92.     gCurrentlyOpenDialog[playerid] = dialogid;
  93.     ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
  94.     return 1;
  95. }
  96. #if defined _ALS_ShowPlayerDialog
  97.     #undef ShowPlayerDialog
  98. #else
  99.     #define _ALS_ShowPlayerDialog
  100. #endif
  101. #define ShowPlayerDialog ex_ShowPlayerDialog
  102.  
  103. // -----------------------------------------------------------------------------
  104. // API Functions
  105. // -----------------------------------------------------------------------------
  106.  
  107. stock IsPlayerDialogOpen(playerid, dialogid)
  108.     return gCurrentlyOpenDialog[playerid] == dialogid;
  109.    
  110. stock bool:IsAnyPlayerDialogOpen(playerid)
  111.     return gCurrentlyOpenDialog[playerid] >= 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement