Beispiel #1
0
        private void OnTick(object sender, EventArgs e)
        {
            if (!Globals.Settings.SpeedometerEnabled || !EnableSpeedometer())
            {
                return;
            }
            try
            {
                this.UISpeedometer.Caption = SpeedHelper.GetSpeedInKmh(GetPlayerSpeed());
                this.DrawMeters();
            }
            catch (Exception exc)
            {
                Logger.LogToFile(PluginName, exc);
            }

            //UI.ShowSubtitle("jap.");

            this.prevPos = this.Character.Position;
        }
Beispiel #2
0
        private void OnTick(object sender, EventArgs e)
        {
            if (!Globals.Settings.TempomatEnabled || !PlayerHelper.PlayerIsNotNull())
            {
                //Resetting script
                if (this.TempomatEnabled)
                {
                    this.ResetScript();
                }
                return;
            }
            try
            {
                if (Game.IsPaused || !Game.Player.Character.IsInVehicle() || !VehicleIsTempomatAllowed())
                {
                    if (this.TempomatEnabled && this.Vehicle == null)
                    {
                        UI.Notify("Tempomat OFF : Error 404 - No vehicle found");
                        this.ResetScript();
                    }
                    return;
                }

                //GTA.UI.ShowSubtitle($"{((this.TempomatMaxSpeed * 1.05) * 3.6f).ToString("000")} | {(this.TempomatMaxSpeed * 3.6f).ToString("000")} | {((this.TempomatMaxSpeed / 1.05) * 3.6f).ToString("000")}");
                if (this.TempomatEnabled)
                {
                    var ResetScript = false;

                    if (Game.IsControlPressed(Globals.GameInputMethod, GTA.Control.VehicleExit))
                    {
                        UI.Notify("Tempomat OFF : Error 404 - No driver found");
                        ResetScript = true;
                    }

                    if ((Game.IsControlPressed(Globals.GameInputMethod, GTA.Control.VehicleBrake) || Game.IsControlPressed(Globals.GameInputMethod, GTA.Control.VehicleHandbrake)))
                    {
                        UI.Notify("Tempomat OFF : Brake detected!");
                        ResetScript = true;
                    }

                    if (ResetScript)
                    {
                        this.ResetScript();
                        return;
                    }


                    this.UISpeedometer.Caption = $"Max Speed: {SpeedHelper.GetSpeedInKmh(this.TempomatMaxSpeed)}";
                    this.UISpeedometer.Draw();

                    //If vehicle is accelerating, TempomatMaxSpeed should change to VehicleSpeed
                    if (Game.IsControlPressed(1, GTA.Control.VehicleAccelerate))
                    {
                        if (IsVehicleAbnormal())
                        {
                            return;
                        }

                        //Player should be accelerating
                        if (Vehicle.Speed > (TempomatMaxSpeed * 1.05))
                        {
                            this.TempomatMaxSpeed = Vehicle.Speed;
                            return;
                        }
                    }
                }

                if (Game.IsControlPressed(Globals.GameInputMethod, GTA.Control.VehicleDuck) && !Globals.NativeUiIsAnyMenuOpen)
                {
                    this.TempomatEnabled = !this.TempomatEnabled;

                    if (this.TempomatEnabled && !IsVehicleAbnormal())
                    {
                        this.TempomatMaxSpeed = Vehicle.Speed;

                        GTA.UI.Notify("Tempomat ON");

                        if (this.TempomatMaxSpeed < 2.777778f)
                        {
                            this.TempomatMaxSpeed = 2.777778f;
                        }
                        GTA.UI.Notify($"Tempomat set to: {SpeedHelper.GetSpeedInKmh(this.TempomatMaxSpeed)}");
                    }
                    else
                    {
                        UI.Notify("Tempomat OFF : Disabled by driver");
                        this.ResetScript();
                    }
                    Wait(250);
                }


                if (!this.TempomatEnabled || this.IsVehicleAbnormal())
                {
                    return;
                }


                //Mos MagicMathShit
                var factor = 10.0f;
                var perc   = Vehicle.Speed / this.TempomatMaxSpeed;
                this.TempomatAccelerationRate = (1.06f - perc) * factor;
                this.TempomatAccelerationRate = Math.Min(1f, this.TempomatAccelerationRate); //max 1
                this.TempomatAccelerationRate = Math.Max(0f, this.TempomatAccelerationRate); //min 0

                //Accelerate
                Game.SetControlNormal(Globals.GameInputMethod, Control.VehicleAccelerate, TempomatAccelerationRate);
            }
            catch (Exception exc)
            {
                Logger.LogToFile(PluginName, exc);
            }
        }