Advertisement
Guest User

Untitled

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