1
0

y_zonepulse.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*----------------------------------------------------------------------------*\
  2. ===========================
  3. Gang Zone colour pulsing.
  4. ===========================
  5. Description:
  6. Gradually fades a zone's colour between one colour and another, then back.
  7. Legal:
  8. Version: MPL 1.1
  9. The contents of this file are subject to the Mozilla Public License Version
  10. 1.1 (the "License"); you may not use this file except in compliance with
  11. the License. You may obtain a copy of the License at
  12. http://www.mozilla.org/MPL/
  13. Software distributed under the License is distributed on an "AS IS" basis,
  14. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  15. for the specific language governing rights and limitations under the
  16. License.
  17. The Original Code is the YSI foreach include.
  18. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  19. Portions created by the Initial Developer are Copyright (C) 2011
  20. the Initial Developer. All Rights Reserved.
  21. Contributors:
  22. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  23. Thanks:
  24. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  25. ZeeX - Very productive conversations.
  26. koolk - IsPlayerinAreaEx code.
  27. TheAlpha - Danish translation.
  28. breadfish - German translation.
  29. Fireburn - Dutch translation.
  30. yom - French translation.
  31. 50p - Polish translation.
  32. Zamaroht - Spanish translation.
  33. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  34. for me to strive to better.
  35. Pixels^ - Running XScripters where the idea was born.
  36. Matite - Pestering me to release it and using it.
  37. Very special thanks to:
  38. Thiadmer - PAWN, whose limits continue to amaze me!
  39. Kye/Kalcor - SA:MP.
  40. SA:MP Team past, present and future - SA:MP.
  41. Version:
  42. 0.1
  43. Changelog:
  44. 19/02/12:
  45. First version.
  46. Functions:
  47. Public:
  48. __GangZonePulse - The timer that does the hard work.
  49. Core:
  50. -
  51. Stock:
  52. GangZonePulse - Pulse a zone for player or collection of players.
  53. GangZonePulseForPlayer - Pulse a zone for a player.
  54. GangZonePulseForAll - Pulse a zone for everyone.
  55. GangZoneStopPulse - Stop a zone pulsing for a set of players.
  56. GangZoneStopPulseForPlayer - Stop a zone pulsing for a single player.
  57. GangZoneStopPulseForAll - Stop a zone pulsing for everyone.
  58. Static:
  59. -
  60. Inline:
  61. -
  62. API:
  63. -
  64. Callbacks:
  65. -
  66. Hooks:
  67. -
  68. Definitions:
  69. -
  70. Enums:
  71. -
  72. Macros:
  73. -
  74. Keywords:
  75. -
  76. Tags:
  77. -
  78. Variables:
  79. Global:
  80. -
  81. Static:
  82. -
  83. Commands:
  84. -
  85. Compile options:
  86. ZONE_PULSE_STAGE_TIME - ms between each pulse frame.
  87. Operators:
  88. -
  89. Iterators:
  90. -
  91. \*----------------------------------------------------------------------------*/
  92. /*
  93. native GangZonePulse(@PlayerSet:ps, zone, from, to, time, delay = ZONE_PULSE_STAGE_TIME);
  94. native GangZonePulseForPlayer(playerid, zone, from, to, time, delay = ZONE_PULSE_STAGE_TIME);
  95. native GangZonePulseForAll(zone, from, to, time, delay = ZONE_PULSE_STAGE_TIME);
  96. native GangZoneStopPulse(@PlayerSet:ps, zone);
  97. native GangZoneStopPulseForPlayer(playerid, zone);
  98. native GangZoneStopPulseForAll(zone);
  99. */
  100. #include <a_samp>
  101. #include "internal\y_version"
  102. #include "y_playerset"
  103. #include "y_iterate"
  104. #include "y_debug"
  105. #if !defined ZONE_PULSE_STAGE_TIME
  106. #define ZONE_PULSE_STAGE_TIME (50)
  107. #endif
  108. //task DoPulse1
  109. forward __GangZonePulse(playerid, zone, from, to, time, stage, delay, time2, delay2);
  110. public __GangZonePulse(playerid, zone, from, to, time, stage, delay, time2, delay2)
  111. {
  112. if (!IsPlayerConnected(playerid))
  113. {
  114. return;
  115. }
  116. static
  117. sTimer[32];
  118. format(sTimer, sizeof (sTimer), "y_zonepulse_%d", zone);
  119. stage = (stage + 1) % (time + time2);
  120. if (stage == time)
  121. {
  122. GangZoneShowForPlayer(playerid, zone, to);
  123. SetPVarInt(playerid, sTimer, SetTimerEx("__GangZonePulse", delay, 0, "iiiiiiiii", playerid, zone, from, to, time, stage, delay, time2, delay2));
  124. return;
  125. }
  126. else if (stage == 0)
  127. {
  128. GangZoneShowForPlayer(playerid, zone, from);
  129. SetPVarInt(playerid, sTimer, SetTimerEx("__GangZonePulse", delay2, 0, "iiiiiiiii", playerid, zone, from, to, time, 0, delay, time2, delay2));
  130. return;
  131. }
  132. if (stage > time)
  133. {
  134. // Fade back
  135. new
  136. multiplier = (time2 - (stage - time2)),
  137. r = ((to >>> 24) - (from >>> 24)) * multiplier / time2 + (from >>> 24),
  138. g = ((to >>> 16 & 0xFF) - (from >>> 16 & 0xFF)) * multiplier / time2 + (from >>> 16 & 0xFF),
  139. b = ((to >>> 8 & 0xFF) - (from >>> 8 & 0xFF)) * multiplier / time2 + (from >>> 8 & 0xFF),
  140. a = ((to & 0xFF) - (from & 0xFF)) * multiplier / time2 + (from & 0xFF);
  141. P:7("__GangZonePulse: %d %d %x %x %x %x", playerid, zone, r & 0xFF, g & 0xFF, b & 0xFF, a & 0xFF);
  142. GangZoneShowForPlayer(playerid, zone, (r << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | (a & 0xFF));
  143. SetPVarInt(playerid, sTimer, SetTimerEx("__GangZonePulse", ZONE_PULSE_STAGE_TIME, 0, "iiiiiiiii", playerid, zone, from, to, time, stage, delay, time2, delay2));
  144. }
  145. else
  146. {
  147. // Fade there.
  148. new
  149. r = ((to >>> 24) - (from >>> 24)) * stage / time + (from >>> 24),
  150. g = ((to >>> 16 & 0xFF) - (from >>> 16 & 0xFF)) * stage / time + (from >>> 16 & 0xFF),
  151. b = ((to >>> 8 & 0xFF) - (from >>> 8 & 0xFF)) * stage / time + (from >>> 8 & 0xFF),
  152. a = ((to & 0xFF) - (from & 0xFF)) * stage / time + (from & 0xFF);
  153. P:7("__GangZonePulse: %d %d %x %x %x %x", playerid, zone, r & 0xFF, g & 0xFF, b & 0xFF, a & 0xFF);
  154. GangZoneShowForPlayer(playerid, zone, (r << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | (a & 0xFF));
  155. SetPVarInt(playerid, sTimer, SetTimerEx("__GangZonePulse", ZONE_PULSE_STAGE_TIME, 0, "iiiiiiiii", playerid, zone, from, to, time, stage, delay, time2, delay2));
  156. }
  157. return;
  158. }
  159. stock _GangZonePulse(@PlayerSet:ps, zone, from, to, time, delay = ZONE_PULSE_STAGE_TIME, time2 = -1, delay2 = -1)
  160. {
  161. static
  162. sTimer[32];
  163. format(sTimer, sizeof (sTimer), "y_zonepulse_%d", zone);
  164. if (time2 == -1)
  165. {
  166. time2 = time;
  167. }
  168. if (delay2 == -1)
  169. {
  170. delay2 = delay;
  171. }
  172. foreach (new p : PS(ps))
  173. {
  174. KillTimer(GetPVarInt(p, sTimer));
  175. GangZoneShowForPlayer(p, zone, from);
  176. SetPVarInt(p, sTimer, SetTimerEx("__GangZonePulse", delay, 0, "iiiiiiiii", p, zone, from, to, time / ZONE_PULSE_STAGE_TIME, 0, delay, time2 / ZONE_PULSE_STAGE_TIME, delay2));
  177. }
  178. }
  179. #define GangZonePulse(%0) PSF:_GangZonePulse(%0)
  180. #define GangZonePulseForPlayer(%0) PSF:_GangZonePulse(%0)
  181. #define GangZonePulseForAll(%0) PSF:_GangZonePulse(ALL_PLAYERS,%0)
  182. stock _GangZoneStopPulse(@PlayerSet:ps, zone)
  183. {
  184. static
  185. sTimer[32];
  186. format(sTimer, sizeof (sTimer), "y_zonepulse_%d", zone);
  187. foreach (new p : PS(ps))
  188. {
  189. KillTimer(GetPVarInt(p, sTimer));
  190. }
  191. }
  192. #define GangZoneStopPulse(%0) PSF:_GangZoneStopPulse(%0)
  193. #define GangZoneStopPulseForPlayer(%0) PSF:_GangZoneStopPulse(%0)
  194. #define GangZoneStopPulseForAll(%0) PSF:_GangZoneStopPulse(ALL_PLAYERS,%0)