audio.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. SA-MP Audio Plugin v0.5
  3. Copyright © 2011 Incognito
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include <a_samp>
  16. // Main Natives
  17. native Audio_CreateTCPServer(port);
  18. native Audio_DestroyTCPServer();
  19. native Audio_SetPack(const name[], bool:transferable = true, bool:automated = true);
  20. native Audio_IsClientConnected(playerid);
  21. native Audio_SendMessage(playerid, const message[]);
  22. native Audio_TransferPack(playerid);
  23. // Sequence Natives
  24. native Audio_CreateSequence();
  25. native Audio_DestroySequence(sequenceid);
  26. native Audio_AddToSequence(sequenceid, audioid);
  27. native Audio_RemoveFromSequence(sequenceid, audioid);
  28. // Audio Natives
  29. native Audio_Play(playerid, audioid, bool:pause = false, bool:loop = false, bool:downmix = false);
  30. native Audio_PlayStreamed(playerid, const url[], bool:pause = false, bool:loop = false, bool:downmix = false);
  31. native Audio_PlaySequence(playerid, sequenceid, bool:pause = false, bool:loop = false, bool:downmix = false);
  32. native Audio_Pause(playerid, handleid);
  33. native Audio_Resume(playerid, handleid);
  34. native Audio_Stop(playerid, handleid);
  35. native Audio_Restart(playerid, handleid);
  36. native Audio_GetPosition(playerid, handleid, const callback[] = "Audio_OnGetPosition");
  37. native Audio_SetPosition(playerid, handleid, seconds);
  38. native Audio_SetVolume(playerid, handleid, volume);
  39. native Audio_SetFX(playerid, handleid, type);
  40. native Audio_RemoveFX(playerid, handleid, type);
  41. native Audio_Set3DPosition(playerid, handleid, Float:x, Float:y, Float:z, Float:distance);
  42. native Audio_Remove3DPosition(playerid, handleid);
  43. // Radio Station Natives
  44. native Audio_SetRadioStation(playerid, station);
  45. native Audio_StopRadio(playerid);
  46. // Internal Natives
  47. native Audio_AddPlayer(playerid, const ip[], const name[]);
  48. native Audio_RenamePlayer(playerid, const name[]);
  49. native Audio_RemovePlayer(playerid);
  50. // Main Callbacks
  51. forward Audio_OnClientConnect(playerid);
  52. forward Audio_OnClientDisconnect(playerid);
  53. forward Audio_OnTransferFile(playerid, file[], current, total, result);
  54. forward Audio_OnPlay(playerid, handleid);
  55. forward Audio_OnStop(playerid, handleid);
  56. forward Audio_OnTrackChange(playerid, handleid, track[]);
  57. forward Audio_OnRadioStationChange(playerid, station);
  58. // Custom Callbacks
  59. forward Audio_OnGetPosition(playerid, handleid, seconds);
  60. // Callback Hook Section
  61. static bool:Audio_g_CTS = false;
  62. static bool:Audio_g_OPC = false;
  63. static bool:Audio_g_OPDC = false;
  64. public OnFilterScriptInit()
  65. {
  66. if (!Audio_g_CTS)
  67. {
  68. Audio_g_CTS = true;
  69. Audio_g_OPC = (funcidx("Audio_OnPlayerConnect") != -1);
  70. Audio_g_OPDC = (funcidx("Audio_OnPlayerDisconnect") != -1);
  71. Audio_CreateTCPServer(GetServerVarAsInt("port"));
  72. }
  73. if (funcidx("Audio_OnFilterScriptInit") != -1)
  74. {
  75. return CallLocalFunction("Audio_OnFilterScriptInit", "");
  76. }
  77. return 1;
  78. }
  79. #if defined _ALS_OnFilterScriptInit
  80. #undef OnFilterScriptInit
  81. #else
  82. #define _ALS_OnFilterScriptInit
  83. #endif
  84. #define OnFilterScriptInit Audio_OnFilterScriptInit
  85. forward Audio_OnFilterScriptInit();
  86. public OnGameModeInit()
  87. {
  88. if (!Audio_g_CTS)
  89. {
  90. Audio_g_CTS = true;
  91. Audio_g_OPC = (funcidx("Audio_OnPlayerConnect") != -1);
  92. Audio_g_OPDC = (funcidx("Audio_OnPlayerDisconnect") != -1);
  93. Audio_CreateTCPServer(GetServerVarAsInt("port"));
  94. }
  95. if (funcidx("Audio_OnGameModeInit") != -1)
  96. {
  97. return CallLocalFunction("Audio_OnGameModeInit", "");
  98. }
  99. return 1;
  100. }
  101. #if defined _ALS_OnGameModeInit
  102. #undef OnGameModeInit
  103. #else
  104. #define _ALS_OnGameModeInit
  105. #endif
  106. #define OnGameModeInit Audio_OnGameModeInit
  107. forward Audio_OnGameModeInit();
  108. public OnPlayerConnect(playerid)
  109. {
  110. if (!IsPlayerNPC(playerid))
  111. {
  112. new ip[16], name[MAX_PLAYER_NAME];
  113. GetPlayerIp(playerid, ip, sizeof(ip));
  114. GetPlayerName(playerid, name, sizeof(name));
  115. Audio_AddPlayer(playerid, ip, name);
  116. }
  117. if (Audio_g_OPC)
  118. {
  119. return CallLocalFunction("Audio_OnPlayerConnect", "d", playerid);
  120. }
  121. return 1;
  122. }
  123. #if defined _ALS_OnPlayerConnect
  124. #undef OnPlayerConnect
  125. #else
  126. #define _ALS_OnPlayerConnect
  127. #endif
  128. #define OnPlayerConnect Audio_OnPlayerConnect
  129. forward Audio_OnPlayerConnect(playerid);
  130. public OnPlayerDisconnect(playerid, reason)
  131. {
  132. if (!IsPlayerNPC(playerid))
  133. {
  134. Audio_RemovePlayer(playerid);
  135. }
  136. if (Audio_g_OPDC)
  137. {
  138. return CallLocalFunction("Audio_OnPlayerDisconnect", "dd", playerid, reason);
  139. }
  140. return 1;
  141. }
  142. #if defined _ALS_OnPlayerDisconnect
  143. #undef OnPlayerDisconnect
  144. #else
  145. #define _ALS_OnPlayerDisconnect
  146. #endif
  147. #define OnPlayerDisconnect Audio_OnPlayerDisconnect
  148. forward Audio_OnPlayerDisconnect(playerid, reason);
  149. // Native Hook Section
  150. stock Audio_SetPlayerName(playerid, name[])
  151. {
  152. new value = SetPlayerName(playerid, name);
  153. if (value > 0)
  154. {
  155. Audio_RenamePlayer(playerid, name);
  156. }
  157. return value;
  158. }
  159. #if defined _ALS_SetPlayerName
  160. #undef SetPlayerName
  161. #else
  162. #define _ALS_SetPlayerName
  163. #endif
  164. #define SetPlayerName Audio_SetPlayerName