streamer.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*
  2. SA-MP Streamer Plugin v2.6
  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. // Definitions
  17. #define STREAMER_TYPE_OBJECT (0)
  18. #define STREAMER_TYPE_PICKUP (1)
  19. #define STREAMER_TYPE_CP (2)
  20. #define STREAMER_TYPE_RACE_CP (3)
  21. #define STREAMER_TYPE_MAP_ICON (4)
  22. #define STREAMER_TYPE_3D_TEXT_LABEL (5)
  23. #define STREAMER_TYPE_AREA (6)
  24. #if !defined FLOAT_INFINITY
  25. #define FLOAT_INFINITY (Float:0x7F800000)
  26. #endif
  27. // Enumerator
  28. enum
  29. {
  30. E_STREAMER_ATTACHED_PLAYER,
  31. E_STREAMER_ATTACHED_VEHICLE,
  32. E_STREAMER_COLOR,
  33. E_STREAMER_DRAW_DISTANCE,
  34. E_STREAMER_EXTRA_ID,
  35. E_STREAMER_INTERIOR_ID,
  36. E_STREAMER_MAX_X,
  37. E_STREAMER_MAX_Y,
  38. E_STREAMER_MAX_Z,
  39. E_STREAMER_MIN_X,
  40. E_STREAMER_MIN_Y,
  41. E_STREAMER_MIN_Z,
  42. E_STREAMER_MODEL_ID,
  43. E_STREAMER_MOVE_R_X,
  44. E_STREAMER_MOVE_R_Y,
  45. E_STREAMER_MOVE_R_Z,
  46. E_STREAMER_MOVE_SPEED,
  47. E_STREAMER_MOVE_X,
  48. E_STREAMER_MOVE_Y,
  49. E_STREAMER_MOVE_Z,
  50. E_STREAMER_NEXT_X,
  51. E_STREAMER_NEXT_Y,
  52. E_STREAMER_NEXT_Z,
  53. E_STREAMER_PLAYER_ID,
  54. E_STREAMER_R_X,
  55. E_STREAMER_R_Y,
  56. E_STREAMER_R_Z,
  57. E_STREAMER_SIZE,
  58. E_STREAMER_STREAM_DISTANCE,
  59. E_STREAMER_STYLE,
  60. E_STREAMER_TEST_LOS,
  61. E_STREAMER_TYPE,
  62. E_STREAMER_WORLD_ID,
  63. E_STREAMER_X,
  64. E_STREAMER_Y,
  65. E_STREAMER_Z
  66. }
  67. // Setting Natives
  68. native Streamer_TickRate(rate);
  69. native Streamer_MaxItems(type, items);
  70. native Streamer_VisibleItems(type, items);
  71. native Streamer_CellDistance(Float:distance);
  72. native Streamer_CellSize(Float:size);
  73. // Update Natives
  74. native Streamer_Update(playerid);
  75. native Streamer_UpdateEx(playerid, Float:x, Float:y, Float:z, worldid = -1, interiorid = -1);
  76. native Streamer_ToggleIdleUpdate(playerid, toggle);
  77. // Data Manipulation Natives
  78. native Streamer_GetFloatData(type, {Text3D,_}:id, data, &Float:result);
  79. native Streamer_SetFloatData(type, {Text3D,_}:id, data, Float:value);
  80. native Streamer_GetIntData(type, {Text3D,_}:id, data);
  81. native Streamer_SetIntData(type, {Text3D,_}:id, data, value);
  82. native Streamer_IsInArrayData(type, {Text3D,_}:id, data, value);
  83. native Streamer_AppendArrayData(type, {Text3D,_}:id, data, value);
  84. native Streamer_RemoveArrayData(type, {Text3D,_}:id, data, value);
  85. native Streamer_GetUpperBound(type);
  86. // Miscellaneous Natives
  87. native Streamer_IsItemVisible(playerid, type, {Text3D,_}:id);
  88. native Streamer_DestroyAllVisibleItems(playerid, type);
  89. native Streamer_CountVisibleItems(playerid, type);
  90. // Object Natives
  91. native CreateDynamicObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 300.0);
  92. native DestroyDynamicObject(objectid);
  93. native IsValidDynamicObject(objectid);
  94. native SetDynamicObjectPos(objectid, Float:x, Float:y, Float:z);
  95. native GetDynamicObjectPos(objectid, &Float:x, &Float:y, &Float:z);
  96. native SetDynamicObjectRot(objectid, Float:rx, Float:ry, Float:rz);
  97. native GetDynamicObjectRot(objectid, &Float:rx, &Float:ry, &Float:rz);
  98. native MoveDynamicObject(objectid, Float:x, Float:y, Float:z, Float:speed, Float:rX = -1000.0, Float:rY = -1000.0, Float:rZ = -1000.0);
  99. native StopDynamicObject(objectid);
  100. native IsDynamicObjectMoving(objectid);
  101. native DestroyAllDynamicObjects();
  102. native CountDynamicObjects();
  103. // Pickup Natives
  104. native CreateDynamicPickup(modelid, type, Float:x, Float:y, Float:z, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 100.0);
  105. native DestroyDynamicPickup(pickupid);
  106. native IsValidDynamicPickup(pickupid);
  107. native DestroyAllDynamicPickups();
  108. native CountDynamicPickups();
  109. // Checkpoint Natives
  110. native CreateDynamicCP(Float:x, Float:y, Float:z, Float:size, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 100.0);
  111. native DestroyDynamicCP(checkpointid);
  112. native IsValidDynamicCP(checkpointid);
  113. native TogglePlayerDynamicCP(playerid, checkpointid, toggle);
  114. native TogglePlayerAllDynamicCPs(playerid, toggle);
  115. native IsPlayerInDynamicCP(playerid, checkpointid);
  116. native DestroyAllDynamicCPs();
  117. native CountDynamicCPs();
  118. // Race Checkpoint Natives
  119. native CreateDynamicRaceCP(type, Float:x, Float:y, Float:z, Float:nextx, Float:nexty, Float:nextz, Float:size, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 100.0);
  120. native DestroyDynamicRaceCP(checkpointid);
  121. native IsValidDynamicRaceCP(checkpointid);
  122. native TogglePlayerDynamicRaceCP(playerid, checkpointid, toggle);
  123. native TogglePlayerAllDynamicRaceCPs(playerid, toggle);
  124. native IsPlayerInDynamicRaceCP(playerid, checkpointid);
  125. native DestroyAllDynamicRaceCPs();
  126. native CountDynamicRaceCPs();
  127. // Map Icon Natives
  128. native CreateDynamicMapIcon(Float:x, Float:y, Float:z, type, color, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 100.0);
  129. native DestroyDynamicMapIcon(iconid);
  130. native IsValidDynamicMapIcon(iconid);
  131. native DestroyAllDynamicMapIcons();
  132. native CountDynamicMapIcons();
  133. // 3D Text Label Natives
  134. native Text3D:CreateDynamic3DTextLabel(const text[], color, Float:x, Float:y, Float:z, Float:drawdistance, attachedplayer = INVALID_PLAYER_ID, attachedvehicle = INVALID_VEHICLE_ID, testlos = 0, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 100.0);
  135. native DestroyDynamic3DTextLabel(Text3D:id);
  136. native IsValidDynamic3DTextLabel(Text3D:id);
  137. native UpdateDynamic3DTextLabelText(Text3D:id, color, const text[]);
  138. native DestroyAllDynamic3DTextLabels();
  139. native CountDynamic3DTextLabels();
  140. // Area Natives
  141. native CreateDynamicCircle(Float:x, Float:y, Float:size, worldid = -1, interiorid = -1, playerid = -1);
  142. native CreateDynamicRectangle(Float:minx, Float:miny, Float:maxx, Float:maxy, worldid = -1, interiorid = -1, playerid = -1);
  143. native CreateDynamicSphere(Float:x, Float:y, Float:z, Float:size, worldid = -1, interiorid = -1, playerid = -1);
  144. native CreateDynamicCube(Float:minx, Float:miny, Float:minz, Float:maxx, Float:maxy, Float:maxz, worldid = -1, interiorid = -1, playerid = -1);
  145. native CreateDynamicPolygon(Float:points[], Float:minz = -FLOAT_INFINITY, Float:maxz = FLOAT_INFINITY, maxpoints = sizeof points, worldid = -1, interiorid = -1, playerid = -1);
  146. native DestroyDynamicArea(areaid);
  147. native IsValidDynamicArea(areaid);
  148. native TogglePlayerDynamicArea(playerid, areaid, toggle);
  149. native TogglePlayerAllDynamicAreas(playerid, toggle);
  150. native IsPlayerInDynamicArea(playerid, areaid);
  151. native IsPlayerInAnyDynamicArea(playerid);
  152. native AttachDynamicAreaToPlayer(areaid, playerid);
  153. native AttachDynamicAreaToVehicle(areaid, vehicleid);
  154. native DestroyAllDynamicAreas();
  155. native CountDynamicAreas();
  156. // Extended Natives
  157. native CreateDynamicObjectEx(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 0.0, Float:streamdistance = 200.0, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  158. native CreateDynamicPickupEx(modelid, type, Float:x, Float:y, Float:z, Float:streamdistance = 100.0, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  159. native CreateDynamicCPEx(Float:x, Float:y, Float:z, Float:size, Float:streamdistance = 100.0, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  160. native CreateDynamicRaceCPEx(type, Float:x, Float:y, Float:z, Float:nextx, Float:nexty, Float:nextz, Float:size, Float:streamdistance = 100.0, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  161. native CreateDynamicMapIconEx(Float:x, Float:y, Float:z, type, color, style = MAPICON_LOCAL, Float:streamdistance = 100.0, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  162. native Text3D:CreateDynamic3DTextLabelEx(const text[], color, Float:x, Float:y, Float:z, Float:drawdistance, attachedplayer = INVALID_PLAYER_ID, attachedvehicle = INVALID_VEHICLE_ID, testlos = 0, Float:streamdistance = 100.0, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  163. native CreateDynamicCircleEx(Float:x, Float:y, Float:size, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  164. native CreateDynamicRectangleEx(Float:minx, Float:miny, Float:maxx, Float:maxy, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  165. native CreateDynamicSphereEx(Float:x, Float:y, Float:z, Float:size, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  166. native CreateDynamicCubeEx(Float:minx, Float:miny, Float:minz, Float:maxx, Float:maxy, Float:maxz, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  167. native CreateDynamicPolygonEx(Float:points[], Float:minz = -FLOAT_INFINITY, Float:maxz = FLOAT_INFINITY, maxpoints = sizeof points, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players);
  168. // Internal Natives
  169. native Streamer_CallbackHook(callback, ...);
  170. // Callbacks
  171. forward OnDynamicObjectMoved(objectid);
  172. forward OnPlayerPickUpDynamicPickup(playerid, pickupid);
  173. forward OnPlayerEnterDynamicCP(playerid, checkpointid);
  174. forward OnPlayerLeaveDynamicCP(playerid, checkpointid);
  175. forward OnPlayerEnterDynamicRaceCP(playerid, checkpointid);
  176. forward OnPlayerLeaveDynamicRaceCP(playerid, checkpointid);
  177. forward OnPlayerEnterDynamicArea(playerid, areaid);
  178. forward OnPlayerLeaveDynamicArea(playerid, areaid);
  179. // Callback Hook Section
  180. #define STREAMER_OPC (0)
  181. #define STREAMER_OPDC (1)
  182. #define STREAMER_OPPP (2)
  183. #define STREAMER_OPEC (3)
  184. #define STREAMER_OPLC (4)
  185. #define STREAMER_OPERC (5)
  186. #define STREAMER_OPLRC (6)
  187. static bool:Streamer_g_OPC = false;
  188. static bool:Streamer_g_OPDC = false;
  189. static bool:Streamer_g_OPPP = false;
  190. static bool:Streamer_g_OPEC = false;
  191. static bool:Streamer_g_OPLC = false;
  192. static bool:Streamer_g_OPERC = false;
  193. static bool:Streamer_g_OPLRC = false;
  194. public OnFilterScriptInit()
  195. {
  196. Streamer_g_OPC = funcidx("Streamer_OnPlayerConnect") != -1;
  197. Streamer_g_OPDC = funcidx("Streamer_OnPlayerDisconnect") != -1;
  198. Streamer_g_OPPP = funcidx("Streamer_OnPlayerPickUpPickup") != -1;
  199. Streamer_g_OPEC = funcidx("Streamer_OnPlayerEnterCP") != -1;
  200. Streamer_g_OPLC = funcidx("Streamer_OnPlayerLeaveCP") != -1;
  201. Streamer_g_OPERC = funcidx("Streamer_OnPlayerEnterRaceCP") != -1;
  202. Streamer_g_OPLRC = funcidx("Streamer_OnPlayerLeaveRaceCP") != -1;
  203. if (funcidx("Streamer_OnFilterScriptInit") != -1)
  204. {
  205. return CallLocalFunction("Streamer_OnFilterScriptInit", "");
  206. }
  207. return 1;
  208. }
  209. #if defined _ALS_OnFilterScriptInit
  210. #undef OnFilterScriptInit
  211. #else
  212. #define _ALS_OnFilterScriptInit
  213. #endif
  214. #define OnFilterScriptInit Streamer_OnFilterScriptInit
  215. forward Streamer_OnFilterScriptInit();
  216. public OnGameModeInit()
  217. {
  218. Streamer_g_OPC = funcidx("Streamer_OnPlayerConnect") != -1;
  219. Streamer_g_OPDC = funcidx("Streamer_OnPlayerDisconnect") != -1;
  220. Streamer_g_OPPP = funcidx("Streamer_OnPlayerPickUpPickup") != -1;
  221. Streamer_g_OPEC = funcidx("Streamer_OnPlayerEnterCP") != -1;
  222. Streamer_g_OPLC = funcidx("Streamer_OnPlayerLeaveCP") != -1;
  223. Streamer_g_OPERC = funcidx("Streamer_OnPlayerEnterRaceCP") != -1;
  224. Streamer_g_OPLRC = funcidx("Streamer_OnPlayerLeaveRaceCP") != -1;
  225. if (funcidx("Streamer_OnGameModeInit") != -1)
  226. {
  227. return CallLocalFunction("Streamer_OnGameModeInit", "");
  228. }
  229. return 1;
  230. }
  231. #if defined _ALS_OnGameModeInit
  232. #undef OnGameModeInit
  233. #else
  234. #define _ALS_OnGameModeInit
  235. #endif
  236. #define OnGameModeInit Streamer_OnGameModeInit
  237. forward Streamer_OnGameModeInit();
  238. public OnPlayerConnect(playerid)
  239. {
  240. if (!IsPlayerNPC(playerid))
  241. {
  242. Streamer_CallbackHook(STREAMER_OPC, playerid);
  243. }
  244. if (Streamer_g_OPC)
  245. {
  246. return CallLocalFunction("Streamer_OnPlayerConnect", "d", playerid);
  247. }
  248. return 1;
  249. }
  250. #if defined _ALS_OnPlayerConnect
  251. #undef OnPlayerConnect
  252. #else
  253. #define _ALS_OnPlayerConnect
  254. #endif
  255. #define OnPlayerConnect Streamer_OnPlayerConnect
  256. forward Streamer_OnPlayerConnect(playerid);
  257. public OnPlayerDisconnect(playerid, reason)
  258. {
  259. if (!IsPlayerNPC(playerid))
  260. {
  261. Streamer_CallbackHook(STREAMER_OPDC, playerid, reason);
  262. }
  263. if (Streamer_g_OPDC)
  264. {
  265. return CallLocalFunction("Streamer_OnPlayerDisconnect", "dd", playerid, reason);
  266. }
  267. return 1;
  268. }
  269. #if defined _ALS_OnPlayerDisconnect
  270. #undef OnPlayerDisconnect
  271. #else
  272. #define _ALS_OnPlayerDisconnect
  273. #endif
  274. #define OnPlayerDisconnect Streamer_OnPlayerDisconnect
  275. forward Streamer_OnPlayerDisconnect(playerid, reason);
  276. public OnPlayerPickUpPickup(playerid, pickupid)
  277. {
  278. if (!IsPlayerNPC(playerid))
  279. {
  280. Streamer_CallbackHook(STREAMER_OPPP, playerid, pickupid);
  281. }
  282. if (Streamer_g_OPPP)
  283. {
  284. return CallLocalFunction("Streamer_OnPlayerPickUpPickup", "dd", playerid, pickupid);
  285. }
  286. return 1;
  287. }
  288. #if defined _ALS_OnPlayerPickUpPickup
  289. #undef OnPlayerPickUpPickup
  290. #else
  291. #define _ALS_OnPlayerPickUpPickup
  292. #endif
  293. #define OnPlayerPickUpPickup Streamer_OnPlayerPickUpPickup
  294. forward Streamer_OnPlayerPickUpPickup(playerid, pickupid);
  295. public OnPlayerEnterCheckpoint(playerid)
  296. {
  297. if (!IsPlayerNPC(playerid))
  298. {
  299. Streamer_CallbackHook(STREAMER_OPEC, playerid);
  300. }
  301. if (Streamer_g_OPEC)
  302. {
  303. return CallLocalFunction("Streamer_OnPlayerEnterCP", "d", playerid);
  304. }
  305. return 1;
  306. }
  307. #if defined _ALS_OnPlayerEnterCheckpoint
  308. #undef OnPlayerEnterCheckpoint
  309. #else
  310. #define _ALS_OnPlayerEnterCheckpoint
  311. #endif
  312. #define OnPlayerEnterCheckpoint Streamer_OnPlayerEnterCP
  313. forward Streamer_OnPlayerEnterCP(playerid);
  314. public OnPlayerLeaveCheckpoint(playerid)
  315. {
  316. if (!IsPlayerNPC(playerid))
  317. {
  318. Streamer_CallbackHook(STREAMER_OPLC, playerid);
  319. }
  320. if (Streamer_g_OPLC)
  321. {
  322. return CallLocalFunction("Streamer_OnPlayerLeaveCP", "d", playerid);
  323. }
  324. return 1;
  325. }
  326. #if defined _ALS_OnPlayerLeaveCheckpoint
  327. #undef OnPlayerLeaveCheckpoint
  328. #else
  329. #define _ALS_OnPlayerLeaveCheckpoint
  330. #endif
  331. #define OnPlayerLeaveCheckpoint Streamer_OnPlayerLeaveCP
  332. forward Streamer_OnPlayerLeaveCP(playerid);
  333. public OnPlayerEnterRaceCheckpoint(playerid)
  334. {
  335. if (!IsPlayerNPC(playerid))
  336. {
  337. Streamer_CallbackHook(STREAMER_OPERC, playerid);
  338. }
  339. if (Streamer_g_OPERC)
  340. {
  341. return CallLocalFunction("Streamer_OnPlayerEnterRaceCP", "d", playerid);
  342. }
  343. return 1;
  344. }
  345. #if defined _ALS_OnPlayerEnterRaceCP
  346. #undef OnPlayerEnterRaceCheckpoint
  347. #else
  348. #define _ALS_OnPlayerEnterRaceCP
  349. #endif
  350. #define OnPlayerEnterRaceCheckpoint Streamer_OnPlayerEnterRaceCP
  351. forward Streamer_OnPlayerEnterRaceCP(playerid);
  352. public OnPlayerLeaveRaceCheckpoint(playerid)
  353. {
  354. if (!IsPlayerNPC(playerid))
  355. {
  356. Streamer_CallbackHook(STREAMER_OPLRC, playerid);
  357. }
  358. if (Streamer_g_OPLRC)
  359. {
  360. return CallLocalFunction("Streamer_OnPlayerLeaveRaceCP", "d", playerid);
  361. }
  362. return 1;
  363. }
  364. #if defined _ALS_OnPlayerLeaveRaceCP
  365. #undef OnPlayerLeaveRaceCheckpoint
  366. #else
  367. #define _ALS_OnPlayerLeaveRaceCP
  368. #endif
  369. #define OnPlayerLeaveRaceCheckpoint Streamer_OnPlayerLeaveRaceCP
  370. forward Streamer_OnPlayerLeaveRaceCP(playerid);