Advertisement
Lemonadio

Dynamic Dialogs Simple

Apr 16th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.31 KB | None | 0 0
  1. /*  Dynamic Dialogs BETA (Simple version)
  2.  *
  3.  *  (c) Copyright 2013, GameMan aka Lemonadio aka MeowCola
  4.  *
  5.  */
  6.  
  7. /* NATIVES for "Pawno"
  8. native ClearDialogListItems(playerid);
  9. native AddDialogListItem(playerid, itemid, itemtext[]);
  10. native ShowPlayerDialogList(playerid, dialogid, caption[], button1[], button2[]);
  11. */
  12.  
  13. #if !defined _samp_included
  14.     #error "Please include 'a_samp.inc' before 'dyndial.inc'"
  15. #endif
  16.  
  17. #if defined _dynamic_dialogs_included
  18.     #endinput
  19. #endif
  20. #define _dynamic_dialogs_included
  21.  
  22. #define MAX_DIALOG_ITEMS                    (16)
  23. #define MAX_ITEM_LENGTH                 (64)
  24. #define MAX_DIALOG_LENGTH               (1024)
  25.  
  26. forward OnDialogListResponse(playerid, dialogid, response, itemid, itemtext[]);
  27.  
  28. new DialogItemsID[MAX_PLAYERS][MAX_DIALOG_ITEMS];
  29. new DialogItemsText[MAX_PLAYERS][MAX_DIALOG_LENGTH];
  30.  
  31. #if defined FILTERSCRIPT
  32. public OnFilterScriptInit() {
  33.     foreach(new i : Player) {
  34.         ClearDialogListItems(i);
  35.     }
  36.     if(funcidx("dd_OnFilterScriptInit") != -1) return CallLocalFunction("dd_OnFilterScriptInit", "");
  37.     return 1;
  38. }
  39. #if defined _ALS_OnFilterScriptInit
  40.     #undef OnFilterScriptInit
  41. #else
  42.     #define _ALS_OnFilterScriptInit
  43. #endif
  44. #define OnFilterScriptInit dd_OnFilterScriptInit
  45. forward dd_OnFilterScriptInit();
  46.  
  47. public OnFilterScriptExit() {
  48.     foreach(new i : Player) {
  49.         ClearDialogListItems(i);
  50.     }
  51.     if(funcidx("dd_OnFilterScriptExit") != -1) return CallLocalFunction("dd_OnFilterScriptExit", "");
  52.     return 1;
  53. }
  54. #if defined _ALS_OnFilterScriptExit
  55.     #undef OnFilterScriptExit
  56. #else
  57.     #define _ALS_OnFilterScriptExit
  58. #endif
  59. #define OnFilterScriptExit dd_OnFilterScriptExit
  60. forward dd_OnFilterScriptExit();
  61.  
  62. #else
  63. public OnGameModeInit() {
  64.     foreach(new i : Player) {
  65.         ClearDialogListItems(i);
  66.     }
  67.     if(funcidx("dd_OnGameModeInit") != -1) return CallLocalFunction("dd_OnGameModeInit", "");
  68.     return 1;
  69. }
  70. #if defined _ALS_OnGameModeInit
  71.     #undef OnGameModeInit
  72. #else
  73.     #define _ALS_OnGameModeInit
  74. #endif
  75. #define OnGameModeInit dd_OnGameModeInit
  76. forward dd_OnGameModeInit();
  77.  
  78. public OnGameModeExit() {
  79.     foreach(new i : Player) {
  80.         ClearDialogListItems(i);
  81.     }
  82.     if(funcidx("dd_OnGameModeExit") != -1) return CallLocalFunction("dd_OnGameModeExit", "");
  83.     return 1;
  84. }
  85. #if defined _ALS_OnGameModeExit
  86.     #undef OnGameModeExit
  87. #else
  88.     #define _ALS_OnGameModeExit
  89. #endif
  90. #define OnGameModeExit dd_OnGameModeExit
  91. forward dd_OnGameModeExit();
  92.  
  93. #endif
  94.  
  95. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  96.     listitem = DialogItemsID[playerid][listitem];
  97.     ClearDialogListItems(playerid);
  98.     if(funcidx("dd_OnDialogResponse") != -1) return CallLocalFunction("dd_OnDialogResponse", "dddds", playerid, dialogid, response, listitem, inputtext);
  99.     return 0;
  100. }
  101.  
  102. #if defined _ALS_OnDialogResponse
  103.     #undef OnDialogResponse
  104. #else
  105.     #define _ALS_OnDialogResponse
  106. #endif
  107. #define OnDialogResponse dd_OnDialogResponse
  108. forward dd_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  109.  
  110. public OnPlayerConnect(playerid)
  111. {
  112.     ClearDialogListItems(playerid);
  113.     if(funcidx("dd_OnPlayerConnect") != -1) return CallLocalFunction("dd_OnPlayerConnect", "d",playerid);
  114.     return 1;
  115. }
  116. #if defined _ALS_OnPlayerConnect
  117.     #undef OnPlayerConnect
  118. #else
  119.     #define _ALS_OnPlayerConnect
  120. #endif
  121. #define OnPlayerConnect dd_OnPlayerConnect
  122. forward dd_OnPlayerConnect(playerid);
  123.  
  124. stock ClearDialogListItems(playerid) {
  125.     if(!IsPlayerConnected(playerid)) return 0;
  126.     for(new di; di < MAX_DIALOG_ITEMS; di++) {
  127.         DialogItemsID[playerid][di] = -1;
  128.     }
  129.     strdel(DialogItemsText[playerid], 0, sizeof(DialogItemsText[]));
  130.     return 1;
  131. }
  132.  
  133. stock AddDialogListItem(playerid, itemid, itemtext[]) {
  134.     if(!IsPlayerConnected(playerid)) return 0;
  135.     if(itemtext[0] == EOS || strlen(itemtext) > MAX_ITEM_LENGTH) return 0;
  136.     for(new di; di < MAX_DIALOG_ITEMS; di++) {
  137.         if(DialogItemsID[playerid][di] != -1) continue;
  138.         DialogItemsID[playerid][di] = itemid;
  139.         new tmp[MAX_ITEM_LENGTH+2];
  140.         format(tmp, sizeof(tmp), "%s\n", itemtext);
  141.         strcat(DialogItemsText[playerid], tmp, sizeof(DialogItemsText[]));
  142.         return 1;
  143.     }
  144.     return 0;
  145. }
  146.  
  147. stock ShowPlayerDialogList(playerid, dialogid, caption[], button1[], button2[]) {
  148.     if(!IsPlayerConnected(playerid)) return 0;
  149.     ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, caption, DialogItemsText[playerid], button1, button2);
  150.     return 1;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement