Advertisement
Bebras

[Filterscript] Sound Browser

Jun 24th, 2014
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.20 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3.  
  4.  
  5. /*
  6.            
  7.             SA:MP sound browser filterscript.
  8.             Author: Bebras
  9.             Date: 2014
  10.  
  11.  
  12.  
  13.  
  14. */
  15.  
  16.  
  17. // Gali būt paklaida ~1.
  18. #define NUMBER_OF_SOUNDS                7070
  19. #define SOUNDS_PER_PAGE                 20
  20. #define MAX_SOUND_NAME                  40
  21. #define MAX_SOUND_ID_LENGTH             5
  22. #define SOUND_DIALOG_ID                 486
  23. #define AUDIO_FILE                      "AudioEvents.txt"
  24.  
  25.  
  26.  
  27. new CurrentSoundPage[MAX_PLAYERS];
  28.  
  29.  
  30.  
  31. public OnFilterScriptInit()
  32. {
  33.     print("----------------------------------");
  34.     print("SoundBrowser by Bebras is now loaded");
  35.     if(!fexist(AUDIO_FILE)) print("[ERROR] audiofile " #AUDIO_FILE "does not exist");
  36.     print("----------------------------------");
  37.  
  38. }
  39.  
  40.  
  41.  
  42. public OnPlayerConnect(playerid)
  43. {
  44.     CurrentSoundPage[playerid] = 1;
  45.     return 1;
  46. }
  47.  
  48.  
  49.  
  50. CMD:sounds(playerid)
  51. {
  52.     if(!fexist(AUDIO_FILE)) return SendClientMessage(playerid, 0xFF0000FF, #AUDIO_FILE " is missing from scriptfiles directory!");
  53.  
  54.     new File:handle = fopen(AUDIO_FILE, io_read);
  55.     if(!handle) return SendClientMessage(playerid, 0xFF0000FF, #AUDIO_FILE "could not be read.");
  56.  
  57.     new buffer[256],soundCount;
  58.     new dialogString[(MAX_SOUND_NAME + MAX_SOUND_ID_LENGTH + 5) * SOUNDS_PER_PAGE + 43]; // ~ 4kB
  59.     while(fread(handle,buffer))
  60.     {
  61.         StripNewLine(buffer);
  62.         if(isnull(buffer)) continue;
  63.         soundCount++;
  64.         if((CurrentSoundPage[playerid] - 1) * SOUNDS_PER_PAGE < soundCount)
  65.         {
  66.             format(dialogString,sizeof(dialogString),"%s%s\n",dialogString,buffer);    
  67.  
  68.             if(soundCount == CurrentSoundPage[playerid] * SOUNDS_PER_PAGE)
  69.                 break;
  70.         }
  71.         else
  72.             continue;
  73.  
  74.     }
  75.     format(buffer,sizeof(buffer),"Sound page %d",CurrentSoundPage[playerid]);
  76.     strcat(dialogString,"{FF0000}Next page --->");
  77.     strcat(dialogString,"\nPrevious page <---");
  78.     ShowPlayerDialog(playerid, SOUND_DIALOG_ID, DIALOG_STYLE_LIST, buffer, dialogString, "Play", "Exit");
  79.     return 1;
  80. }
  81.  
  82. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  83. {
  84.     switch(dialogid)
  85.     {
  86.         case SOUND_DIALOG_ID:
  87.         {
  88.             if(!response) return 1;
  89.             switch(listitem)
  90.             {
  91.                 case SOUNDS_PER_PAGE:
  92.                 {
  93.                     CurrentSoundPage[playerid]++;
  94.                     if(CurrentSoundPage[playerid] * SOUNDS_PER_PAGE >= NUMBER_OF_SOUNDS)
  95.                         CurrentSoundPage[playerid]--;
  96.                 }
  97.                 case SOUNDS_PER_PAGE+1:
  98.                 {
  99.                     CurrentSoundPage[playerid]--;
  100.                     if(CurrentSoundPage[playerid] == 0)
  101.                         CurrentSoundPage[playerid] = 1;
  102.                 }
  103.                 default:
  104.                 {
  105.                     new id,tmp[MAX_SOUND_ID_LENGTH+1],name[MAX_SOUND_NAME+1];
  106.                     strmid(name,inputtext,0,strfind(inputtext," "));
  107.                     strmid(tmp,inputtext,strfind(inputtext," ")+1,strlen(inputtext));
  108.                     id = strval(tmp);
  109.  
  110.                     PlayerPlaySound(playerid, id,0, 0, 0);
  111.  
  112.                     new string[100];
  113.                     format(string,sizeof(string),"Playing sound %s (ID:%d)",name,id);
  114.                     SendClientMessage(playerid, random(16777215), string);
  115.  
  116.                 }
  117.             }
  118.             cmd_sounds(playerid);
  119.             return 1;
  120.         }
  121.     }
  122.     return 0;
  123. }
  124.  
  125.  
  126. stock StripNewLine(string[])
  127. {
  128.     new len = strlen(string);
  129.     if (string[0]==0) return ;
  130.     if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
  131.         string[len - 1] = 0;
  132.         if (string[0]==0) return ;
  133.         if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement