Advertisement
Zzerss

Textdraw animado con efecto de transparencia

Apr 17th, 2023 (edited)
1,925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.55 KB | Gaming | 0 0
  1. #include "a_samp"
  2. #include "zcmd"
  3. #include "sscanf2"
  4.  
  5.  
  6.  
  7. new PlayerText:ANIMATED_NOTIF_XD[MAX_PLAYERS];
  8. // Start pos animated txt 320.0 330.0 || End pos Y 310.0
  9. #define POS_XNOTIFC_ANIMATED 320.0
  10. #define POS_YNOTIFC_ANIMATED 330.0
  11. #define POS_END_NOTIFC_ANIMATED 310.0
  12. #define TIMER_FOR_ANIMATED 25 // = 0.025
  13. #define VALOR_REDUCE_FOR_LETTER_X 0.0010039  //Obtener este resultado? > POS_LETTER_ALT_X
  14. #define VALOR_REDUCE_FOR_LETTER_Y 0.0040043
  15.  
  16. #define POS_LETTER_ALT_X 0.2811
  17. #define POS_LETTER_ALT_Y 1.12121
  18. /*
  19. Si tienes un valor de 0.2811 y quieres que se reduzca a 0 en 7 segundos, con un temporizador que se ejecuta cada 25 ms (0.025 segundos),
  20. entonces necesitarás restar una cantidad fija en cada ejecución del temporizador para lograrlo primero, debes calcular cuántas veces se
  21. ejecutará el temporizador en 7 segundos como el temporizador se ejecuta cada 0.025 segundos se ejecutará 7 / 0.025 = 280 veces en 7 segundos.
  22. Luego, debes calcular cuánto debes restar en cada ejecución del temporizador para reducir el valor de 0.2811 a 0 en 280 ejecuciones.
  23. Para hacer esto, puedes dividir el valor inicial (0.2811) entre el número de ejecuciones (280): 0.2811 / 280 = 0.0010039285714285714.
  24. Por lo tanto, si restas aproximadamente 0.0010039 en cada ejecución del temporizador,
  25. el valor de 0.2811 se reducirá a 0 en aproximadamente 7 segundos y habrá un total de 280 ejecuciones del temporizador.
  26. */
  27.  
  28.  
  29.  
  30. enum asdasdasd
  31. {
  32.     TTIMER,
  33.     bool:SHOW_NOTIFC_ANIMATED,
  34.     Float:COUNT_NOTIFC_ANIMATED_POS,
  35.     Float:COUNT_TEXTSIZE_NOTIFC_X,
  36.     Float:COUNT_TEXTSIZE_NOTIFC_Y,
  37.     CREATE_AND_DESTROY,
  38.     COUNT_COLOR_OPACITY,
  39.     TEXT_FOR_NOTIFC_ANIMATED[ 128 ],
  40.     COLOR_FOR_NOTIFC_ANIMATED_IDX,
  41.     FINAL_COLOR_FROM_TXT,
  42.     FINAL_COLOR_FROM_BACKGROUND
  43. }
  44. new PLAYER_NOTIFC[ MAX_PLAYERS ][ asdasdasd ];
  45. CMD:prueba1(playerid, params[])
  46. {
  47.     new string[123 + 1];
  48.     if(sscanf(params, "s[123]", string)) return 1;
  49.     ShowAnimated_Notification(playerid, 0xFFFF00FF,string);
  50.    
  51.     return 1;
  52. }
  53. ShowAnimated_Notification(playerid, color, text[])
  54. {
  55.     if(PLAYER_NOTIFC[ playerid ][ SHOW_NOTIFC_ANIMATED ]) return 1;
  56.     PLAYER_NOTIFC[ playerid ][ SHOW_NOTIFC_ANIMATED ] = true;
  57.     PLAYER_NOTIFC[ playerid ][ CREATE_AND_DESTROY ] = 0;
  58.     PLAYER_NOTIFC[ playerid ][ COUNT_NOTIFC_ANIMATED_POS ] = POS_YNOTIFC_ANIMATED;
  59.     PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_X ] = POS_LETTER_ALT_X;
  60.     PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_Y ] = POS_LETTER_ALT_Y;
  61.  
  62.     PLAYER_NOTIFC[ playerid ][ COUNT_COLOR_OPACITY ] = 99;
  63.     PLAYER_NOTIFC[ playerid ][ COLOR_FOR_NOTIFC_ANIMATED_IDX ] = color;
  64.     format(PLAYER_NOTIFC[ playerid ][ TEXT_FOR_NOTIFC_ANIMATED ], 128,"%s",text);
  65.     KillTimer(PLAYER_NOTIFC[ playerid ][ TTIMER ]);
  66.     PLAYER_NOTIFC[ playerid ][ TTIMER ] = SetTimerEx("Verificar_Posxd", TIMER_FOR_ANIMATED, true, "d", playerid);
  67.     return 1;
  68. }
  69. //0.2800 || 1.000
  70. forward Verificar_Posxd(playerid);
  71. public Verificar_Posxd(playerid)
  72. {
  73.     if(PLAYER_NOTIFC[ playerid ][ COUNT_NOTIFC_ANIMATED_POS ] != POS_END_NOTIFC_ANIMATED || PLAYER_NOTIFC[ playerid ][ COUNT_NOTIFC_ANIMATED_POS ] > POS_END_NOTIFC_ANIMATED) PLAYER_NOTIFC[ playerid ][ COUNT_NOTIFC_ANIMATED_POS ] -= 0.2;
  74.     if(PLAYER_NOTIFC[ playerid ][ COUNT_NOTIFC_ANIMATED_POS ] == POS_END_NOTIFC_ANIMATED || PLAYER_NOTIFC[ playerid ][ COUNT_NOTIFC_ANIMATED_POS ] <= POS_END_NOTIFC_ANIMATED) return TURN_OFF_NOTIFC(playerid);
  75.     if(PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_X ] != 0 ) PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_X ] -= VALOR_REDUCE_FOR_LETTER_X;
  76.     if(PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_Y ] != 0 ) PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_Y ] -= VALOR_REDUCE_FOR_LETTER_Y;
  77.     new savecolor[15 + 1];
  78.     PLAYER_NOTIFC[ playerid ][ COUNT_COLOR_OPACITY ] -= 1;
  79.     format(savecolor, sizeof savecolor,"%s%02d",IntToHexColor(PLAYER_NOTIFC[ playerid ][ COLOR_FOR_NOTIFC_ANIMATED_IDX ]),PLAYER_NOTIFC[ playerid ][ COUNT_COLOR_OPACITY ]);
  80.     PLAYER_NOTIFC[ playerid ][ FINAL_COLOR_FROM_TXT ] = HexToInt(savecolor);
  81.     format(savecolor, sizeof savecolor,"000000%02d",PLAYER_NOTIFC[ playerid ][ COUNT_COLOR_OPACITY ]);
  82.     PLAYER_NOTIFC[ playerid ][ FINAL_COLOR_FROM_BACKGROUND ] = HexToInt(savecolor);
  83.  
  84.     //
  85.     switch(PLAYER_NOTIFC[ playerid ][ CREATE_AND_DESTROY ])
  86.     {
  87.         case 0:
  88.         {
  89.             PlayerTextDrawDestroy(playerid, ANIMATED_NOTIF_XD[playerid]);
  90.             PlayerTextDrawHide(playerid, ANIMATED_NOTIF_XD[playerid]);
  91.             PLAYER_NOTIFC[ playerid ][ CREATE_AND_DESTROY ] = 1;
  92.             ANIMATED_NOTIF_XD[playerid] = CreatePlayerTextDraw(playerid, POS_XNOTIFC_ANIMATED, PLAYER_NOTIFC[ playerid ][ COUNT_NOTIFC_ANIMATED_POS ], PLAYER_NOTIFC[ playerid ][ TEXT_FOR_NOTIFC_ANIMATED ]);
  93.             PlayerTextDrawLetterSize(playerid, ANIMATED_NOTIF_XD[playerid], PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_X ], PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_Y ]);
  94.             PlayerTextDrawAlignment(playerid, ANIMATED_NOTIF_XD[playerid], 2);
  95.             PlayerTextDrawColor(playerid, ANIMATED_NOTIF_XD[playerid], PLAYER_NOTIFC[ playerid ][ FINAL_COLOR_FROM_TXT ]);//PLAYER_NOTIFC[ playerid ][ COLOR_FOR_NOTIFC_ANIMATED_IDX ]);
  96.             PlayerTextDrawSetShadow(playerid, ANIMATED_NOTIF_XD[playerid], 0);
  97.             PlayerTextDrawSetOutline(playerid, ANIMATED_NOTIF_XD[playerid], 1);
  98.             PlayerTextDrawBackgroundColor(playerid, ANIMATED_NOTIF_XD[playerid], PLAYER_NOTIFC[ playerid ][ FINAL_COLOR_FROM_BACKGROUND ]);
  99.             PlayerTextDrawFont(playerid, ANIMATED_NOTIF_XD[playerid], 1);
  100.             PlayerTextDrawSetProportional(playerid, ANIMATED_NOTIF_XD[playerid], 1);
  101.             PlayerTextDrawSetShadow(playerid, ANIMATED_NOTIF_XD[playerid], 0);
  102.             PlayerTextDrawShow(playerid, ANIMATED_NOTIF_XD[playerid]);
  103.         }
  104.         case 1:
  105.         {
  106.             PlayerTextDrawDestroy(playerid, ANIMATED_NOTIF_XD[playerid]);
  107.             PlayerTextDrawHide(playerid, ANIMATED_NOTIF_XD[playerid]);
  108.             PLAYER_NOTIFC[ playerid ][ CREATE_AND_DESTROY ] = 0;
  109.             ANIMATED_NOTIF_XD[playerid] = CreatePlayerTextDraw(playerid, POS_XNOTIFC_ANIMATED, PLAYER_NOTIFC[ playerid ][ COUNT_NOTIFC_ANIMATED_POS ], PLAYER_NOTIFC[ playerid ][ TEXT_FOR_NOTIFC_ANIMATED ]);
  110.             PlayerTextDrawLetterSize(playerid, ANIMATED_NOTIF_XD[playerid], PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_X ], PLAYER_NOTIFC[ playerid ][ COUNT_TEXTSIZE_NOTIFC_Y ]);
  111.             PlayerTextDrawAlignment(playerid, ANIMATED_NOTIF_XD[playerid], 2);
  112.             PlayerTextDrawColor(playerid, ANIMATED_NOTIF_XD[playerid], PLAYER_NOTIFC[ playerid ][ FINAL_COLOR_FROM_TXT ]);//PLAYER_NOTIFC[ playerid ][ COLOR_FOR_NOTIFC_ANIMATED_IDX ]);
  113.             PlayerTextDrawSetShadow(playerid, ANIMATED_NOTIF_XD[playerid], 0);
  114.             PlayerTextDrawSetOutline(playerid, ANIMATED_NOTIF_XD[playerid], 1);
  115.             PlayerTextDrawBackgroundColor(playerid, ANIMATED_NOTIF_XD[playerid], PLAYER_NOTIFC[ playerid ][ FINAL_COLOR_FROM_BACKGROUND ]);
  116.             PlayerTextDrawFont(playerid, ANIMATED_NOTIF_XD[playerid], 1);
  117.             PlayerTextDrawSetProportional(playerid, ANIMATED_NOTIF_XD[playerid], 1);
  118.             PlayerTextDrawSetShadow(playerid, ANIMATED_NOTIF_XD[playerid], 0);
  119.             PlayerTextDrawShow(playerid, ANIMATED_NOTIF_XD[playerid]);
  120.         }
  121.     }
  122.  
  123.     return 1;
  124. }
  125.  
  126. TURN_OFF_NOTIFC(playerid) //Falta mejorar
  127. {
  128.     PLAYER_NOTIFC[ playerid ][ SHOW_NOTIFC_ANIMATED ] = false;
  129.     KillTimer(PLAYER_NOTIFC[ playerid ][ TTIMER ]);
  130.     PlayerTextDrawDestroy(playerid, ANIMATED_NOTIF_XD[playerid]);
  131.     return 1;
  132. }
  133.  
  134. stock HexToInt(string[])
  135. {
  136.     if (string[0]==0) return 0;
  137.     new i;
  138.     new cur=1;
  139.     new res=0;
  140.     for (i=strlen(string);i>0;i--)
  141.     {
  142.         if (string[i-1]<58) res=res+cur*(string[i-1]-48); else res=res+cur*(string[i-1]-65+10);
  143.         cur=cur*16;
  144.     }
  145.     return res;
  146. }
  147. stock IntToHexColor(color) {
  148.     new hexColor[7];
  149.     format(hexColor, sizeof(hexColor), "%06x", color);
  150.     return hexColor;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement