From 145cfd5cc044fec7ea49e99bd52a062e54365a04 Mon Sep 17 00:00:00 2001 From: oldnapalm <38410858+oldnapalm@users.noreply.github.com> Date: Mon, 10 May 2021 09:17:05 -0300 Subject: [PATCH] Add CyclistsBreakLaws option --- BicycleCity/BicycleCity.cs | 36 +++++++++++++++++++++++++----------- BicycleCity/BicycleCity.ini | 1 + README.md | 1 + 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/BicycleCity/BicycleCity.cs b/BicycleCity/BicycleCity.cs index 6ad9b99..7449970 100644 --- a/BicycleCity/BicycleCity.cs +++ b/BicycleCity/BicycleCity.cs @@ -11,13 +11,19 @@ public class BicycleCity : Script int bikesPercentage; bool aggressiveDrivers; bool aggressiveCyclists; + bool cyclistsBreakLaws; DateTime lastTime; string[] availableBicycles = { "BMX", "CRUISER", "FIXTER", "SCORCHER", "TRIBIKE", "TRIBIKE2", "TRIBIKE3" }; - VehicleDrivingFlags customDrivingStyle = VehicleDrivingFlags.AvoidEmptyVehicles | - VehicleDrivingFlags.AvoidObjects | - VehicleDrivingFlags.AvoidPeds | - VehicleDrivingFlags.AvoidVehicles | - VehicleDrivingFlags.StopAtTrafficLights; + VehicleDrivingFlags aggressiveDrivingStyle = VehicleDrivingFlags.AvoidEmptyVehicles | + VehicleDrivingFlags.AvoidObjects | + VehicleDrivingFlags.AvoidPeds | + VehicleDrivingFlags.AvoidVehicles | + VehicleDrivingFlags.StopAtTrafficLights; + VehicleDrivingFlags lawBreakerDrivingStyle = VehicleDrivingFlags.AllowGoingWrongWay | + VehicleDrivingFlags.AllowMedianCrossing | + VehicleDrivingFlags.AvoidEmptyVehicles | + VehicleDrivingFlags.AvoidObjects | + VehicleDrivingFlags.AvoidVehicles; public BicycleCity() { @@ -27,6 +33,7 @@ public BicycleCity() bikesPercentage = 100; aggressiveDrivers = settings.GetValue("Main", "AggressiveDrivers", false); aggressiveCyclists = settings.GetValue("Main", "AggressiveCyclists", false); + cyclistsBreakLaws = settings.GetValue("Main", "CyclistsBreakLaws", false); lastTime = DateTime.UtcNow; Tick += OnTick; } @@ -40,16 +47,17 @@ void OnTick(object sender, EventArgs e) int bicycles = 0; foreach (Vehicle vehicle in allVehicles) { - if (vehicle.Model.IsBicycle && vehicle.Driver != null && !vehicle.Driver.IsPlayer) + if (vehicle.Driver == null || vehicle.Driver.IsPlayer) + continue; + if (vehicle.Model.IsBicycle) bicycles++; else if (!vehicle.Model.IsTrain && !vehicle.Model.IsBoat && !vehicle.Model.IsHelicopter && !vehicle.Model.IsPlane && - !Function.Call(Hash.IS_ENTITY_A_MISSION_ENTITY, vehicle) && - vehicle.Driver != null && !vehicle.Driver.IsPlayer) + !Function.Call(Hash.IS_ENTITY_A_MISSION_ENTITY, vehicle)) { canChange.Add(vehicle); if (aggressiveDrivers) - Function.Call(Hash.SET_DRIVE_TASK_DRIVING_STYLE, vehicle.Driver, (int)customDrivingStyle); + Function.Call(Hash.SET_DRIVE_TASK_DRIVING_STYLE, vehicle.Driver, (int)aggressiveDrivingStyle); } } int toChange = (bicycles + canChange.Count) * bikesPercentage / 100 - bicycles; @@ -74,8 +82,14 @@ void OnTick(object sender, EventArgs e) newVehicle.MaxSpeed = 10; canChange[i].Delete(); driver.SetIntoVehicle(newVehicle, VehicleSeat.Driver); - Function.Call(Hash.TASK_VEHICLE_DRIVE_WANDER, driver, newVehicle, (float)random.Next(4, 8), - aggressiveCyclists ? (int)customDrivingStyle : (int)DrivingStyle.Normal); + int drivingStyle; + if (cyclistsBreakLaws) + drivingStyle = (int)lawBreakerDrivingStyle; + else if (aggressiveCyclists) + drivingStyle = (int)aggressiveDrivingStyle; + else + drivingStyle = (int)DrivingStyle.Normal; + Function.Call(Hash.TASK_VEHICLE_DRIVE_WANDER, driver, newVehicle, (float)random.Next(4, 8), drivingStyle); Function.Call(Hash.SET_PED_KEEP_TASK, driver, true); driver.MarkAsNoLongerNeeded(); newVehicle.MarkAsNoLongerNeeded(); diff --git a/BicycleCity/BicycleCity.ini b/BicycleCity/BicycleCity.ini index 10d59e8..f034483 100644 --- a/BicycleCity/BicycleCity.ini +++ b/BicycleCity/BicycleCity.ini @@ -2,3 +2,4 @@ BikesPercentage=50 AggressiveDrivers=false AggressiveCyclists=false +CyclistsBreakLaws=false diff --git a/README.md b/README.md index 99b0400..239c9a8 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Replace cars by bikes (GTA V mod) - Change `BikesPercentage` if you want more or less cars replaced by bikes - Set `AggressiveDrivers` to `true` if you want drivers to overtake slower vehicles - Set `AggressiveCyclists` to `true` if you want cyclists to overtake slower vehicles + - Set `CyclistsBreakLaws` to `true` if you want cyclists to break traffic laws ## Download https://github.com/oldnapalm/BicycleCity/releases/latest