Advertisement
norn

nJukebox v0.1

Nov 6th, 2011
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.51 KB | None | 0 0
  1. #include <a_samp>
  2. #define MAX_JUKEBOXES 100
  3. #define MAX_JUKEBOX_ITEMS 50
  4. #define MAX_JB_STREAM_URL 100
  5. #define MAX_JB_STREAM_T 60
  6. #define JUKEBOX_MAX_ITEMS_A MAX_JUKEBOXES * MAX_JUKEBOX_ITEMS
  7. #define JUKEBOX_DIALOG 5483
  8. forward JukeBoxDialog(playerid, jukeboxid);
  9. forward CreateJukebox(Float:x, Float:y, Float:z, Float:rotx, Float:roty, Float:rotz, pps, Float:stream_distance);
  10. forward AttachStreamToJukebox(jukeboxid, streamtitle[MAX_JB_STREAM_T], streamurl[MAX_JB_STREAM_URL]);
  11. forward JukeBoxItemExists(id);
  12. forward JukeBoxExists(id);
  13. forward DestroyJukebox(id);
  14. forward DestroyJukeboxItem(id);
  15. forward SetJukeboxPos(id, Float:x, Float:y, Float:z);
  16. forward SetJukeboxRot(id, Float:x, Float:y, Float:z);
  17. forward SetJukeboxItemStream(id, newstream[MAX_JB_STREAM_T]);
  18. forward SetJukeboxItemTitle(id, newtitle[MAX_JB_STREAM_T]);
  19. forward SetJukeboxItemOwner(id, jukeboxid);
  20. forward SetJukeboxPricePerSong(id, price);
  21. forward SetJukeboxStreamDistance(id, Float:stream_distance);
  22. enum _JukeBoxItem
  23. {
  24. jbiOwnerID,
  25. jbiStreamURL[MAX_JB_STREAM_URL],
  26. jbiStreamTitle[MAX_JB_STREAM_T],
  27. jbiOrder
  28. }
  29. enum _JukeBox
  30. {
  31. Float:jbX,
  32. Float:jbY,
  33. Float:jbZ,
  34. Float:jbRotX,
  35. Float:jbRotY,
  36. Float:jbRotZ,
  37. jbPPS,
  38. jbObjID,
  39. jbItemsLoaded,
  40. Float:jbStreamDistance
  41. }
  42. new JukeBox[MAX_JUKEBOXES][_JukeBox], JukeBoxItem[JUKEBOX_MAX_ITEMS_A][_JukeBoxItem];
  43. public SetJukeboxItemStream(id, newstream[MAX_JB_STREAM_T])
  44. {
  45. if(JukeBoxItemExists(id)) {
  46. format(JukeBoxItem[id][jbiStreamURL], MAX_JB_STREAM_URL, newstream);
  47. return true;
  48. }
  49. return false;
  50. }
  51. public SetJukeboxStreamDistance(id, Float:stream_distance)
  52. {
  53. if(JukeBoxExists(id)) {
  54. JukeBox[id][jbStreamDistance] = stream_distance;
  55. return true;
  56. }
  57. return false;
  58. }
  59. public SetJukeboxItemTitle(id, newtitle[MAX_JB_STREAM_T])
  60. {
  61. if(JukeBoxItemExists(id)) {
  62. format(JukeBoxItem[id][jbiStreamTitle], MAX_JB_STREAM_T, newtitle);
  63. return true;
  64. }
  65. return false;
  66. }
  67. public SetJukeboxItemOwner(id, jukeboxid)
  68. {
  69. if(JukeBoxItemExists(id) && JukeBoxExists(jukeboxid)) {
  70. JukeBoxItem[id][jbiOwnerID] = jukeboxid;
  71. return true;
  72. }
  73. return false;
  74. }
  75. public SetJukeboxRot(id, Float:x, Float:y, Float:z)
  76. {
  77. if(JukeBoxExists(id)) {
  78. JukeBox[id][jbRotX] = x, JukeBox[id][jbRotY] = y, JukeBox[id][jbRotZ] = z;
  79. SetObjectRot(JukeBox[id][jbObjID], JukeBox[id][jbRotX], JukeBox[id][jbRotY], JukeBox[id][jbRotZ]);
  80. return true;
  81. }
  82. return false;
  83. }
  84. public SetJukeboxPricePerSong(id, price)
  85. {
  86. if(JukeBoxExists(id)) {
  87. JukeBox[id][jbPPS] = price;
  88. return true;
  89. }
  90. return false;
  91. }
  92. public SetJukeboxPos(id, Float:x, Float:y, Float:z)
  93. {
  94. if(JukeBoxExists(id)) {
  95. DestroyObject(JukeBox[id][jbObjID]);
  96. JukeBox[id][jbX] = x, JukeBox[id][jbY] = y, JukeBox[id][jbZ] = z;
  97. JukeBox[id][jbObjID] = CreateObject(2618, JukeBox[id][jbX], JukeBox[id][jbY], JukeBox[id][jbZ], JukeBox[id][jbRotX], JukeBox[id][jbRotY], JukeBox[id][jbRotZ]);
  98. return true;
  99. }
  100. return false;
  101. }
  102. public DestroyJukebox(id)
  103. {
  104. if(JukeBoxExists(id)) {
  105. for(new i = 0; i < JUKEBOX_MAX_ITEMS_A; i++) {
  106. if(JukeBoxItemExists(i)) {
  107. if(JukeBoxItem[i][jbiOwnerID] == id) {
  108. DestroyJukeboxItem(id);
  109. }
  110. }
  111. }
  112. JukeBox[id][jbX] = 0, JukeBox[id][jbY] = 0, JukeBox[id][jbZ] = 0, JukeBox[id][jbRotX] = 0, JukeBox[id][jbRotY] = 0, JukeBox[id][jbRotZ] = 0, JukeBox[id][jbPPS] = 0, JukeBox[id][jbStreamDistance] = 0, JukeBox[id][jbItemsLoaded] = 0;
  113. DestroyObject(JukeBox[id][jbObjID]);
  114. return true;
  115. }
  116. return false;
  117. }
  118. public DestroyJukeboxItem(id)
  119. {
  120. if(JukeBoxItemExists(id)) {
  121. JukeBox[JukeBoxItem[id][jbiOwnerID]][jbItemsLoaded]--;
  122. format(JukeBoxItem[id][jbiStreamTitle], MAX_JB_STREAM_T, "");
  123. format(JukeBoxItem[id][jbiStreamURL], MAX_JB_STREAM_URL, "");
  124. JukeBoxItem[id][jbiOwnerID] = 0;
  125. JukeBoxItem[id][jbiOrder] = 0;
  126. return true;
  127. }
  128. return false;
  129. }
  130. public CreateJukebox(Float:x, Float:y, Float:z, Float:rotx, Float:roty, Float:rotz, pps, Float:stream_distance)
  131. {
  132. new id = JB_Array_Space();
  133. if(id != -1) {
  134. JukeBox[id][jbX] = x, JukeBox[id][jbY] = y, JukeBox[id][jbZ] = z, JukeBox[id][jbRotX] = rotx, JukeBox[id][jbRotY] = roty, JukeBox[id][jbRotZ] = rotz, JukeBox[id][jbPPS] = pps, JukeBox[id][jbStreamDistance] = stream_distance;
  135. JukeBox[id][jbObjID] = CreateObject(2618, JukeBox[id][jbX], JukeBox[id][jbY], JukeBox[id][jbZ], JukeBox[id][jbRotX], JukeBox[id][jbRotY], JukeBox[id][jbRotZ]);
  136. }
  137. return id;
  138. }
  139. public AttachStreamToJukebox(jukeboxid, streamtitle[MAX_JB_STREAM_T], streamurl[MAX_JB_STREAM_URL])
  140. {
  141. if(JukeBoxExists(jukeboxid)) {
  142. if(JukeBox[jukeboxid][jbItemsLoaded] < MAX_JUKEBOX_ITEMS) {
  143. new id = JBI_Array_Space();
  144. if(id != -1) {
  145. format(JukeBoxItem[id][jbiStreamTitle], MAX_JB_STREAM_T, streamtitle);
  146. format(JukeBoxItem[id][jbiStreamURL], MAX_JB_STREAM_URL, streamurl);
  147. JukeBoxItem[id][jbiOwnerID] = jukeboxid;
  148. printf("[nJukebox:] Attached %s to jukebox id %d.", JukeBoxItem[id][jbiStreamTitle], jukeboxid);
  149. JukeBoxItem[id][jbiOrder] = JukeBox[jukeboxid][jbItemsLoaded];
  150. JukeBox[jukeboxid][jbItemsLoaded]++;
  151. return id;
  152. }
  153. }
  154. }
  155. return -1;
  156. }
  157. stock JBI_Array_Space()
  158. {
  159. for(new s = 0; s < JUKEBOX_MAX_ITEMS_A; s++) {
  160. if(!JukeBoxItemExists(s)) {
  161. return s;
  162. }
  163. }
  164. return -1;
  165. }
  166. stock JB_Array_Space()
  167. {
  168. for(new s = 0; s < MAX_JUKEBOXES; s++) {
  169. if(!JukeBoxExists(s)) {
  170. return s;
  171. }
  172. }
  173. return -1;
  174. }
  175. public JukeBoxItemExists(id)
  176. {
  177. if(!strlen(JukeBoxItem[id][jbiStreamURL])) { return false; }
  178. return true;
  179. }
  180. public JukeBoxExists(id)
  181. {
  182. if(!JukeBox[id][jbX] && !JukeBox[id][jbY] && !JukeBox[id][jbZ]) { return false; }
  183. return true;
  184. }
  185. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  186. {
  187. switch(dialogid) {
  188. case JUKEBOX_DIALOG:
  189. {
  190. PlayerPlaySound(playerid, 5205, 0.0, 0.0, 0.0);
  191. if(response) {
  192. for(new i = 0; i < JUKEBOX_MAX_ITEMS_A; i++) {
  193. new jukeboxid = GetPVarInt(playerid, "jukeboxID");
  194. if(JukeBoxItemExists(i)) {
  195. if(JukeBoxItem[i][jbiOwnerID] == jukeboxid) {
  196. if(JukeBoxItem[i][jbiOrder] == listitem) {
  197. if(GetPlayerMoney(playerid) >= JukeBox[jukeboxid][jbPPS]) {
  198. GivePlayerMoney(playerid, -JukeBox[jukeboxid][jbPPS]);
  199. new now_playing[128], np_name[MAX_PLAYER_NAME];
  200. GetPlayerName(playerid, np_name, MAX_PLAYER_NAME);
  201. format(now_playing, sizeof(now_playing), "JUKEBOX: {FFFFFF}%s {ADD8E6}[Selected by {FFFFFF}%s(%d){ADD8E6}]", JukeBoxItem[i][jbiStreamTitle], np_name, playerid);
  202. for(new pid = 0; pid < MAX_PLAYERS; pid++) {
  203. if(IsPlayerConnected(pid) && IsPlayerInRangeOfPoint(pid, JukeBox[jukeboxid][jbStreamDistance], JukeBox[jukeboxid][jbX], JukeBox[jukeboxid][jbY], JukeBox[jukeboxid][jbZ])) {
  204. PlayAudioStreamForPlayer(pid, JukeBoxItem[i][jbiStreamURL], JukeBox[jukeboxid][jbX], JukeBox[jukeboxid][jbY], JukeBox[jukeboxid][jbZ], JukeBox[jukeboxid][jbStreamDistance], 1);
  205. SendClientMessage(pid, 0xADD8E6FF, now_playing);
  206.  
  207. }
  208. }
  209. DeletePVar(playerid,"jukeboxID");
  210. return true;
  211. }
  212. else {
  213. new jbrs[128];
  214. format(jbrs, sizeof(jbrs), "[ERROR:] You don't have enough money to play this song! [$%d]", JukeBox[i][jbPPS]);
  215. return SendClientMessage(playerid, 0xADD8E6FF, jbrs);
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. if (inputtext[0]) return CallLocalFunction("NJB_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,inputtext);
  225. else return CallLocalFunction("NJB_OnDialogResponse","iiiis",playerid,dialogid,response,listitem,"\1\0");
  226. }
  227. #if defined _ALS_OnDialogResponse
  228. #undef OnDialogResponse
  229. #else
  230. #define _ALS_OnDialogResponse
  231. #endif
  232. #define OnDialogResponse NJB_OnDialogResponse
  233. forward NJB_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  234. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  235. {
  236. if (newkeys & KEY_SECONDARY_ATTACK) {
  237. for(new s = 0; s < MAX_JUKEBOXES; s++) {
  238. if(JukeBoxExists(s)) {
  239. if(IsPlayerInRangeOfPoint(playerid, 1.5, JukeBox[s][jbX], JukeBox[s][jbY], JukeBox[s][jbZ])) {
  240. new Float:Px, Float:Py, Float: Pa;
  241. GetPlayerPos(playerid, Px, Py, Pa);
  242. Pa = floatabs(atan((JukeBox[s][jbY]-Py)/(JukeBox[s][jbX]-Px)));
  243. if (JukeBox[s][jbX] <= Px && JukeBox[s][jbY] >= Py) Pa = floatsub(180, Pa);
  244. else if (JukeBox[s][jbX] < Px && JukeBox[s][jbY] < Py) Pa = floatadd(Pa, 180);
  245. else if (JukeBox[s][jbX] >= Px && JukeBox[s][jbY] <= Py) Pa = floatsub(360.0, Pa);
  246. Pa = floatsub(Pa, 90.0);
  247. if (Pa >= 360.0) Pa = floatsub(Pa, 360.0);
  248. SetPlayerFacingAngle(playerid, Pa);
  249. ApplyAnimation(playerid,"GANGS","DRUGS_BUY",3.00,0,0,0,0,0,0);
  250. SetTimerEx("JukeBoxDialog", 1500, false, "ii", playerid, s);
  251. PlayerPlaySound(playerid, 5205, 0.0, 0.0, 0.0);
  252. }
  253. }
  254. }
  255. }
  256. return CallLocalFunction("NJB_OnPlayerKeyStateChange", "iii", playerid, newkeys, oldkeys);
  257. }
  258. #if defined _ALS_OnPlayerKeyStateChange
  259. #undef OnPlayerKeyStateChange
  260. #else
  261. #define _ALS_OnPlayerKeyStateChange
  262. #endif
  263. #define OnPlayerKeyStateChange NJB_OnPlayerKeyStateChange
  264. forward NJB_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  265. public JukeBoxDialog(playerid, jukeboxid)
  266. {
  267. if(JukeBoxExists(jukeboxid) && IsPlayerConnected(playerid)) {
  268. new ddata[1028], ptext[70], loaded;
  269. for(new i = 0; i < JUKEBOX_MAX_ITEMS_A; i++) {
  270. if(JukeBoxItemExists(i)) {
  271. if(JukeBoxItem[i][jbiOwnerID] == jukeboxid) {
  272. if(loaded == JukeBox[jukeboxid][jbItemsLoaded]) { return true; }
  273. format( ddata, sizeof(ddata), "%s\n{37DB45}%d. {FFFFFF}%s", ddata, loaded+1, JukeBoxItem[i][jbiStreamTitle]);
  274. loaded++;
  275. }
  276. }
  277. }
  278. if(strlen(ddata) >= 1) { format(ptext, sizeof(ptext), "{FFFFFF}Jukebox %d - {37DB45}$ %d {FFFFFF}Per Song", jukeboxid, JukeBox[jukeboxid][jbPPS]), ShowPlayerDialog(playerid, JUKEBOX_DIALOG, DIALOG_STYLE_LIST, ptext, ddata, "Play Song", "Cancel"), SetPVarInt(playerid, "jukeboxID", jukeboxid); }
  279. }
  280. return true;
  281. }
  282.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement