Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using GTA;
  4. using GTA.Math;
  5. using System.Diagnostics;
  6. using System.IO.Pipes;
  7. using System.IO;
  8. using System.Threading;
  9. namespace GTATimer
  10. {
  11.     public class Class1 : Script
  12.     {
  13.         static NamedPipeServerStream server = new NamedPipeServerStream("VStreaming");
  14.         static Thread t = new Thread(new ThreadStart(provideV));
  15.         static Stopwatch stopWatch = new Stopwatch();
  16.         private static Mutex mut = new Mutex();
  17.         static TimeSpan ts;
  18.         static bool started = false;
  19.         static bool stopwatchStarted = false;
  20.         static string elapsedTime;
  21.         static float V = -11.1f;
  22.         static int count = 0;
  23.         static bool vUpdated = false;
  24.         public Class1()
  25.         {
  26.             Tick += onTick;
  27.             KeyUp += onKeyUp;
  28.            
  29.             t.Start();
  30.         }
  31.         public static void provideV()
  32.         {
  33.             server.WaitForConnection();
  34.             while (true) {
  35.                 if (vUpdated) {
  36.                 //float v = Game.Player.Character.CurrentVehicle.Speed;
  37.                     try {
  38.                         mut.WaitOne();
  39.                         var byteArray = new byte[4];
  40.                         byteArray = BitConverter.GetBytes(Class1.V);
  41.                         server.Write(byteArray, 0, 4);
  42.                         vUpdated = false;
  43.                         mut.ReleaseMutex();
  44.  
  45.                     }catch(Exception e){
  46.                         //server.WaitForConnection();
  47.                         break;
  48.                     }
  49.                 }
  50.                 //UI.ShowSubtitle("V: " + v);
  51.                
  52.                 Thread.Sleep(1);
  53.             }
  54.             server.Close();
  55.         }
  56.         protected static void onTick(object sender, EventArgs e)
  57.         {
  58.             ts = stopWatch.Elapsed;
  59.             elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
  60.             ts.Hours, ts.Minutes, ts.Seconds,
  61.             ts.Milliseconds / 10);;
  62.             UI.ShowSubtitle("Runtime " + elapsedTime);
  63.             mut.WaitOne();
  64.             Class1.V = Game.Player.Character.CurrentVehicle.Speed;
  65.             vUpdated = true;
  66.             mut.ReleaseMutex();
  67.         }
  68.         protected static void onKeyUp(object value0, System.Windows.Forms.KeyEventArgs value1)
  69.         {
  70.             if(stopwatchStarted == false && value1.KeyCode == Keys.T)
  71.             {
  72.                 //Game.Player.Character.Position = new Vector3(169.1f, 6561.4f, 31.3f);
  73.                 Vector3 rot = Game.Player.Character.CurrentVehicle.Rotation;
  74.                 Game.Player.Character.LastVehicle.Position = new Vector3(169.1f, 6561.4f, 31.3f);
  75.                
  76.                 Game.Player.Character.CurrentVehicle.Repair();
  77.                 stopWatch.Reset();
  78.                 stopWatch.Start();
  79.                 stopwatchStarted = true;
  80.             }
  81.             else if (stopwatchStarted == true && value1.KeyCode == Keys.T)
  82.             {
  83.                 ts = stopWatch.Elapsed;
  84.                 stopWatch.Stop();
  85.                 stopwatchStarted = false;
  86.                 elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
  87.                 ts.Hours, ts.Minutes, ts.Seconds,
  88.                 ts.Milliseconds / 10);
  89.             }
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement