1
0

audio.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (C) 2012 Incognito
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <a_samp>
  17. // Natives (Main)
  18. native Audio_CreateTCPServer(port);
  19. native Audio_DestroyTCPServer();
  20. native Audio_SetPack(const name[], bool:transferable = true, bool:automated = true);
  21. native Audio_IsClientConnected(playerid);
  22. native Audio_SendMessage(playerid, const message[]);
  23. native Audio_TransferPack(playerid);
  24. // Natives (Sequences)
  25. native Audio_CreateSequence();
  26. native Audio_DestroySequence(sequenceid);
  27. native Audio_AddToSequence(sequenceid, audioid);
  28. native Audio_RemoveFromSequence(sequenceid, audioid);
  29. // Natives (Audio)
  30. native Audio_Play(playerid, audioid, bool:pause = false, bool:loop = false, bool:downmix = false);
  31. native Audio_PlayStreamed(playerid, const url[], bool:pause = false, bool:loop = false, bool:downmix = false);
  32. native Audio_PlaySequence(playerid, sequenceid, bool:pause = false, bool:loop = false, bool:downmix = false);
  33. native Audio_Pause(playerid, handleid);
  34. native Audio_Resume(playerid, handleid);
  35. native Audio_Stop(playerid, handleid);
  36. native Audio_Restart(playerid, handleid);
  37. native Audio_GetPosition(playerid, handleid, const callback[] = "Audio_OnGetPosition");
  38. native Audio_SetPosition(playerid, handleid, seconds);
  39. native Audio_SetVolume(playerid, handleid, volume);
  40. native Audio_SetFX(playerid, handleid, type);
  41. native Audio_RemoveFX(playerid, handleid, type);
  42. native Audio_Set3DPosition(playerid, handleid, Float:x, Float:y, Float:z, Float:distance);
  43. native Audio_Remove3DPosition(playerid, handleid);
  44. // Natives (Radio Stations)
  45. native Audio_SetRadioStation(playerid, station);
  46. native Audio_StopRadio(playerid);
  47. // Natives (Internal)
  48. native Audio_AddPlayer(playerid, const ip[], const name[]);
  49. native Audio_RenamePlayer(playerid, const name[]);
  50. native Audio_RemovePlayer(playerid);
  51. // Callbacks (Main)
  52. forward Audio_OnClientConnect(playerid);
  53. forward Audio_OnClientDisconnect(playerid);
  54. forward Audio_OnTransferFile(playerid, file[], current, total, result);
  55. forward Audio_OnPlay(playerid, handleid);
  56. forward Audio_OnStop(playerid, handleid);
  57. forward Audio_OnTrackChange(playerid, handleid, track[]);
  58. forward Audio_OnRadioStationChange(playerid, station);
  59. // Callbacks (Custom)
  60. forward Audio_OnGetPosition(playerid, handleid, seconds);
  61. // Callback Hook Section
  62. static bool:Audio_g_CTS = false;
  63. static bool:Audio_g_OPC = false;
  64. static bool:Audio_g_OPDC = false;
  65. public OnFilterScriptInit()
  66. {
  67. if (!Audio_g_CTS)
  68. {
  69. Audio_g_CTS = true;
  70. Audio_g_OPC = (funcidx("Audio_OnPlayerConnect") != -1);
  71. Audio_g_OPDC = (funcidx("Audio_OnPlayerDisconnect") != -1);
  72. Audio_CreateTCPServer(GetServerVarAsInt("port"));
  73. }
  74. if (funcidx("Audio_OnFilterScriptInit") != -1)
  75. {
  76. return CallLocalFunction("Audio_OnFilterScriptInit", "");
  77. }
  78. return 1;
  79. }
  80. #if defined _ALS_OnFilterScriptInit
  81. #undef OnFilterScriptInit
  82. #else
  83. #define _ALS_OnFilterScriptInit
  84. #endif
  85. #define OnFilterScriptInit Audio_OnFilterScriptInit
  86. forward Audio_OnFilterScriptInit();
  87. public OnGameModeInit()
  88. {
  89. if (!Audio_g_CTS)
  90. {
  91. Audio_g_CTS = true;
  92. Audio_g_OPC = (funcidx("Audio_OnPlayerConnect") != -1);
  93. Audio_g_OPDC = (funcidx("Audio_OnPlayerDisconnect") != -1);
  94. Audio_CreateTCPServer(GetServerVarAsInt("port"));
  95. }
  96. if (funcidx("Audio_OnGameModeInit") != -1)
  97. {
  98. return CallLocalFunction("Audio_OnGameModeInit", "");
  99. }
  100. return 1;
  101. }
  102. #if defined _ALS_OnGameModeInit
  103. #undef OnGameModeInit
  104. #else
  105. #define _ALS_OnGameModeInit
  106. #endif
  107. #define OnGameModeInit Audio_OnGameModeInit
  108. forward Audio_OnGameModeInit();
  109. public OnPlayerConnect(playerid)
  110. {
  111. if (!IsPlayerNPC(playerid))
  112. {
  113. new ip[16], name[MAX_PLAYER_NAME];
  114. GetPlayerIp(playerid, ip, sizeof(ip));
  115. GetPlayerName(playerid, name, sizeof(name));
  116. Audio_AddPlayer(playerid, ip, name);
  117. }
  118. if (Audio_g_OPC)
  119. {
  120. return CallLocalFunction("Audio_OnPlayerConnect", "d", playerid);
  121. }
  122. return 1;
  123. }
  124. #if defined _ALS_OnPlayerConnect
  125. #undef OnPlayerConnect
  126. #else
  127. #define _ALS_OnPlayerConnect
  128. #endif
  129. #define OnPlayerConnect Audio_OnPlayerConnect
  130. forward Audio_OnPlayerConnect(playerid);
  131. public OnPlayerDisconnect(playerid, reason)
  132. {
  133. if (!IsPlayerNPC(playerid))
  134. {
  135. Audio_RemovePlayer(playerid);
  136. }
  137. if (Audio_g_OPDC)
  138. {
  139. return CallLocalFunction("Audio_OnPlayerDisconnect", "dd", playerid, reason);
  140. }
  141. return 1;
  142. }
  143. #if defined _ALS_OnPlayerDisconnect
  144. #undef OnPlayerDisconnect
  145. #else
  146. #define _ALS_OnPlayerDisconnect
  147. #endif
  148. #define OnPlayerDisconnect Audio_OnPlayerDisconnect
  149. forward Audio_OnPlayerDisconnect(playerid, reason);
  150. // Native Hook Section
  151. stock Audio_SetPlayerName(playerid, name[])
  152. {
  153. new value = SetPlayerName(playerid, name);
  154. if (value > 0)
  155. {
  156. Audio_RenamePlayer(playerid, name);
  157. }
  158. return value;
  159. }
  160. #if defined _ALS_SetPlayerName
  161. #undef SetPlayerName
  162. #else
  163. #define _ALS_SetPlayerName
  164. #endif
  165. #define SetPlayerName Audio_SetPlayerName