Advertisement
Guest User

nPlayer v0.1.1

a guest
Nov 5th, 2011
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.41 KB | None | 0 0
  1. /*
  2. __________.__
  3. ____\______ \ | _____ ___.__. ___________
  4. / \| ___/ | \__ \< | |/ __ \_ __ \
  5. | | \ | | |__/ __ \\___ \ ___/| | \/
  6. |___| /____| |____(____ / ____|\___ >__|
  7. \/ \/\/ \/
  8. Credits:
  9. Incognito (http://forum.sa-mp.com/member.php?u=925) (Audio Plugin) (Non 0.3d Version)
  10. Norn (Scott Davey) (http://forum.sa-mp.com/member.php?u=33812)
  11. Y_Less - Callback Hooking Method (http://forum.sa-mp.com/member.php?u=29176)
  12. */
  13.  
  14. #include <a_samp>
  15. stock NRNULL[] = "\1\0";
  16. #define NPMAX_ITEMS 500
  17. #define NPMAX_CATEGORIES 30
  18. #define NPINVALID_ITEM_ID -1
  19. #define NPMAX_CATEGORY_LENGTH 75
  20. #define NPMAX_ITEM_LENGTH 75
  21. #define NPMAX_STREAM_URL_LENGTH 128
  22. #define NPCATEGORIES_DIALOG_ID 1553
  23. #define NPLAYER_DIALOG_ID 1552
  24. forward PlayerCategoryBrowse(playerid, listitem);
  25. forward PlayerAddCategory(name[NPMAX_CATEGORY_LENGTH]);
  26. forward AddStreamToCategory(categoryid, name[NPMAX_ITEM_LENGTH], streamurl[NPMAX_STREAM_URL_LENGTH]);
  27. forward PlayerInitDialog(playerid);
  28. forward PlayerStop(playerid);
  29. forward PlayerPlay(playerid, itemid);
  30. forward DeleteCategory(categoryid);
  31. forward ModifyCategory(categoryid, name[NPMAX_CATEGORY_LENGTH]);
  32. forward ModifyItem(itemid, name[NPMAX_ITEM_LENGTH], streamurl[NPMAX_STREAM_URL_LENGTH]);
  33. forward DeleteItem(itemid);
  34. forward ItemCountFromCategory(categoryid);
  35. forward CategoryIDFromDialogOrder(listitem);
  36. forward ItemIDFromDialogOrder(playerid, listitem);
  37. enum nPlayerItem
  38. {
  39. npCategoryID,
  40. npTitle[NPMAX_ITEM_LENGTH],
  41. npStreamURL[NPMAX_STREAM_URL_LENGTH]
  42. }
  43. new PlayerItem[NPMAX_ITEMS][nPlayerItem], nCategories[NPMAX_ITEMS][NPMAX_CATEGORY_LENGTH], nrCATEGORY_COUNT = 0, npITEM_COUNT = 0, npDIALOG_STRING[1028], npTextString[128];
  44. public PlayerAddCategory(name[NPMAX_CATEGORY_LENGTH])
  45. {
  46. new CATEGORY_ID = NPINVALID_ITEM_ID;
  47. if(strlen(name) >= 1 && strlen(name) <= NPMAX_CATEGORY_LENGTH) {
  48. if(nrCATEGORY_COUNT < NPMAX_CATEGORIES) {
  49. for(new i=0;i<NPMAX_CATEGORIES;i++) {
  50. if(!strlen(nCategories[i])) {
  51. format(nCategories[i], NPMAX_CATEGORY_LENGTH, name);
  52. CATEGORY_ID = i;
  53. printf("[nPlayer:] Category ID %d (%s) created.", CATEGORY_ID, nCategories[i]);
  54. nrCATEGORY_COUNT++;
  55. return CATEGORY_ID;
  56. }
  57. }
  58. }
  59. }
  60. return CATEGORY_ID;
  61. }
  62. public AddStreamToCategory(categoryid, name[NPMAX_ITEM_LENGTH], streamurl[NPMAX_STREAM_URL_LENGTH])
  63. {
  64. new ITEM_ID = -1;
  65. if(strlen(name) >= 1 && strlen(name) <= NPMAX_ITEM_LENGTH) {
  66. if(npITEM_COUNT < NPMAX_ITEMS) {
  67. for(new i=0;i<NPMAX_ITEMS;i++) {
  68. if(!strlen(PlayerItem[i][npTitle])) {
  69. ITEM_ID = i;
  70. PlayerItem[i][npCategoryID] = categoryid;
  71. format(PlayerItem[i][npTitle], NPMAX_ITEM_LENGTH, name);
  72. format(PlayerItem[i][npStreamURL], NPMAX_STREAM_URL_LENGTH, streamurl);
  73. printf("[nPlayer:] Item ID %d (%s) created and attached to %s.", i, PlayerItem[i][npTitle], nCategories[categoryid]);
  74. npITEM_COUNT++;
  75. return ITEM_ID;
  76. }
  77. }
  78. }
  79. }
  80. return ITEM_ID;
  81. }
  82. public PlayerInitDialog(playerid)
  83. {
  84. format(npDIALOG_STRING, sizeof(npDIALOG_STRING), "");
  85. for(new i=0;i<nrCATEGORY_COUNT;i++) {
  86. if(!i) {
  87. if(strlen(nCategories[i]) >= 1)
  88. format(npDIALOG_STRING, sizeof(npDIALOG_STRING), nCategories[i]);
  89. }
  90. else {
  91. if(strlen(nCategories[i]) >= 1)
  92. format(npDIALOG_STRING, sizeof(npDIALOG_STRING), "%s\n%s", npDIALOG_STRING, nCategories[i]);
  93. }
  94. }
  95. if(strlen(npDIALOG_STRING) >= 1) { ShowPlayerDialog(playerid, NPCATEGORIES_DIALOG_ID, DIALOG_STYLE_LIST, "Player - Browse Categories", npDIALOG_STRING, "Browse", "Cancel"); }
  96. return true;
  97. }
  98. stock PlayerCategoryNameFromID(categoryid)
  99. {
  100. new category_name[NPMAX_CATEGORY_LENGTH];
  101. format(category_name, sizeof(category_name), nCategories[categoryid]);
  102. return category_name;
  103. }
  104. stock ItemNameFromID(itemid)
  105. {
  106. new item_name[NPMAX_ITEM_LENGTH];
  107. format(item_name, sizeof(item_name), PlayerItem[itemid][npTitle]);
  108. return item_name;
  109. }
  110. public PlayerStop(playerid)
  111. {
  112. StopAudioStreamForPlayer(playerid);
  113. return true;
  114. }
  115.  
  116. public PlayerPlay(playerid, itemid)
  117. {
  118. PlayerStop(playerid);
  119. PlayAudioStreamForPlayer(playerid, PlayerItem[itemid][npStreamURL]);
  120. return true;
  121. }
  122. public DeleteCategory(categoryid)
  123. {
  124. format(nCategories[categoryid], NPMAX_CATEGORY_LENGTH, "");
  125. for(new i=0;i<npITEM_COUNT;i++) {
  126. if(PlayerItem[i][npCategoryID] == categoryid && strlen(PlayerItem[i][npTitle]) >= 1) {
  127. format(PlayerItem[i][npTitle], NPMAX_ITEM_LENGTH, "");
  128. npITEM_COUNT--;
  129. }
  130. }
  131. nrCATEGORY_COUNT--;
  132. return true;
  133. }
  134. public ModifyCategory(categoryid, name[NPMAX_CATEGORY_LENGTH])
  135. {
  136. format(nCategories[categoryid], NPMAX_ITEM_LENGTH, name);
  137. return true;
  138. }
  139. public ModifyItem(itemid, name[NPMAX_ITEM_LENGTH], streamurl[NPMAX_STREAM_URL_LENGTH])
  140. {
  141. format(PlayerItem[itemid][npTitle], NPMAX_ITEM_LENGTH, name);
  142. format(PlayerItem[itemid][npStreamURL], NPMAX_ITEM_LENGTH, streamurl);
  143. return true;
  144. }
  145. public DeleteItem(itemid)
  146. {
  147. format(PlayerItem[itemid][npTitle], NPMAX_ITEM_LENGTH, "");
  148. npITEM_COUNT--;
  149. return true;
  150. }
  151. public ItemCountFromCategory(categoryid)
  152. {
  153. new count = 0;
  154. for(new i=0;i<npITEM_COUNT;i++) {
  155. if(PlayerItem[i][npCategoryID] == categoryid && strlen(PlayerItem[i][npTitle]) >= 1) {
  156. count++;
  157. }
  158. }
  159. return count;
  160. }
  161. public CategoryIDFromDialogOrder(listitem)
  162. {
  163. new current_array_id, bool:breakloop = false, id = -1;
  164. for(new i=0;i<nrCATEGORY_COUNT;i++) {
  165. if(strlen(nCategories[i]) >= 1) {
  166. if(!breakloop) {
  167. if(current_array_id == listitem) {
  168. id = i;
  169. breakloop = true;
  170. }
  171. current_array_id++;
  172. }
  173. }
  174. }
  175. return id;
  176. }
  177. public ItemIDFromDialogOrder(playerid, listitem)
  178. {
  179. new categoryid = GetPVarInt(playerid, "playerCategory"), current_array_id, bool:breakloop = false, id = -1;
  180. for(new i=0;i<npITEM_COUNT;i++) {
  181. if(PlayerItem[i][npCategoryID] == categoryid && strlen(PlayerItem[i][npTitle]) >= 1) {
  182. if(!breakloop) {
  183. if(current_array_id == listitem) {
  184. id = i;
  185. breakloop = true;
  186. }
  187. current_array_id++;
  188. }
  189. }
  190. }
  191. return id;
  192. }
  193. public PlayerCategoryBrowse(playerid, listitem)
  194. {
  195. format(npDIALOG_STRING, sizeof(npDIALOG_STRING), "");
  196. new categoryid = CategoryIDFromDialogOrder(listitem);
  197. SetPVarInt(playerid, "playerCategory", categoryid);
  198. if(ItemCountFromCategory(categoryid) >= 1) {
  199. for(new i=0;i<npITEM_COUNT;i++) {
  200. if(PlayerItem[i][npCategoryID] == categoryid) {
  201. if(!i) {
  202. if(strlen(PlayerItem[i][npTitle]) >= 1)
  203. format(npDIALOG_STRING, sizeof(npDIALOG_STRING), PlayerItem[i][npTitle]);
  204. }
  205. else {
  206. if(strlen(PlayerItem[i][npTitle]) >= 1)
  207. format(npDIALOG_STRING, sizeof(npDIALOG_STRING), "%s\n%s", npDIALOG_STRING, PlayerItem[i][npTitle]);
  208. }
  209. }
  210. }
  211. new dialog_title[100];
  212. format(dialog_title, sizeof(dialog_title), "Player - %s", nCategories[categoryid]);
  213. if(strlen(npDIALOG_STRING) >= 1) { ShowPlayerDialog(playerid, NPLAYER_DIALOG_ID, DIALOG_STYLE_LIST, dialog_title, npDIALOG_STRING, "Stream", "Go Back"); }
  214. }
  215. else {
  216. format(npTextString, sizeof(npTextString), "[Player:] No items exist in category ' %s '.", PlayerCategoryNameFromID(categoryid));
  217. SendClientMessage(playerid, 0xFF0000FF, npTextString);
  218. PlayerInitDialog(playerid);
  219. }
  220. return true;
  221. }
  222. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  223. {
  224. switch(dialogid) {
  225. case NPLAYER_DIALOG_ID:
  226. {
  227. if(response) {
  228. new item_id = ItemIDFromDialogOrder(playerid, listitem);
  229. PlayerPlay(playerid, item_id);
  230. format(npTextString,sizeof(npTextString),"[Player:] Stream for %s started.", ItemNameFromID(item_id));
  231. SendClientMessage(playerid, 0xADD8E6FF, npTextString);
  232. }
  233. else {
  234. PlayerInitDialog(playerid);
  235. }
  236. }
  237. case NPCATEGORIES_DIALOG_ID:
  238. {
  239. if(response) {
  240. PlayerCategoryBrowse(playerid, listitem);
  241. }
  242. }
  243. }
  244. if (inputtext[0]) return CallLocalFunction("nplayer_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,inputtext);
  245. else return CallLocalFunction("nplayer_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,NRNULL);
  246. }
  247. #if defined _ALS_OnDialogResponse
  248. #undef OnDialogResponse
  249. #else
  250. #define _ALS_OnDialogResponse
  251. #endif
  252. #define OnDialogResponse nplayer_OnDialogResponse
  253. forward nplayer_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  254.  
  255.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement