Guest User

Untitled

a guest
Nov 19th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. ///////////////////////////////////////
  2. ///////////Made by Joe Staff///////////
  3. ///////////////////////////////////////
  4.  
  5. #include <a_samp>
  6. #define _UPDATERATE 100 //milliseconds
  7. forward _UpdateFadeTimer();
  8. forward OnFadeComplete(playerid,beforehold);
  9. new _pEndColor[MAX_PLAYERS][4];
  10. new _pCurrentColor[MAX_PLAYERS][4];
  11. new _pRateColor[MAX_PLAYERS][4];
  12. new _pStep[MAX_PLAYERS];
  13. new _pHold[MAX_PLAYERS];
  14. new _OPArray[MAX_PLAYERS];
  15. new _OnlinePlayers;
  16. new Text:_text; //Look, only one!
  17.  
  18. /*
  19. native ConvertToColor(RR,GG,BB,AA);
  20. native StopPlayerFade(playerid);
  21. native FadeColorForPlayer(playerid,RR1,GG1,BB1,AA1,RR2,GG2,BB2,AA2,steps,hold);
  22. native FadeInit();
  23. native FadeExit();
  24. native FadePlayerConnect(playerid);
  25. native FadePlayerDisonnect(playerid);
  26. */
  27.  
  28.  
  29.  
  30. stock ConvertToColor(RR,GG,BB,AA)return (RR*16777216)+(GG*65536)+(BB*256)+AA;
  31. stock _UpdateOPA(playerid=INVALID_PLAYER_ID) //my version of foreach (I made it before Y_Less did! publicly anyway)
  32. {
  33. _OnlinePlayers=0;
  34. for(new ply;ply<MAX_PLAYERS;ply++)
  35. {
  36. if(IsPlayerConnected(ply)&&(ply!=playerid))
  37. {
  38. _OPArray[_OnlinePlayers]=ply;
  39. _OnlinePlayers++;
  40. }
  41. }
  42. }
  43. stock FadeColorForPlayer(playerid,RR1,GG1,BB1,AA1,RR2,GG2,BB2,AA2,steps,hold)
  44. {
  45. _pStep[playerid]=steps;//countdown, sorta
  46. new tmpsteps; //This will have to be added to incase the math is messed up (programming annoyance)
  47. _pHold[playerid]=hold;//How long the last color is held before disappearing (Divide this by UPDATERATE to get the time Ex:hold=10, in milliseconds that's 1000)
  48. _pEndColor[playerid][0]=RR2;
  49. _pEndColor[playerid][1]=GG2;
  50. _pEndColor[playerid][2]=BB2;
  51. _pEndColor[playerid][3]=AA2;
  52. _pCurrentColor[playerid][0]=RR1;
  53. _pCurrentColor[playerid][1]=GG1;
  54. _pCurrentColor[playerid][2]=BB1;
  55. _pCurrentColor[playerid][3]=AA1;
  56. _pRateColor[playerid][0]=(RR1-RR2)/steps;
  57. _pRateColor[playerid][1]=(GG1-GG2)/steps;
  58. _pRateColor[playerid][2]=(BB1-BB2)/steps;
  59. _pRateColor[playerid][3]=(AA1-AA2)/steps;
  60. //No dividing by 0!
  61. if(_pRateColor[playerid][0]!=0)if(((RR1-RR2)/_pRateColor[playerid][0])>steps)tmpsteps=((RR1-RR2)/_pRateColor[playerid][0])-steps;
  62. if(_pRateColor[playerid][1]!=0)if(((GG1-GG2)/_pRateColor[playerid][1])>steps+tmpsteps)tmpsteps=((GG1-GG2)/_pRateColor[playerid][1])-steps;
  63. if(_pRateColor[playerid][2]!=0)if(((BB1-BB2)/_pRateColor[playerid][2])>steps+tmpsteps)tmpsteps=((BB1-BB2)/_pRateColor[playerid][2])-steps;
  64. if(_pRateColor[playerid][3]!=0)if(((AA1-AA2)/_pRateColor[playerid][3])>steps+tmpsteps)tmpsteps=((AA1-AA2)/_pRateColor[playerid][3])-steps;
  65. if(tmpsteps)_pStep[playerid]+=tmpsteps;
  66. }
  67. FadeInit()
  68. {
  69. _text=TextDrawCreate(0.0,0.0,"~r~");
  70. TextDrawTextSize(_text,640,480);
  71. TextDrawLetterSize(_text,0.0,50.0);
  72. TextDrawUseBox(_text,1);
  73. SetTimer("_UpdateFadeTimer",_UPDATERATE,1);
  74. _UpdateOPA();
  75. return 1;
  76. }
  77. FadeExit()
  78. {
  79. TextDrawDestroy(_text);
  80. return 1;
  81. }
  82. FadePlayerConnect(playerid)
  83. {
  84. _UpdateOPA();
  85. _pHold[playerid]=-1;
  86. _pStep[playerid]=-1;
  87. return 1;
  88. }
  89. FadePlayerDisconnect(playerid)
  90. {
  91. _UpdateOPA(playerid);
  92. return 1;
  93. }
  94. stock StopPlayerFade(playerid)
  95. {
  96. _pStep[playerid]=0;
  97. _pHold[playerid]=0;
  98. }
  99. public _UpdateFadeTimer()
  100. {
  101. new playerid;
  102. for(new opa;opa<_OnlinePlayers;opa++)
  103. {
  104. playerid=_OPArray[opa];
  105. if(_pStep[playerid])
  106. {
  107. _pStep[playerid]--;
  108. for(new color;color<4;color++)
  109. {
  110. _pCurrentColor[playerid][color]-=_pRateColor[playerid][color];
  111. if(_pRateColor[playerid][color]>0)
  112. {
  113. if(_pCurrentColor[playerid][color]<_pEndColor[playerid][color])_pCurrentColor[playerid][color]=_pEndColor[playerid][color];
  114. }
  115. if(_pRateColor[playerid][color]<0)
  116. {
  117. if(_pCurrentColor[playerid][color]>_pEndColor[playerid][color])_pCurrentColor[playerid][color]=_pEndColor[playerid][color];
  118. }
  119. if(_pCurrentColor[playerid][color]<0)_pCurrentColor[playerid][color]=0;
  120. if(_pCurrentColor[playerid][color]>255)_pCurrentColor[playerid][color]=255;
  121. }
  122. TextDrawBoxColor(_text,ConvertToColor(_pCurrentColor[playerid][0],_pCurrentColor[playerid][1],_pCurrentColor[playerid][2],_pCurrentColor[playerid][3]));
  123. TextDrawShowForPlayer(playerid,_text);
  124. }
  125. else if(_pStep[playerid]==0)
  126. {
  127. _pStep[playerid]=-1;
  128. CallLocalFunction("OnFadeComplete","ii",playerid,1);
  129. }
  130. else if(_pHold[playerid])
  131. {
  132. _pHold[playerid]--;
  133. }
  134. else if(_pHold[playerid]==0)
  135. {
  136. _pHold[playerid]=-1;
  137. TextDrawHideForPlayer(playerid,_text);
  138. CallLocalFunction("OnFadeComplete","ii",playerid,0);
  139. }
  140. }
  141. }
Add Comment
Please, Sign In to add comment