Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using GTA;
- using GTA.Math;
- using System.Diagnostics;
- using System.IO.Pipes;
- using System.IO;
- using System.Threading;
- namespace GTATimer
- {
- public class Class1 : Script
- {
- static NamedPipeServerStream server = new NamedPipeServerStream("VStreaming");
- static Thread t = new Thread(new ThreadStart(provideV));
- static Stopwatch stopWatch = new Stopwatch();
- private static Mutex mut = new Mutex();
- static TimeSpan ts;
- static bool started = false;
- static bool stopwatchStarted = false;
- static string elapsedTime;
- static float V = -11.1f;
- static int count = 0;
- static bool vUpdated = false;
- public Class1()
- {
- Tick += onTick;
- KeyUp += onKeyUp;
- t.Start();
- }
- public static void provideV()
- {
- server.WaitForConnection();
- while (true) {
- if (vUpdated) {
- //float v = Game.Player.Character.CurrentVehicle.Speed;
- try {
- mut.WaitOne();
- var byteArray = new byte[4];
- byteArray = BitConverter.GetBytes(Class1.V);
- server.Write(byteArray, 0, 4);
- vUpdated = false;
- mut.ReleaseMutex();
- }catch(Exception e){
- //server.WaitForConnection();
- break;
- }
- }
- //UI.ShowSubtitle("V: " + v);
- Thread.Sleep(1);
- }
- server.Close();
- }
- protected static void onTick(object sender, EventArgs e)
- {
- ts = stopWatch.Elapsed;
- elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
- ts.Hours, ts.Minutes, ts.Seconds,
- ts.Milliseconds / 10);;
- UI.ShowSubtitle("Runtime " + elapsedTime);
- mut.WaitOne();
- Class1.V = Game.Player.Character.CurrentVehicle.Speed;
- vUpdated = true;
- mut.ReleaseMutex();
- }
- protected static void onKeyUp(object value0, System.Windows.Forms.KeyEventArgs value1)
- {
- if(stopwatchStarted == false && value1.KeyCode == Keys.T)
- {
- //Game.Player.Character.Position = new Vector3(169.1f, 6561.4f, 31.3f);
- Vector3 rot = Game.Player.Character.CurrentVehicle.Rotation;
- Game.Player.Character.LastVehicle.Position = new Vector3(169.1f, 6561.4f, 31.3f);
- Game.Player.Character.CurrentVehicle.Repair();
- stopWatch.Reset();
- stopWatch.Start();
- stopwatchStarted = true;
- }
- else if (stopwatchStarted == true && value1.KeyCode == Keys.T)
- {
- ts = stopWatch.Elapsed;
- stopWatch.Stop();
- stopwatchStarted = false;
- elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
- ts.Hours, ts.Minutes, ts.Seconds,
- ts.Milliseconds / 10);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement