Advertisement
Gamer_Z

Untitled

Nov 1st, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. /*
  2. * NAMED DIALOGS System
  3. *
  4. * Version 1.1
  5. *
  6. * By Gamer_Z
  7. *
  8. * for SSI (SA-MP Server Includes)
  9. *
  10. * Released under MPL v1.1
  11. *
  12. * A copy of the license can be obtained at
  13. * http://www.mozilla.org/MPL/MPL-1.1.txt
  14. *
  15. */
  16. #if defined _NAMED_DIALOGS_INCLUDED_
  17. #endinput
  18. #else
  19. #define _NAMED_DIALOGS_INCLUDED_
  20. #endif
  21.  
  22. //#define NDLG_NO_DISABLE_CALLBACK// When defined, Use still the old callback
  23. //#define NDLG_USE_YSI_HOOK//Use YSI hook instead of the default one
  24.  
  25. #if !defined _cstl_inc
  26. #error You need to have the CSTL Data container plugin include\
  27. to use this include (NameDialogs)\
  28. Please ensure you have included this include BELOW\
  29. your CSTL include
  30. #endif
  31.  
  32. #if !defined isnull
  33. #define isnull(%1) \
  34. ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
  35. #endif
  36.  
  37. new __PRIV__REGISTERED___DLGS_FS__ = 0;
  38. new __PRIV__REGISTEREDDialogName__[32];
  39. new __PRIV__REDIALOGID___DLGS_FS__ = -1;
  40.  
  41. //native fnDialog(DialogName)
  42. #define fnDialog(%1) \
  43. forward ND%1(playerid,response,listitem,inputtext[]);\
  44. public ND%1(playerid,response,listitem,inputtext[])
  45.  
  46. //native nDialog(%1,%2,%3,%4)
  47. #define nDialog:%0(%1,%2,%3,%4) \
  48. forward ND%0(%1,%2,%3,%4);\
  49. public ND%0(%1,%2,%3,%4)
  50.  
  51. //native RegisterDialog(dialogname[])
  52. stock RegisterDialog(dialogname[])
  53. {
  54. ++__PRIV__REDIALOGID___DLGS_FS__;//Add one to variable
  55. if(__PRIV__REDIALOGID___DLGS_FS__ > 32767)return 0;//ERROR: MAX AMOUNT OF DIALOGS HAS BEEN REACHED, SA-MP USES ONLY 2 BYTES INSTEAD OF 4 BYTES - THAT's FRIKING!
  56. vector_push_back(__PRIV__REGISTERED___DLGS_FS__, __PRIV__REDIALOGID___DLGS_FS__);//Push the vector to add the variable
  57. return vector_set_arr(__PRIV__REGISTERED___DLGS_FS__, __PRIV__REDIALOGID___DLGS_FS__, dialogname);//Add the entry name to the container element
  58. }
  59.  
  60. //native ShowPlayerDialogName(playerid,dialogname[],style, caption[], info[], button1[], button2[])//MAX DIALOG NAME IS 30 CHARACTERS, MAX 32768 UNIQUE NAMES/DIALOGS
  61. stock ShowPlayerDialogName(playerid,dialogname[],style, caption[], info[], button1[], button2[])//MAX DIALOG NAME IS 30 CHARACTERS, MAX 32768 UNIQUE NAMES/DIALOGS
  62. {
  63. new dialogid = vector_find_arr(__PRIV__REGISTERED___DLGS_FS__,dialogname);//Try to find if the Dialog Name is registered
  64. if(dialogid == (-1))//if not then register it for us, instead of doing in OnGameModeInit manual registers this does the easy job
  65. {
  66. RegisterDialog(dialogname);//Register it
  67. dialogid = vector_find_arr(__PRIV__REGISTERED___DLGS_FS__,dialogname);//Find it again to get the dialog id, which is used to get the Dialog Name later
  68. }
  69. return ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);//Show the dialog for the player and await response
  70. }
  71.  
  72. #if defined NDLG_USE_YSI_HOOK
  73. #if defined NDLG_NO_DISABLE_CALLBACK
  74. Hook:NameDialog_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])//Our callback - response
  75. {
  76. vector_get_arr(__PRIV__REGISTERED___DLGS_FS__, dialogid, __PRIV__REGISTEREDDialogName__, 30);//get the name of dialogid
  77. format(__PRIV__REGISTEREDDialogName__,32,"ND%s",__PRIV__REGISTEREDDialogName__);//add ND to the beginning
  78. if(isnull(inputtext))format(inputtext,2,"\1");//avoid server crash on NULL string in CallLocalFunction
  79. if(funcidx(__PRIV__REGISTERED___DLGS_FS__) != -1)
  80. {
  81. CallLocalFunction(__PRIV__REGISTEREDDialogName__,"iiis",playerid,response,listitem,inputtext);//Execute our final callback response
  82. }
  83. }
  84. #else
  85. Hook:NameDialog_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])//Our callback - response
  86. {
  87. vector_get_arr(__PRIV__REGISTERED___DLGS_FS__, dialogid, __PRIV__REGISTEREDDialogName__, 30);//get the name of dialogid
  88. format(__PRIV__REGISTEREDDialogName__,32,"ND%s",__PRIV__REGISTEREDDialogName__);//add ND to the beginning
  89. if(isnull(inputtext))format(inputtext,2,"\1");//avoid server crash on NULL string in CallLocalFunction
  90. CallLocalFunction(__PRIV__REGISTEREDDialogName__,"iiis",playerid,response,listitem,inputtext);//Execute our final callback response
  91. return -1;
  92. }
  93. #endif
  94. #else
  95. #if defined NDLG_NO_DISABLE_CALLBACK
  96. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])//Our callback - response
  97. {
  98. vector_get_arr(__PRIV__REGISTERED___DLGS_FS__, dialogid, __PRIV__REGISTEREDDialogName__, 30);//get the name of dialogid
  99. format(__PRIV__REGISTEREDDialogName__,32,"ND%s",__PRIV__REGISTEREDDialogName__);//add ND to the beginning
  100. if(isnull(inputtext))format(inputtext,2,"\1");//avoid server crash on NULL string in CallLocalFunction
  101. if(funcidx(__PRIV__REGISTERED___DLGS_FS__) != -1)
  102. {
  103. return CallLocalFunction(__PRIV__REGISTEREDDialogName__,"iiis",playerid,response,listitem,inputtext);//Execute our final callback response
  104. }
  105. return CallLocalFunction("NDLG_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,inputtext);
  106. }
  107. #else
  108. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])//Our callback - response
  109. {
  110. vector_get_arr(__PRIV__REGISTERED___DLGS_FS__, dialogid, __PRIV__REGISTEREDDialogName__, 30);//get the name of dialogid
  111. format(__PRIV__REGISTEREDDialogName__,32,"ND%s",__PRIV__REGISTEREDDialogName__);//add ND to the beginning
  112. if(isnull(inputtext))format(inputtext,2,"\1");//avoid server crash on NULL string in CallLocalFunction
  113. return CallLocalFunction(__PRIV__REGISTEREDDialogName__,"iiis",playerid,response,listitem,inputtext);//Execute our final callback response
  114. }
  115. #endif
  116. #if defined _ALS_OnDialogResponse
  117. #undef OnDialogResponse
  118. #else
  119. #define _ALS_OnDialogResponse
  120. #endif
  121. #define OnDialogResponse NDLG_OnDialogResponse
  122. forward FDLG_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  123. #endif
  124.  
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement