From a419403c1fded55eae0968361eb87393c4770805 Mon Sep 17 00:00:00 2001 From: oldnapalm <38410858+oldnapalm@users.noreply.github.com> Date: Tue, 21 Dec 2021 09:39:19 -0300 Subject: [PATCH] Add CantFallFromBike option --- BicycleCity/BicycleCity.cs | 59 ++++++++++++++++++++----------------- BicycleCity/BicycleCity.ini | 3 +- README.md | 1 + 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/BicycleCity/BicycleCity.cs b/BicycleCity/BicycleCity.cs index 9dfc110..01987ec 100644 --- a/BicycleCity/BicycleCity.cs +++ b/BicycleCity/BicycleCity.cs @@ -10,32 +10,33 @@ namespace BicycleCity { public class BicycleCity : Script { - int bikesPercentage; - bool aggressiveDrivers; - bool aggressiveCyclists; - bool cyclistsBreakLaws; - bool cheeringCrowds; - int cheeringCrowdsSlope; - bool stopPedAttacks; - int lastTime = Environment.TickCount; - int lastPaparazzi = Environment.TickCount; - List fans = new List(); - string[] availableBicycles = { "BMX", "CRUISER", "FIXTER", "SCORCHER", "TRIBIKE", "TRIBIKE2", "TRIBIKE3" }; - VehicleDrivingFlags aggressiveDrivingStyle = VehicleDrivingFlags.AvoidEmptyVehicles | - VehicleDrivingFlags.AvoidObjects | - VehicleDrivingFlags.AvoidPeds | - VehicleDrivingFlags.AvoidVehicles | - VehicleDrivingFlags.StopAtTrafficLights; - VehicleDrivingFlags lawBreakerDrivingStyle = VehicleDrivingFlags.AllowGoingWrongWay | - VehicleDrivingFlags.AllowMedianCrossing | - VehicleDrivingFlags.AvoidEmptyVehicles | - VehicleDrivingFlags.AvoidObjects | - VehicleDrivingFlags.AvoidVehicles; + private readonly int bikesPercentage; + private readonly bool aggressiveDrivers; + private readonly bool aggressiveCyclists; + private readonly bool cyclistsBreakLaws; + private readonly bool cheeringCrowds; + private readonly int cheeringCrowdsSlope; + private readonly bool stopPedAttacks; + private readonly bool cantFallFromBike; + private int lastTime = Environment.TickCount; + private int lastPaparazzi = Environment.TickCount; + private readonly List fans = new List(); + private readonly string[] availableBicycles = { "BMX", "CRUISER", "FIXTER", "SCORCHER", "TRIBIKE", "TRIBIKE2", "TRIBIKE3" }; + private readonly VehicleDrivingFlags aggressiveDrivingStyle = VehicleDrivingFlags.AvoidEmptyVehicles | + VehicleDrivingFlags.AvoidObjects | + VehicleDrivingFlags.AvoidPeds | + VehicleDrivingFlags.AvoidVehicles | + VehicleDrivingFlags.StopAtTrafficLights; + private readonly VehicleDrivingFlags lawBreakerDrivingStyle = VehicleDrivingFlags.AllowGoingWrongWay | + VehicleDrivingFlags.AllowMedianCrossing | + VehicleDrivingFlags.AvoidEmptyVehicles | + VehicleDrivingFlags.AvoidObjects | + VehicleDrivingFlags.AvoidVehicles; public BicycleCity() { ScriptSettings settings = ScriptSettings.Load(@".\Scripts\BicycleCity.ini"); - bikesPercentage = settings.GetValue("Main", "BikesPercentage", 50); + bikesPercentage = settings.GetValue("Main", "BikesPercentage", 0); if (bikesPercentage < 0) bikesPercentage = 0; if (bikesPercentage > 100) bikesPercentage = 100; aggressiveDrivers = settings.GetValue("Main", "AggressiveDrivers", false); @@ -44,11 +45,12 @@ public BicycleCity() cheeringCrowds = settings.GetValue("Main", "CheeringCrowds", true); cheeringCrowdsSlope = settings.GetValue("Main", "CheeringCrowdsSlope", 8); stopPedAttacks = settings.GetValue("Main", "StopPedAttacks", false); + cantFallFromBike = settings.GetValue("Main", "CantFallFromBike", true); Tick += OnTick; Aborted += OnAbort; } - void OnTick(object sender, EventArgs e) + private void OnTick(object sender, EventArgs e) { if (Environment.TickCount >= lastTime + 1000) { @@ -152,7 +154,7 @@ void OnTick(object sender, EventArgs e) { if (fan != null) { - if (fan.Position.DistanceTo(Game.Player.Character.Position) > 150f || isEnemy(fan)) + if (fan.Position.DistanceTo(Game.Player.Character.Position) > 150f || IsEnemy(fan)) { fan.Delete(); fans.Remove(fan); @@ -165,7 +167,7 @@ void OnTick(object sender, EventArgs e) if (stopPedAttacks) foreach (Ped ped in World.GetNearbyPeds(Game.Player.Character, 100f)) - if (isEnemy(ped)) + if (IsEnemy(ped)) ped.Delete(); lastTime = Environment.TickCount; @@ -175,14 +177,17 @@ void OnTick(object sender, EventArgs e) foreach (Ped fan in fans) if (fan != null && !fan.IsRunning) fan.Heading = (Game.Player.Character.Position - fan.Position).ToHeading(); + + if (cantFallFromBike) + Function.Call(Hash.SET_PED_CAN_BE_KNOCKED_OFF_VEHICLE, Game.Player.Character, 1); } - bool isEnemy(Ped ped) + private bool IsEnemy(Ped ped) { return (ped.GetRelationshipWithPed(Game.Player.Character) == Relationship.Hate && ped.IsHuman) || ped.IsInCombat || ped.IsInMeleeCombat || ped.IsShooting; } - void OnAbort(object sender, EventArgs e) + private void OnAbort(object sender, EventArgs e) { Tick -= OnTick; diff --git a/BicycleCity/BicycleCity.ini b/BicycleCity/BicycleCity.ini index 91511e1..76534b3 100644 --- a/BicycleCity/BicycleCity.ini +++ b/BicycleCity/BicycleCity.ini @@ -1,8 +1,9 @@ [Main] -BikesPercentage=50 +BikesPercentage=0 AggressiveDrivers=false AggressiveCyclists=false CyclistsBreakLaws=false CheeringCrowds=true CheeringCrowdsSlope=8 StopPedAttacks=false +CantFallFromBike=true diff --git a/README.md b/README.md index e74580c..1dfd9ff 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Replace cars by bikes (GTA V mod) - **CheeringCrowds** - cheering peds will be spawned on climbs - **CheeringCrowdsSlope** - minimum slope for cheering crowds - **StopPedAttacks** - attacking peds will be removed + - **CantFallFromBike** - player can't be knocked off the bike ## Download https://github.com/oldnapalm/BicycleCity/releases/latest