Advertisement
GTA5HelpDesk

Untitled

Feb 9th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1.  
  2. using GTA;
  3. using LemonUI.Elements;
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. public class Test : Script
  9. {
  10. ScaledRectangle rectangle;
  11. const int slidingDuration = 3000;
  12. bool isSlidingRight = true;
  13. int slidingStartTick;
  14. int startingPosition;
  15. bool isSliding = false;
  16. bool isXPressed = false; // Add this flag
  17.  
  18. public Test()
  19. {
  20. Tick += OnTick;
  21. KeyDown += OnKeyDown;
  22.  
  23. rectangle = new ScaledRectangle(new PointF(100, 410), new SizeF(400, 400));
  24. }
  25.  
  26. private float lerp(float a, float b, float t)
  27. {
  28. return a + (b - a) * t;
  29. }
  30.  
  31. private void OnTick(object sender, EventArgs e)
  32. {
  33. if (isSliding)
  34. {
  35. float progress = (float)(Game.GameTime - slidingStartTick) / slidingDuration;
  36. float xPosition = lerp(startingPosition, isSlidingRight ? -500 : 100, progress);
  37. rectangle.Position = new PointF(xPosition, 410);
  38.  
  39. if (progress >= 1f)
  40. {
  41. isSliding = false;
  42. if (isSlidingRight)
  43. {
  44. rectangle.Position = new PointF(-500, 410);
  45. }
  46. else
  47. {
  48. rectangle.Position = new PointF(100, 410);
  49. }
  50. }
  51. }
  52. if (isXPressed) // Only draw the rectangle if 'X' has been pressed
  53. {
  54. rectangle.Draw();
  55. }
  56. }
  57.  
  58. private void OnKeyDown(object sender, KeyEventArgs e)
  59. {
  60. if (e.KeyCode == Keys.X)
  61. {
  62. isSliding = false;
  63. rectangle.Position = new PointF(100, 410);
  64. isXPressed = true; // Set the flag to true when 'X' is pressed
  65. }
  66. else if (e.KeyCode == Keys.Y)
  67. {
  68. if (!isSliding)
  69. {
  70. isSliding = true;
  71. slidingStartTick = Game.GameTime;
  72. startingPosition = (int)rectangle.Position.X;
  73. isSlidingRight = !isSlidingRight;
  74. }
  75. else
  76. {
  77. isSliding = false;
  78. startingPosition = (int)rectangle.Position.X;
  79. }
  80. }
  81. }
  82. }
  83.  
  84.  
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement