예제 #1
0
        public static bool EnsurePlayerIsVehicleDriver(out int player, out int vehicle, bool notification = true)
        {
            if (!EnsurePlayerIsInVehicle(out player, out vehicle, notification))
            {
                return(false);
            }

            var driver = API.GetPedInVehicleSeat(vehicle, -1);

            if (driver != player && !Autopilot.IsOwnedAutopilot(driver))
            {
                if (notification)
                {
                    Notification("Player is not the driver of this vehicle");
                }

                return(false);
            }

            return(true);
        }
예제 #2
0
        private static Task UpdateControls()
        {
            var player  = API.GetPlayerPed(-1);
            var vehicle = API.GetVehiclePedIsIn(player, !API.IsPedInAnyVehicle(player, false));

            if (API.IsEntityDead(vehicle))
            {
                if (Common.GetClosestEntity(Autopilot.Get(true, -1).Select(tup => tup.Item2).Where(v => !API.IsEntityDead(v)), out vehicle))
                {
                    API.SetPlayersLastVehicle(vehicle);
                }
                else
                {
                    return(Delay(100));
                }
            }

            var driver         = API.GetPedInVehicleSeat(vehicle, -1);
            var isAutopilot    = Autopilot.IsOwnedAutopilot(driver);
            var hasOtherDriver = !API.IsVehicleSeatFree(vehicle, -1) && driver != player && !isAutopilot;

            if (hasOtherDriver || MainMenu.IsOpen || API.IsEntityDead(vehicle))
            {
                return(Delay(100));
            }

            if (API.DecorExistOn(vehicle, CustomHornDecor))
            {
                if (API.IsControlJustPressed(0, 86)) // INPUT_VEH_HORN
                {
                    TriggerServerEvent("PocceMod:ToggleHorn", API.VehToNet(vehicle), true);
                }
                else if (API.IsControlJustReleased(0, 86))
                {
                    TriggerServerEvent("PocceMod:ToggleHorn", API.VehToNet(vehicle), false);
                }
            }

            if (API.DecorExistOn(vehicle, LightMultiplierDecor))
            {
                if (API.IsControlPressed(0, 172)) // up
                {
                    SetLightMultiplier(vehicle, GetLightMultiplier(vehicle) + 0.1f);
                    TurnOnLight(vehicle, Light.Headlight);
                }
                else if (API.IsControlPressed(0, 173)) // down
                {
                    SetLightMultiplier(vehicle, GetLightMultiplier(vehicle) - 0.1f);
                    TurnOnLight(vehicle, Light.Headlight);
                }
            }

            if (TurboBoostKey > 0 && IsFeatureEnabled(vehicle, FeatureFlag.TurboBoost))
            {
                var mode = TurboBoostMode.Custom;
                if (TurboBoostVerticalKey > 0 && API.IsControlPressed(0, TurboBoostVerticalKey)) // LEFT_SHIFT by default
                {
                    mode = TurboBoostMode.Vertical;
                }
                else if (TurboBoostHorizontalKey > 0 && API.IsControlPressed(0, TurboBoostHorizontalKey)) // LEFT_CTRL by default
                {
                    mode = TurboBoostMode.Horizontal;
                }

                if (API.IsControlJustPressed(0, TurboBoostKey) || API.IsDisabledControlJustPressed(0, TurboBoostKey))
                {
                    TriggerServerEvent("PocceMod:ToggleTurboBoost", API.VehToNet(vehicle), true, (int)mode);
                }
                else if (API.IsControlJustReleased(0, TurboBoostKey) || API.IsDisabledControlJustReleased(0, TurboBoostKey))
                {
                    TriggerServerEvent("PocceMod:ToggleTurboBoost", API.VehToNet(vehicle), false, 0);
                }
            }

            if (driver == player && StabilizerKey > 0 && IsFeatureEnabled(vehicle, FeatureFlag.Stabilizer))
            {
                if (API.IsControlJustPressed(0, StabilizerKey))
                {
                    _stabilizerPitch = API.GetEntityPitch(vehicle);
                    _stabilizerRoll  = API.GetEntityRoll(vehicle);
                }
                else if (API.IsControlPressed(0, StabilizerKey))
                {
                    var pitch = _stabilizerPitch - API.GetEntityPitch(vehicle);
                    var roll  = _stabilizerRoll - API.GetEntityRoll(vehicle);
                    Common.ApplyTorque(vehicle, pitch * 0.1f, roll * 0.1f);
                }
            }

            if (driver != player && IsFeatureEnabled(vehicle, FeatureFlag.RemoteControl))
            {
                if (RemoteControlKeys.Any(key => API.IsControlPressed(0, key)))
                {
                    if (API.IsVehicleSeatFree(vehicle, -1))
                    {
                        return(Autopilot.Spawn(vehicle));
                    }

                    if (API.IsPedInFlyingVehicle(driver))
                    {
                        var model  = (uint)API.GetEntityModel(vehicle);
                        var isHeli = API.IsThisModelAHeli(model);

                        var force = isHeli ? 0.1f : 1f;
                        if (API.IsControlPressed(0, 172)) // up
                        {
                            Common.ApplyTorque(vehicle, -force, 0);
                        }
                        else if (API.IsControlPressed(0, 173)) // down
                        {
                            Common.ApplyTorque(vehicle, force, 0);
                        }

                        if (API.IsControlPressed(0, 174)) // left
                        {
                            Common.ApplyTorque(vehicle, 0, force / 2);
                        }
                        else if (API.IsControlPressed(0, 175)) // right
                        {
                            Common.ApplyTorque(vehicle, 0, -force / 2);
                        }

                        if (isHeli)
                        {
                            API.TaskVehicleTempAction(driver, vehicle, 9, 1);
                        }

                        return(Delay(33));
                    }
                    else // non-aircraft
                    {
                        if (API.IsControlPressed(0, 172)) // up
                        {
                            API.TaskVehicleTempAction(driver, vehicle, 9, 1);

                            if (API.IsControlPressed(0, 174)) // left
                            {
                                API.TaskVehicleTempAction(driver, vehicle, 7, 1);
                            }
                            else if (API.IsControlPressed(0, 175)) // right
                            {
                                API.TaskVehicleTempAction(driver, vehicle, 8, 1);
                            }
                        }
                        else if (API.IsControlPressed(0, 173)) // down
                        {
                            API.TaskVehicleTempAction(driver, vehicle, 22, 1);

                            if (API.IsControlPressed(0, 174)) // left
                            {
                                API.TaskVehicleTempAction(driver, vehicle, 13, 1);
                            }
                            else if (API.IsControlPressed(0, 175)) // right
                            {
                                API.TaskVehicleTempAction(driver, vehicle, 14, 1);
                            }
                        }
                        else
                        {
                            if (API.IsControlPressed(0, 174)) // left
                            {
                                API.TaskVehicleTempAction(driver, vehicle, 4, 1);
                            }
                            else if (API.IsControlPressed(0, 175)) // right
                            {
                                API.TaskVehicleTempAction(driver, vehicle, 5, 1);
                            }
                        }
                    }
                }

                /*else if (API.IsPedInFlyingVehicle(driver) && API.IsEntityInAir(vehicle) && RemoteControlKeys.Any(key => API.IsControlJustReleased(0, key)))
                 * {
                 *  //Autopilot.GotoWaypoint(driver, vehicle, API.GetEntityCoords(player, true));
                 *  Autopilot.Wander(driver, vehicle);
                 * }*/
            }

            return(Task.FromResult(0));
        }