JeffryUGP

Interactive Dialogs - Example Code

Jan 20th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.97 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. new g_PlayerDialog[MAX_PLAYERS] = {-1,...};
  4.  
  5. #define MAX_OWN_DIALOGS 100
  6. new g_dCaption[MAX_OWN_DIALOGS][36];
  7. new g_dInfo[MAX_OWN_DIALOGS][256];
  8. new g_dButton1[MAX_OWN_DIALOGS][8];
  9. new g_dButton2[MAX_OWN_DIALOGS][8];
  10.  
  11. public OnPlayerDisconnect(playerid, reason)
  12. {
  13.     g_PlayerDialog[playerid] = -1;
  14.     return 1;
  15. }
  16.  
  17.  
  18. public OnPlayerCommandText(playerid, cmdtext[])
  19. {
  20.     if(!strcmp("/ListeZeigen", cmdtext, true))
  21.     {
  22.         if(!strlen(GetDialogInfo(0))) return SendClientMessage(playerid, 0xFF0000FF, "Es ist niemand in der Liste.");
  23.         ShowPlayerDialog_Ex(playerid, 0, DIALOG_STYLE_LIST, "Beispiel", GetDialogInfo(0), "Ausw.", "Cancel");
  24.         print(GetDialogInfo(0));
  25.         return 1;
  26.     }
  27.     if(!strcmp("/InListeEintragen", cmdtext, true))
  28.     {
  29.         AddItemToDialog(0, SpielerName(playerid));
  30.         return 1;
  31.     }
  32.     if(!strcmp("/AusListeAustragen", cmdtext, true))
  33.     {
  34.         RemoveItemFromDialog(0, SpielerName(playerid));
  35.         return 1;
  36.     }
  37.     return 0;
  38. }
  39.  
  40. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  41. {
  42.     g_PlayerDialog[playerid] = -1;
  43.    
  44.     if(dialogid == 0 && response == 1)
  45.     {
  46.         new item[64], l_found_id = -1;
  47.         item = GetItemFromDialog(dialogid, listitem);
  48.         print(item);
  49.         for(new i=0; i<MAX_PLAYERS; i++)
  50.         {
  51.             if(IsPlayerConnected(i) && !strcmp(SpielerName(i), item))
  52.             {
  53.                 l_found_id = i;
  54.                 break;
  55.             }
  56.         }
  57.         new l_str[144];
  58.         format(l_str, sizeof(l_str), "Info: Ich habe Spieler %s mit der ID %d angeklickt.", SpielerName(l_found_id), l_found_id);
  59.         SendClientMessage(playerid, -1, l_str);
  60.     }
  61.     return 1;
  62. }
  63.  
  64.  
  65. stock ShowPlayerDialog_Ex(playerid, dialogid, style, caption[], info[], button1[], button2[])
  66. {
  67.     ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
  68.     g_PlayerDialog[playerid] = dialogid;
  69.     if(dialogid > -1 && dialogid < MAX_OWN_DIALOGS)
  70.     {
  71.         format(g_dCaption[dialogid], sizeof(g_dCaption[]), caption);
  72.         format(g_dInfo[dialogid], sizeof(g_dInfo[]), info);
  73.         format(g_dButton1[dialogid], sizeof(g_dButton1[]), button1);
  74.         format(g_dButton2[dialogid], sizeof(g_dButton2[]), button2);
  75.     }
  76.     return 1;
  77. }
  78.  
  79. stock GetPlayerDialog(playerid)
  80. {
  81.     return g_PlayerDialog[playerid];
  82. }
  83.  
  84. stock GetDialogCaption(dialogid)
  85. {
  86.     return g_dCaption[dialogid];
  87. }
  88.  
  89. stock GetDialogInfo(dialogid)
  90. {
  91.     return g_dInfo[dialogid];
  92. }
  93.  
  94. stock GetDialogButton1(dialogid)
  95. {
  96.     return g_dButton1[dialogid];
  97. }
  98.  
  99. stock GetDialogButton2(dialogid)
  100. {
  101.     return g_dButton2[dialogid];
  102. }
  103.  
  104.  
  105. stock AddItemToDialog(dialogid, item[])
  106. {
  107.     new l_pos = strfind(g_dInfo[dialogid], item);
  108.     if(l_pos != -1) strdel(g_dInfo[dialogid], l_pos, l_pos+strlen(item)+2);
  109.     format(g_dInfo[dialogid], sizeof(g_dInfo[]), "%s%s\n", g_dInfo[dialogid], item);
  110.     return UpdateDialogForAll(dialogid);
  111. }
  112.  
  113. stock RemoveItemFromDialog(dialogid, item[])
  114. {
  115.     new l_pos = strfind(g_dInfo[dialogid], item);
  116.     if(l_pos == -1) return 0;
  117.     strdel(g_dInfo[dialogid], l_pos, l_pos+strlen(item)+1);
  118.     return UpdateDialogForAll(dialogid);
  119. }
  120.  
  121. stock GetItemFromDialog(dialogid, listitem)
  122. {
  123.     new l_str[64], c_count, l_lastpos = -1, tmp[sizeof(g_dInfo[])];
  124.     tmp = "*";
  125.     for(new i=0; i<strlen(g_dInfo[dialogid]); i++)
  126.     {
  127.         if(g_dInfo[dialogid][i] == '\n')
  128.         {
  129.             if(c_count == listitem)
  130.             {
  131.                 tmp = g_dInfo[dialogid];
  132.                 strdel(tmp, i, strlen(g_dInfo[dialogid]));
  133.                 strdel(tmp, 0, l_lastpos+1);
  134.                 break;
  135.             }
  136.             c_count++;
  137.             l_lastpos = i;
  138.         }
  139.     }
  140.     format(l_str, sizeof(l_str), tmp);
  141.     return l_str;
  142. }
  143.  
  144. stock UpdateDialogForAll(dialogid)
  145. {
  146.     for(new i=0; i<MAX_PLAYERS; i++)
  147.     {
  148.         if(g_PlayerDialog[i] == dialogid)
  149.         {
  150.             ShowPlayerDialog(i, g_PlayerDialog[i], DIALOG_STYLE_LIST, g_dCaption[g_PlayerDialog[i]], g_dInfo[g_PlayerDialog[i]], g_dButton1[g_PlayerDialog[i]], g_dButton2[g_PlayerDialog[i]]);
  151.         }
  152.     }
  153.     return 1;
  154. }
  155.  
  156. stock SpielerName(playerid)
  157. {
  158.     new l_name[MAX_PLAYER_NAME];
  159.     GetPlayerName(playerid, l_name, sizeof(l_name));
  160.     return l_name;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment