Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include zcmd
- stock NRNULL[] = "\1\0";
- #define NPMAX_ITEMS 500
- #define NPMAX_CATEGORIES 30
- #define NPINVALID_ITEM_ID -1
- #define NPMAX_CATEGORY_LENGTH 75
- #define NPMAX_ITEM_LENGTH 900
- #define NPMAX_STREAM_URL_LENGTH 900
- #define NPCATEGORIES_DIALOG_ID 1553
- #define NPLAYER_DIALOG_ID 1552
- enum nPlayerItem
- {
- npCategoryID,
- npTitle[NPMAX_ITEM_LENGTH],
- npStreamURL[NPMAX_STREAM_URL_LENGTH]
- }
- new PlayerItem[NPMAX_ITEMS][nPlayerItem], nCategories[NPMAX_ITEMS][NPMAX_CATEGORY_LENGTH], nrCATEGORY_COUNT = 0, npITEM_COUNT = 0, npDIALOG_STRING[1028];
- /*
- native AddCategoryEx(category,name[]);
- native DeleteCategoryEx(categoryid);
- native AddMusic(categoryid, musicname[],musicurl[]);
- native AddMusicToCateg(category,musicname[],musicurl[]);
- native ShowDialog(playerid);
- */
- stock AddCategory(name[NPMAX_CATEGORY_LENGTH])
- {
- new CATEGORY_ID = NPINVALID_ITEM_ID;
- if(strlen(name) >= 1 && strlen(name) <= NPMAX_CATEGORY_LENGTH)
- {
- if(nrCATEGORY_COUNT < NPMAX_CATEGORIES)
- {
- for(new i=0;i<NPMAX_CATEGORIES;i++)
- {
- if(!strlen(nCategories[i]))
- {
- format(nCategories[i], NPMAX_CATEGORY_LENGTH, name);
- CATEGORY_ID = i;
- nrCATEGORY_COUNT++;
- return CATEGORY_ID;
- }
- }
- }
- }
- return CATEGORY_ID;
- }
- stock AddCategoryEx(category,name[NPMAX_CATEGORY_LENGTH])
- {
- category = AddCategory(name);
- return category;
- }
- stock DeleteCategoryEx(categoryid)
- {
- format(nCategories[categoryid], NPMAX_CATEGORY_LENGTH, "");
- for(new i=0;i<npITEM_COUNT;i++)
- {
- if(PlayerItem[i][npCategoryID] == categoryid && strlen(PlayerItem[i][npTitle]) >= 1)
- {
- format(PlayerItem[i][npTitle], NPMAX_ITEM_LENGTH, "");
- npITEM_COUNT--;
- }
- }
- nrCATEGORY_COUNT--;
- return true;
- }
- stock AddMusic(categoryid, name[NPMAX_ITEM_LENGTH], streamurl[NPMAX_STREAM_URL_LENGTH])
- {
- new ITEM_ID = -1;
- if(strlen(name) >= 1 && strlen(name) <= NPMAX_ITEM_LENGTH)
- {
- if(npITEM_COUNT < NPMAX_ITEMS)
- {
- for(new i=0;i<NPMAX_ITEMS;i++)
- {
- if(!strlen(PlayerItem[i][npTitle]))
- {
- ITEM_ID = i;
- PlayerItem[i][npCategoryID] = categoryid;
- format(PlayerItem[i][npTitle], NPMAX_ITEM_LENGTH, name);
- format(PlayerItem[i][npStreamURL], NPMAX_STREAM_URL_LENGTH, streamurl);
- npITEM_COUNT++;
- return ITEM_ID;
- }
- }
- }
- }
- return ITEM_ID;
- }
- stock ShowDialog(playerid)
- {
- format(npDIALOG_STRING, sizeof(npDIALOG_STRING), "");
- for(new i=0;i<nrCATEGORY_COUNT;i++)
- {
- if(!i)
- {
- if(strlen(nCategories[i]) >= 1) format(npDIALOG_STRING, sizeof(npDIALOG_STRING), nCategories[i]);
- }
- else
- {
- if(strlen(nCategories[i]) >= 1) format(npDIALOG_STRING, sizeof(npDIALOG_STRING), "%s\n%s", npDIALOG_STRING, nCategories[i]);
- }
- }
- if(strlen(npDIALOG_STRING) >= 1) ShowPlayerDialog(playerid, NPCATEGORIES_DIALOG_ID, DIALOG_STYLE_LIST, "Select Category", npDIALOG_STRING, "Select", "Cancel");
- else ShowPlayerDialog(playerid, 0, DIALOG_STYLE_LIST, "Select Category", "No Category Found","Select", "Cancel");
- return true;
- }
- stock StopMusic(playerid)
- {
- StopAudioStreamForPlayer(playerid);
- return true;
- }
- stock PlayMusic(playerid, itemid)
- {
- StopMusic(playerid);
- PlayAudioStreamForPlayer(playerid, PlayerItem[itemid][npStreamURL]);
- return true;
- }
- stock ItemIDFromDialogOrder(playerid, listitem)
- {
- new categoryid = GetPVarInt(playerid, "Category"), current_array_id, bool:breakloop = false, id = -1;
- for(new i=0;i<npITEM_COUNT;i++)
- {
- if(PlayerItem[i][npCategoryID] == categoryid && strlen(PlayerItem[i][npTitle]) >= 1)
- {
- if(!breakloop)
- {
- if(current_array_id == listitem)
- {
- id = i;
- breakloop = true;
- }
- current_array_id++;
- }
- }
- }
- return id;
- }
- stock CategoryIDFromDialogOrder(listitem)
- {
- new current_array_id, bool:breakloop = false, id = -1;
- for(new i=0;i<nrCATEGORY_COUNT;i++)
- {
- if(strlen(nCategories[i]) >= 1)
- {
- if(!breakloop)
- {
- if(current_array_id == listitem)
- {
- id = i;
- breakloop = true;
- }
- current_array_id++;
- }
- }
- }
- return id;
- }
- stock ItemCountFromCategory(categoryid)
- {
- new count = 0;
- for(new i=0;i<npITEM_COUNT;i++)
- {
- if(PlayerItem[i][npCategoryID] == categoryid && strlen(PlayerItem[i][npTitle]) >= 1)
- {
- count++;
- }
- }
- return count;
- }
- stock CategoryBrowse(playerid, listitem)
- {
- format(npDIALOG_STRING, sizeof(npDIALOG_STRING), "");
- new categoryid = CategoryIDFromDialogOrder(listitem);
- SetPVarInt(playerid, "Category", categoryid);
- if(ItemCountFromCategory(categoryid) >= 1)
- {
- for(new i=0;i<npITEM_COUNT;i++)
- {
- if(PlayerItem[i][npCategoryID] == categoryid)
- {
- if(!i)
- {
- if(strlen(PlayerItem[i][npTitle]) >= 1) format(npDIALOG_STRING, sizeof(npDIALOG_STRING), PlayerItem[i][npTitle]);
- }
- else
- {
- if(strlen(PlayerItem[i][npTitle]) >= 1) format(npDIALOG_STRING, sizeof(npDIALOG_STRING), "%s\n%s", npDIALOG_STRING, PlayerItem[i][npTitle]);
- }
- }
- }
- new dialog_title[100];
- format(dialog_title, sizeof(dialog_title), "%s", nCategories[categoryid]);
- if(strlen(npDIALOG_STRING) >= 1) ShowPlayerDialog(playerid, NPLAYER_DIALOG_ID, DIALOG_STYLE_LIST, dialog_title, npDIALOG_STRING, "Play", "Back");
- }
- else
- {
- ShowDialog(playerid);
- }
- return true;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case NPLAYER_DIALOG_ID:
- {
- if(response)
- {
- new item_id = ItemIDFromDialogOrder(playerid, listitem);
- PlayMusic(playerid, item_id);
- }
- else
- {
- ShowDialog(playerid);
- }
- }
- case NPCATEGORIES_DIALOG_ID:
- {
- if(response)
- {
- CategoryBrowse(playerid, listitem);
- }
- }
- }
- if (inputtext[0]) return CallLocalFunction("nplayer_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,inputtext);
- else return CallLocalFunction("nplayer_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,NRNULL);
- }
- CMD:music(playerid, params[])
- {
- ShowDialog(playerid);
- return 1;
- }
- #if defined _ALS_OnDialogResponse
- #undef OnDialogResponse
- #else
- #define _ALS_OnDialogResponse
- #endif
- #define OnDialogResponse nplayer_OnDialogResponse
- forward nplayer_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement