fade.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ///////////////////////////////////////
  2. ///////////Made by Joe Staff///////////
  3. ///////////////////////////////////////
  4. #include <a_samp>
  5. #define _UPDATERATE 100 //milliseconds
  6. #define _TELEPORTFADECOLORR 0
  7. #define _TELEPORTFADECOLORG 0
  8. #define _TELEPORTFADECOLORB 0
  9. #define _TELEPORTFADECOLORA 255
  10. forward _UpdateFadeTimer();
  11. forward OnFadeComplete(playerid,beforehold);
  12. new _pEndColor[MAX_PLAYERS][4];
  13. new _pCurrentColor[MAX_PLAYERS][4];
  14. new _pRateColor[MAX_PLAYERS][4];
  15. new _pStep[MAX_PLAYERS];
  16. new _pHold[MAX_PLAYERS];
  17. new _OPArray[MAX_PLAYERS];
  18. new _OnlinePlayers;
  19. new _PlayerTeleporting[MAX_PLAYERS];
  20. new _PlayerInterior[MAX_PLAYERS];
  21. new Float:_pTPToPos[MAX_PLAYERS][3];
  22. new _pTPSteps[MAX_PLAYERS];
  23. new Text:_text; //Look, only one!
  24. /*
  25. native ConvertToColor(RR,GG,BB,AA);
  26. native StopPlayerFade(playerid);
  27. native FadeColorForPlayer(playerid,RR1,GG1,BB1,AA1,RR2,GG2,BB2,AA2,steps,hold);
  28. native FadeInit();
  29. native FadeExit();
  30. native FadePlayerConnect(playerid);
  31. native FadePlayerDisonnect(playerid);
  32. native SetPlayerPosFade(playerid,steps,Float:x,Float:y,Float:z);
  33. */
  34. stock SetPlayerPosFade(playerid,steps,interior,Float:x,Float:y,Float:z)
  35. {
  36. _PlayerTeleporting[playerid]=1;
  37. _pTPToPos[playerid][0]=x;
  38. _pTPToPos[playerid][1]=y;
  39. _pTPToPos[playerid][2]=z;
  40. _pTPSteps[playerid]=steps;
  41. _PlayerInterior[playerid]=interior;
  42. FadeColorForPlayer(playerid,0,0,0,0,_TELEPORTFADECOLORR,_TELEPORTFADECOLORG,_TELEPORTFADECOLORB,_TELEPORTFADECOLORA,steps,1);
  43. }
  44. stock ConvertToColor(RR,GG,BB,AA)return (RR*16777216)+(GG*65536)+(BB*256)+AA;
  45. stock _UpdateOPA(playerid=INVALID_PLAYER_ID) //my version of foreach (I made it before Y_Less did! publicly anyway)
  46. {
  47. _OnlinePlayers=0;
  48. for(new ply;ply<MAX_PLAYERS;ply++)
  49. {
  50. if(IsPlayerConnected(ply)&&(ply!=playerid))
  51. {
  52. _OPArray[_OnlinePlayers]=ply;
  53. _OnlinePlayers++;
  54. }
  55. }
  56. }
  57. stock FadeColorForPlayer(playerid,RR1,GG1,BB1,AA1,RR2,GG2,BB2,AA2,steps,hold)
  58. {
  59. _pStep[playerid]=steps;//countdown, sorta
  60. new tmpsteps; //This will have to be added to incase the math is messed up (programming annoyance)
  61. _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)
  62. _pEndColor[playerid][0]=RR2;
  63. _pEndColor[playerid][1]=GG2;
  64. _pEndColor[playerid][2]=BB2;
  65. _pEndColor[playerid][3]=AA2;
  66. _pCurrentColor[playerid][0]=RR1;
  67. _pCurrentColor[playerid][1]=GG1;
  68. _pCurrentColor[playerid][2]=BB1;
  69. _pCurrentColor[playerid][3]=AA1;
  70. _pRateColor[playerid][0]=(RR1-RR2)/steps;
  71. _pRateColor[playerid][1]=(GG1-GG2)/steps;
  72. _pRateColor[playerid][2]=(BB1-BB2)/steps;
  73. _pRateColor[playerid][3]=(AA1-AA2)/steps;
  74. //No dividing by 0!
  75. if(_pRateColor[playerid][0]!=0)if(((RR1-RR2)/_pRateColor[playerid][0])>steps)tmpsteps=((RR1-RR2)/_pRateColor[playerid][0])-steps;
  76. if(_pRateColor[playerid][1]!=0)if(((GG1-GG2)/_pRateColor[playerid][1])>steps+tmpsteps)tmpsteps=((GG1-GG2)/_pRateColor[playerid][1])-steps;
  77. if(_pRateColor[playerid][2]!=0)if(((BB1-BB2)/_pRateColor[playerid][2])>steps+tmpsteps)tmpsteps=((BB1-BB2)/_pRateColor[playerid][2])-steps;
  78. if(_pRateColor[playerid][3]!=0)if(((AA1-AA2)/_pRateColor[playerid][3])>steps+tmpsteps)tmpsteps=((AA1-AA2)/_pRateColor[playerid][3])-steps;
  79. if(tmpsteps)_pStep[playerid]+=tmpsteps+1;
  80. }
  81. FadeInit()
  82. {
  83. _text=TextDrawCreate(0.0,0.0,"~r~");
  84. TextDrawTextSize(_text,640,480);
  85. TextDrawLetterSize(_text,0.0,50.0);
  86. TextDrawUseBox(_text,1);
  87. SetTimer("_UpdateFadeTimer",_UPDATERATE,1);
  88. _UpdateOPA();
  89. return 1;
  90. }
  91. FadeExit()
  92. {
  93. TextDrawDestroy(_text);
  94. return 1;
  95. }
  96. FadePlayerConnect(playerid)
  97. {
  98. _UpdateOPA();
  99. _pHold[playerid]=-1;
  100. _pStep[playerid]=-1;
  101. _PlayerTeleporting[playerid]=0;
  102. return 1;
  103. }
  104. FadePlayerDisconnect(playerid)
  105. {
  106. _UpdateOPA(playerid);
  107. return 1;
  108. }
  109. stock StopPlayerFade(playerid)
  110. {
  111. _pStep[playerid]=0;
  112. _pHold[playerid]=0;
  113. }
  114. public _UpdateFadeTimer()
  115. {
  116. new playerid;
  117. for(new opa;opa<_OnlinePlayers;opa++)
  118. {
  119. playerid=_OPArray[opa];
  120. if(_pStep[playerid])
  121. {
  122. _pStep[playerid]--;
  123. for(new color;color<4;color++)
  124. {
  125. _pCurrentColor[playerid][color]-=_pRateColor[playerid][color];
  126. if(_pRateColor[playerid][color]>0)
  127. {
  128. if(_pCurrentColor[playerid][color]<_pEndColor[playerid][color])_pCurrentColor[playerid][color]=_pEndColor[playerid][color];
  129. }
  130. if(_pRateColor[playerid][color]<0)
  131. {
  132. if(_pCurrentColor[playerid][color]>_pEndColor[playerid][color])_pCurrentColor[playerid][color]=_pEndColor[playerid][color];
  133. }
  134. if(_pCurrentColor[playerid][color]<0)_pCurrentColor[playerid][color]=0;
  135. if(_pCurrentColor[playerid][color]>255)_pCurrentColor[playerid][color]=255;
  136. }
  137. TextDrawBoxColor(_text,ConvertToColor(_pCurrentColor[playerid][0],_pCurrentColor[playerid][1],_pCurrentColor[playerid][2],_pCurrentColor[playerid][3]));
  138. TextDrawShowForPlayer(playerid,_text);
  139. }
  140. else if(_pStep[playerid]==0)
  141. {
  142. _pStep[playerid]=-1;
  143. if(_PlayerTeleporting[playerid]==1)
  144. {
  145. SetPlayerPos(playerid,_pTPToPos[playerid][0],_pTPToPos[playerid][1],_pTPToPos[playerid][2]);
  146. SetPlayerInterior(playerid,_PlayerInterior[playerid]);
  147. FadeColorForPlayer(playerid,_TELEPORTFADECOLORR,_TELEPORTFADECOLORG,_TELEPORTFADECOLORB,_TELEPORTFADECOLORA,0,0,0,0,_pTPSteps[playerid],1);
  148. _PlayerTeleporting[playerid]=2;
  149. }else if(_PlayerTeleporting[playerid]==2)
  150. {
  151. _PlayerTeleporting[playerid]=0;
  152. }
  153. else
  154. {
  155. CallLocalFunction("OnFadeComplete","ii",playerid,1);
  156. }
  157. }
  158. else if(_pHold[playerid])
  159. {
  160. _pHold[playerid]--;
  161. }
  162. else if(_pHold[playerid]==0)
  163. {
  164. _pHold[playerid]=-1;
  165. TextDrawHideForPlayer(playerid,_text);
  166. CallLocalFunction("OnFadeComplete","ii",playerid,0);
  167. }
  168. }
  169. }