Seifader.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. Seifader - SA-MP screen fader by Seif v2.0
  3. Made YSI compatible by Cyber_Punk.....
  4. *-----------------------------------------------*
  5. | This include allows you to fade players' |
  6. | screens from a color or to a color. Also, |
  7. | it calls a callback when the fading finishes |
  8. | so you can do whatever when the fading ends. |
  9. | 'OnPlayerScreenFade & OnPlayerScreenColorFade'|
  10. *-----------------------------------------------*
  11. */
  12. /*x---------------------------------Important-------------------------------------x*/
  13. //**INCLUDES**//
  14. #include <a_samp>
  15. //**PRAGMAS**//
  16. //**MISC**//
  17. //#define function%0(%1) forward%0(%1); public%0(%1) //This one macro caused pawncc to hang, it worked on a blank gm yet not with YSI included....
  18. /*
  19. On a hunch I commented it out, I got an instant compiler crash.
  20. I manually declared all the publics and forwards, now everything works fine.
  21. Not sure why it was needed it saved on what 6 to 9 lines of code >.<
  22. */
  23. #if defined MAX_PLAYERS
  24. #undef MAX_PLAYERS
  25. #define MAX_PLAYERS 100 // CHANGE IT TO YOUR PLAYER SLOTS IN YOUR SERVER
  26. #endif
  27. /*x---------------------------------Defining-------------------------------------x*/
  28. //**COLORS*//
  29. //Some colors I made
  30. /*#define GREEN 0x21DD00FF
  31. #define RED 0xE60000FF
  32. #define ADMIN_RED 0xFB0000FF
  33. #define YELLOW 0xFFFF00FF
  34. #define ORANGE 0xF97804FF
  35. #define LIGHTRED 0xFF8080FF
  36. #define LIGHTBLUE 0x00C2ECFF
  37. #define PURPLE 0xB360FDFF
  38. #define BLUE 0x1229FAFF
  39. #define LIGHTGREEN 0x38FF06FF
  40. #define DARKPINK 0xE100E1FF
  41. #define DARKGREEN 0x008040FF
  42. #define ANNOUNCEMENT 0x6AF7E1FF
  43. #define GREY 0xCECECEFF
  44. #define PINK 0xD52DFFFF
  45. #define DARKGREY 0x626262FF
  46. #define AQUAGREEN 0x03D687FF
  47. #define WHITE 0xFFFFFFFF*/
  48. //**MISC**//
  49. #define MAX_FADES 5 // max fades that a player can have at the same time.
  50. //**VARIABLES**//
  51. new colorfade[MAX_PLAYERS][MAX_FADES];
  52. new FadeAvailability[MAX_PLAYERS][MAX_FADES];
  53. new Text:PlayerFadeText[MAX_PLAYERS][MAX_FADES];
  54. new bool:FlashFade[MAX_PLAYERS][MAX_FADES];
  55. new FlashFadeTimes[MAX_PLAYERS][MAX_FADES];
  56. // **FORWARDS** //
  57. forward OnPlayerScreenFade(playerid, color, speed);
  58. forward OnPlayerScreenColorFade(playerid, color, speed);
  59. forward OnPlayerFadeFlashed(playerid, color, speed);
  60. // **NATIVES** //
  61. /*
  62. native Seifader_OnExit();
  63. native RemovePlayerColorFade(playerid);
  64. native FadePlayerScreen(playerid, color, speed);
  65. native FadePlayerScreenToColor(playerid, color, speed);
  66. native FlashPlayerScreen(playerid, color, speed, times);
  67. native IsValidPlayerFade(playerid, fadeid);
  68. */
  69. /*x---------------------------------Functions-------------------------------------x*/
  70. /*
  71. ---[FadePlayerScreen]---
  72. »playerid: the target
  73. »color: the color you want his screen to fade from
  74. »speed: from 1-255 where 255 is the fastest(instant)
  75. »wipe_other_colorfades: (optional) we want no bug to occur, so this will make sure there's
  76. no other fade that could've messed with it and thus maybe causing
  77. a player's screen to be stuck at a color. It's random but you always
  78. want to prevent it. I've fully tested this include and rarely
  79. encountered that issue. Unfortunately, nothing is bug-free.
  80. *Return: id of the fade
  81. *-----------------------------------------------*
  82. | Fades the player's screen from a color. |
  83. *-----------------------------------------------*
  84. */
  85. stock FadePlayerScreen(playerid, color, speed, bool:wipe_other_colorfades = true)
  86. {
  87. if (wipe_other_colorfades == true) RemovePlayerColorFade(playerid);
  88. new fadeid = FindFadeID(playerid);
  89. new maxalpha = GetAlpha(color);
  90. PlayerFadeText[playerid][fadeid] = TextDrawCreate(0.0, 0.0, "_");
  91. TextDrawFont(PlayerFadeText[playerid][fadeid], 1);
  92. TextDrawLetterSize(PlayerFadeText[playerid][fadeid], 0.0, 50.0);
  93. TextDrawUseBox(PlayerFadeText[playerid][fadeid], true);
  94. TextDrawColor(PlayerFadeText[playerid][fadeid], 0);
  95. colorfade[playerid][fadeid] = color;
  96. TextDrawBoxColor(PlayerFadeText[playerid][fadeid], color);
  97. TextDrawShowForPlayer(playerid, PlayerFadeText[playerid][fadeid]);
  98. FadeAvailability[playerid][fadeid] = 1;
  99. FlashFade[playerid][fadeid] = false;
  100. SetTimerEx("ScreenFade", 100, 0, "ddddd", playerid, color, speed, maxalpha, fadeid);
  101. return fadeid;
  102. }
  103. /*
  104. ---[FadePlayerScreenToColor]---
  105. »playerid: the target
  106. »color: the color you want his screen to fade TO
  107. »speed: from 1-255 where 255 is the fastest(instant)
  108. *Return: id of the fade
  109. *-----------------------------------------------*
  110. | Fades the player's screen to a color. |
  111. *-----------------------------------------------*
  112. */
  113. forward FadePlayerScreenToColor(playerid, color, speed);
  114. public FadePlayerScreenToColor(playerid, color, speed)
  115. {
  116. new fadeid = FindFadeID(playerid);
  117. new maxalpha = GetAlpha(color);
  118. PlayerFadeText[playerid][fadeid] = TextDrawCreate(0.0, 0.0, "_");
  119. TextDrawFont(PlayerFadeText[playerid][fadeid], 1);
  120. TextDrawLetterSize(PlayerFadeText[playerid][fadeid], 0.0, 50.0);
  121. TextDrawUseBox(PlayerFadeText[playerid][fadeid], true);
  122. TextDrawColor(PlayerFadeText[playerid][fadeid], 0);
  123. color -= maxalpha;
  124. colorfade[playerid][fadeid] = color;
  125. TextDrawBoxColor(PlayerFadeText[playerid][fadeid], color);
  126. TextDrawShowForPlayer(playerid, PlayerFadeText[playerid][fadeid]);
  127. FadeAvailability[playerid][fadeid] = 1;
  128. FlashFade[playerid][fadeid] = false;
  129. SetTimerEx("ScreenFadeColor", 100, 0, "ddddd", playerid, color, speed, maxalpha, fadeid);
  130. return fadeid;
  131. }
  132. /*
  133. ---[FlashPlayerScreen]---
  134. »playerid: the target
  135. »color: the color you want his screen to flash to
  136. »speed: from 1-255 where 1 is the fastest(instant)
  137. »times: amount of flashes
  138. *Return: id of the fade
  139. *-----------------------------------------------*
  140. | Flashes the player's screen. Basically, this |
  141. | is a mix of FadePlayerScreen and ToColor |
  142. | together to make your screen flash. |
  143. *-----------------------------------------------*
  144. */
  145. forward FlashPlayerScreen(playerid, color, speed, times);
  146. public FlashPlayerScreen(playerid, color, speed, times)
  147. {
  148. new fadeid = FindFadeID(playerid);
  149. new maxalpha = GetAlpha(color);
  150. PlayerFadeText[playerid][fadeid] = TextDrawCreate(0.0, 0.0, "_");
  151. TextDrawFont(PlayerFadeText[playerid][fadeid], 1);
  152. TextDrawLetterSize(PlayerFadeText[playerid][fadeid], 0.0, 50.0);
  153. TextDrawUseBox(PlayerFadeText[playerid][fadeid], true);
  154. TextDrawColor(PlayerFadeText[playerid][fadeid], 0);
  155. color -= maxalpha;
  156. colorfade[playerid][fadeid] = color;
  157. TextDrawBoxColor(PlayerFadeText[playerid][fadeid], color);
  158. TextDrawShowForPlayer(playerid, PlayerFadeText[playerid][fadeid]);
  159. FadeAvailability[playerid][fadeid] = 1;
  160. FlashFade[playerid][fadeid] = true;
  161. FlashFadeTimes[playerid][fadeid] = times;
  162. SetTimerEx("ScreenFadeColor", 100, 0, "ddddd", playerid, color, speed, maxalpha, fadeid);
  163. return fadeid;
  164. }
  165. /*
  166. ---[RemovePlayerColorFade]---
  167. »playerid: the target
  168. *-----------------------------------------------*
  169. | Removes every fade made to a player. |
  170. *-----------------------------------------------*
  171. */
  172. forward RemovePlayerColorFade(playerid);
  173. public RemovePlayerColorFade(playerid) // This function is used to erase every fade made for the player. Should be used before FadePlayerScreen to make sure there's no bug
  174. {
  175. for(new i; i < MAX_FADES; i++)
  176. {
  177. TextDrawDestroy(PlayerFadeText[playerid][i]);
  178. FadeAvailability[playerid][i] = 0;
  179. FlashFade[playerid][i] = false;
  180. FlashFadeTimes[playerid][i] = 0;
  181. }
  182. }
  183. /*
  184. ---[IsValidPlayerFade]---
  185. »playerid: the target
  186. »fadeid: the fade id you want to check
  187. *Return: 1 if valid, 0 if invalid
  188. *-----------------------------------------------*
  189. | Checks if the fade id is valid, meaning |
  190. | if it's being used by the player or not. |
  191. *-----------------------------------------------*
  192. */
  193. forward IsValidPlayerFade(playerid, fadeid);
  194. public IsValidPlayerFade(playerid, fadeid) return FadeAvailability[playerid][fadeid];
  195. //------------------------------------------------: Script functions :---------------------------------------------------//
  196. Seifader_OnExit()
  197. {
  198. for(new all, m = GetMaxPlayers(); all < m; all++)
  199. {
  200. if (IsPlayerNPC(all) || !IsPlayerConnected(all)) continue;
  201. for(new f; f < MAX_FADES; f++)
  202. {
  203. TextDrawDestroy(PlayerFadeText[all][f]);
  204. FadeAvailability[all][f] = 0;
  205. FlashFade[all][f] = false;
  206. FlashFadeTimes[all][f] = 0;
  207. }
  208. }
  209. }
  210. forward ScreenFade(playerid, color, speed, maxalpha, fadeid);
  211. public ScreenFade(playerid, color, speed, maxalpha, fadeid)
  212. {
  213. if (color <= (colorfade[playerid][fadeid] - maxalpha))
  214. {
  215. FADECOLOR_FINISH:
  216. TextDrawDestroy(PlayerFadeText[playerid][fadeid]);
  217. OnPlayerScreenFade(playerid, color, speed);
  218. FadeAvailability[playerid][fadeid] = 0;
  219. }
  220. else
  221. {
  222. if (!FadeAvailability[playerid][fadeid]) return 1;
  223. color -= speed;
  224. if (color <= (colorfade[playerid][fadeid] - maxalpha)) goto FADECOLOR_FINISH; //color = (colorfade[playerid][fadeid] - maxalpha);
  225. TextDrawBoxColor(PlayerFadeText[playerid][fadeid], color);
  226. TextDrawShowForPlayer(playerid, PlayerFadeText[playerid][fadeid]);
  227. SetTimerEx("ScreenFade", 100, 0, "ddddd", playerid, color, speed, maxalpha, fadeid);
  228. }
  229. return 1;
  230. }
  231. forward ScreenFade_Flash(playerid, color, speed, maxalpha, fadeid);
  232. public ScreenFade_Flash(playerid, color, speed, maxalpha, fadeid)
  233. {
  234. if (color <= colorfade[playerid][fadeid])
  235. {
  236. FADECOLOR_FINISH:
  237. if (FlashFade[playerid][fadeid] == true)
  238. {
  239. if (!FlashFadeTimes[playerid][fadeid])
  240. {
  241. TextDrawDestroy(PlayerFadeText[playerid][fadeid]);
  242. OnPlayerFadeFlashed(playerid, color, speed);
  243. FadeAvailability[playerid][fadeid] = 0;
  244. return 1;
  245. }
  246. TextDrawBoxColor(PlayerFadeText[playerid][fadeid], colorfade[playerid][fadeid]);
  247. TextDrawShowForPlayer(playerid, PlayerFadeText[playerid][fadeid]);
  248. SetTimerEx("ScreenFadeColor", 100, 0, "ddddd", playerid, colorfade[playerid][fadeid], speed, maxalpha, fadeid);
  249. return 1;
  250. }
  251. TextDrawDestroy(PlayerFadeText[playerid][fadeid]);
  252. OnPlayerScreenFade(playerid, color, speed);
  253. FadeAvailability[playerid][fadeid] = 0;
  254. }
  255. else
  256. {
  257. if (!FadeAvailability[playerid][fadeid]) return 1;
  258. color -= speed;
  259. if (color <= colorfade[playerid][fadeid]) goto FADECOLOR_FINISH; //color = (colorfade[playerid][fadeid] - maxalpha);
  260. TextDrawBoxColor(PlayerFadeText[playerid][fadeid], color);
  261. TextDrawShowForPlayer(playerid, PlayerFadeText[playerid][fadeid]);
  262. SetTimerEx("ScreenFade_Flash", 100, 0, "ddddd", playerid, color, speed, maxalpha, fadeid);
  263. }
  264. return 1;
  265. }
  266. forward ScreenFadeColor(playerid, color, speed, maxalpha, fadeid);
  267. public ScreenFadeColor(playerid, color, speed, maxalpha, fadeid)
  268. {
  269. if (color >= (colorfade[playerid][fadeid] + maxalpha))
  270. {
  271. FADE_FINISH:
  272. if (FlashFade[playerid][fadeid] == true)
  273. {
  274. FlashFadeTimes[playerid][fadeid]--;
  275. TextDrawBoxColor(PlayerFadeText[playerid][fadeid], colorfade[playerid][fadeid]+maxalpha);
  276. TextDrawShowForPlayer(playerid, PlayerFadeText[playerid][fadeid]);
  277. SetTimerEx("ScreenFade_Flash", 100, 0, "ddddd", playerid, colorfade[playerid][fadeid]+maxalpha, speed, maxalpha, fadeid);
  278. return 1;
  279. }
  280. OnPlayerScreenColorFade(playerid, color, speed);
  281. FadeAvailability[playerid][fadeid] = 0;
  282. }
  283. else
  284. {
  285. if (!FadeAvailability[playerid][fadeid]) return 1;
  286. color += speed;
  287. if (color >= (colorfade[playerid][fadeid] + maxalpha)) goto FADE_FINISH;
  288. TextDrawBoxColor(PlayerFadeText[playerid][fadeid], color);
  289. TextDrawShowForPlayer(playerid, PlayerFadeText[playerid][fadeid]);
  290. SetTimerEx("ScreenFadeColor", 100, 0, "ddddd", playerid, color, speed, maxalpha, fadeid);
  291. }
  292. return 1;
  293. }
  294. forward FindFadeID(playerid);
  295. public FindFadeID(playerid)
  296. {
  297. for(new f; f < MAX_FADES; f++)
  298. {
  299. if (FadeAvailability[playerid][f] == 0)
  300. {
  301. //printf("found fade id: %d", f);
  302. return f;
  303. }
  304. }
  305. return -1;
  306. }
  307. forward GetAlpha(color);
  308. public GetAlpha(color)
  309. {
  310. return color&0xFF;
  311. }
  312. // Required in your script that uses this include, otherwise you'll get an error:
  313. /*public OnPlayerScreenFade(playerid, color, speed)
  314. {
  315. return 1;
  316. }
  317. public OnPlayerScreenColorFade(playerid, color, speed)
  318. {
  319. return 1;
  320. }
  321. public OnPlayerFadeFlashed(playerid, color, speed)
  322. {
  323. return 1;
  324. }*/