Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- /*
- SA:MP sound browser filterscript.
- Author: Bebras
- Date: 2014
- */
- // Gali būt paklaida ~1.
- #define NUMBER_OF_SOUNDS 7070
- #define SOUNDS_PER_PAGE 20
- #define MAX_SOUND_NAME 40
- #define MAX_SOUND_ID_LENGTH 5
- #define SOUND_DIALOG_ID 486
- #define AUDIO_FILE "AudioEvents.txt"
- new CurrentSoundPage[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- print("----------------------------------");
- print("SoundBrowser by Bebras is now loaded");
- if(!fexist(AUDIO_FILE)) print("[ERROR] audiofile " #AUDIO_FILE "does not exist");
- print("----------------------------------");
- }
- public OnPlayerConnect(playerid)
- {
- CurrentSoundPage[playerid] = 1;
- return 1;
- }
- CMD:sounds(playerid)
- {
- if(!fexist(AUDIO_FILE)) return SendClientMessage(playerid, 0xFF0000FF, #AUDIO_FILE " is missing from scriptfiles directory!");
- new File:handle = fopen(AUDIO_FILE, io_read);
- if(!handle) return SendClientMessage(playerid, 0xFF0000FF, #AUDIO_FILE "could not be read.");
- new buffer[256],soundCount;
- new dialogString[(MAX_SOUND_NAME + MAX_SOUND_ID_LENGTH + 5) * SOUNDS_PER_PAGE + 43]; // ~ 4kB
- while(fread(handle,buffer))
- {
- StripNewLine(buffer);
- if(isnull(buffer)) continue;
- soundCount++;
- if((CurrentSoundPage[playerid] - 1) * SOUNDS_PER_PAGE < soundCount)
- {
- format(dialogString,sizeof(dialogString),"%s%s\n",dialogString,buffer);
- if(soundCount == CurrentSoundPage[playerid] * SOUNDS_PER_PAGE)
- break;
- }
- else
- continue;
- }
- format(buffer,sizeof(buffer),"Sound page %d",CurrentSoundPage[playerid]);
- strcat(dialogString,"{FF0000}Next page --->");
- strcat(dialogString,"\nPrevious page <---");
- ShowPlayerDialog(playerid, SOUND_DIALOG_ID, DIALOG_STYLE_LIST, buffer, dialogString, "Play", "Exit");
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case SOUND_DIALOG_ID:
- {
- if(!response) return 1;
- switch(listitem)
- {
- case SOUNDS_PER_PAGE:
- {
- CurrentSoundPage[playerid]++;
- if(CurrentSoundPage[playerid] * SOUNDS_PER_PAGE >= NUMBER_OF_SOUNDS)
- CurrentSoundPage[playerid]--;
- }
- case SOUNDS_PER_PAGE+1:
- {
- CurrentSoundPage[playerid]--;
- if(CurrentSoundPage[playerid] == 0)
- CurrentSoundPage[playerid] = 1;
- }
- default:
- {
- new id,tmp[MAX_SOUND_ID_LENGTH+1],name[MAX_SOUND_NAME+1];
- strmid(name,inputtext,0,strfind(inputtext," "));
- strmid(tmp,inputtext,strfind(inputtext," ")+1,strlen(inputtext));
- id = strval(tmp);
- PlayerPlaySound(playerid, id,0, 0, 0);
- new string[100];
- format(string,sizeof(string),"Playing sound %s (ID:%d)",name,id);
- SendClientMessage(playerid, random(16777215), string);
- }
- }
- cmd_sounds(playerid);
- return 1;
- }
- }
- return 0;
- }
- stock StripNewLine(string[])
- {
- new len = strlen(string);
- if (string[0]==0) return ;
- if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
- string[len - 1] = 0;
- if (string[0]==0) return ;
- if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement