1
0

audio.inc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. SA-MP Audio Plugin v0.4
  3. Copyright © 2010 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. #if defined _audio_included
  16. #endinput
  17. #endif
  18. #define _audio_included
  19. #pragma library audio
  20. // Natives
  21. native Audio_CreateTCPServer(port);
  22. native Audio_DestroyTCPServer();
  23. native Audio_SetPack(const audiopack[], bool:transferable = true);
  24. native Audio_CreateSequence();
  25. native Audio_DestroySequence(sequenceid);
  26. native Audio_AddToSequence(sequenceid, audioid);
  27. native Audio_RemoveFromSequence(sequenceid, audioid);
  28. native Audio_Play(playerid, audioid, bool:pause = false, bool:loop = false, bool:downmix = false);
  29. native Audio_PlaySequence(playerid, sequenceid, 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_Pause(playerid, handleid);
  32. native Audio_Resume(playerid, handleid);
  33. native Audio_Stop(playerid, handleid);
  34. native Audio_Restart(playerid, handleid);
  35. native Audio_Seek(playerid, handleid, seconds);
  36. native Audio_SetVolume(playerid, handleid, volume);
  37. native Audio_Set3DPosition(playerid, handleid, Float:x, Float:y, Float:z, Float:distance);
  38. native Audio_Set3DOffsets(playerid, handleid, Float:x, Float:y, Float:z);
  39. native Audio_SetFX(playerid, handleid, type);
  40. native Audio_RemoveFX(playerid, handleid, type);
  41. native Audio_SetEAX(playerid, environment);
  42. native Audio_RemoveEAX(playerid);
  43. native Audio_IsClientConnected(playerid);
  44. native Audio_TransferPack(playerid);
  45. native Audio_AddPlayer(playerid, const ip[], const name[]);
  46. native Audio_RemovePlayer(playerid);
  47. // Callbacks
  48. forward Audio_OnClientConnect(playerid);
  49. forward Audio_OnClientDisconnect(playerid);
  50. forward Audio_OnSetPack(audiopack[]);
  51. forward Audio_OnTransferFile(playerid, file[], current, total, result);
  52. forward Audio_OnPlay(playerid, handleid);
  53. forward Audio_OnStop(playerid, handleid);
  54. forward Audio_OnTrackChange(playerid, handleid, track[]);
  55. // Automatic Setup System
  56. static
  57. bool:Audio_g_CTS = false,
  58. bool:Audio_g_OPC = false,
  59. bool:Audio_g_OPDC = false;
  60. public
  61. OnFilterScriptInit()
  62. {
  63. if (!Audio_g_CTS)
  64. {
  65. Audio_g_CTS = true;
  66. Audio_g_OPC = (funcidx("Audio_OnPlayerConnect") != -1);
  67. Audio_g_OPDC = (funcidx("Audio_OnPlayerDisconnect") != -1);
  68. Audio_CreateTCPServer(GetServerVarAsInt("port"));
  69. }
  70. if (funcidx("Audio_OnFilterScriptInit") != -1)
  71. {
  72. return CallLocalFunction("Audio_OnFilterScriptInit", "");
  73. }
  74. return 1;
  75. }
  76. #if defined _ALS_OnFilterScriptInit
  77. #undef OnFilterScriptInit
  78. #else
  79. #define _ALS_OnFilterScriptInit
  80. #endif
  81. #define OnFilterScriptInit Audio_OnFilterScriptInit
  82. forward
  83. Audio_OnFilterScriptInit();
  84. public
  85. OnGameModeInit()
  86. {
  87. if (!Audio_g_CTS)
  88. {
  89. Audio_g_CTS = true;
  90. Audio_g_OPC = (funcidx("Audio_OnPlayerConnect") != -1);
  91. Audio_g_OPDC = (funcidx("Audio_OnPlayerDisconnect") != -1);
  92. Audio_CreateTCPServer(GetServerVarAsInt("port"));
  93. }
  94. if (funcidx("Audio_OnGameModeInit") != -1)
  95. {
  96. return CallLocalFunction("Audio_OnGameModeInit", "");
  97. }
  98. return 1;
  99. }
  100. #if defined _ALS_OnGameModeInit
  101. #undef OnGameModeInit
  102. #else
  103. #define _ALS_OnGameModeInit
  104. #endif
  105. #define OnGameModeInit Audio_OnGameModeInit
  106. forward
  107. Audio_OnGameModeInit();
  108. public
  109. OnPlayerConnect(playerid)
  110. {
  111. if (!IsPlayerNPC(playerid))
  112. {
  113. new
  114. ip[16],
  115. name[MAX_PLAYER_NAME];
  116. GetPlayerIp(playerid, ip, sizeof(ip));
  117. GetPlayerName(playerid, name, sizeof(name));
  118. Audio_AddPlayer(playerid, ip, name);
  119. }
  120. if (Audio_g_OPC)
  121. {
  122. return CallLocalFunction("Audio_OnPlayerConnect", "d", playerid);
  123. }
  124. return 1;
  125. }
  126. #if defined _ALS_OnPlayerConnect
  127. #undef OnPlayerConnect
  128. #else
  129. #define _ALS_OnPlayerConnect
  130. #endif
  131. #define OnPlayerConnect Audio_OnPlayerConnect
  132. forward
  133. Audio_OnPlayerConnect(playerid);
  134. public
  135. OnPlayerDisconnect(playerid, reason)
  136. {
  137. if (!IsPlayerNPC(playerid))
  138. {
  139. Audio_RemovePlayer(playerid);
  140. }
  141. if (Audio_g_OPDC)
  142. {
  143. return CallLocalFunction("Audio_OnPlayerDisconnect", "dd", playerid, reason);
  144. }
  145. return 1;
  146. }
  147. #if defined _ALS_OnPlayerDisconnect
  148. #undef OnPlayerDisconnect
  149. #else
  150. #define _ALS_OnPlayerDisconnect
  151. #endif
  152. #define OnPlayerDisconnect Audio_OnPlayerDisconnect
  153. forward
  154. Audio_OnPlayerDisconnect(playerid, reason);