Skip to content

Commit

Permalink
Add CyclistsBreakLaws option
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed May 10, 2021
1 parent 487490a commit 145cfd5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
36 changes: 25 additions & 11 deletions BicycleCity/BicycleCity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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;
}
Expand All @@ -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<bool>(Hash.IS_ENTITY_A_MISSION_ENTITY, vehicle) &&
vehicle.Driver != null && !vehicle.Driver.IsPlayer)
!Function.Call<bool>(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;
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions BicycleCity/BicycleCity.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
BikesPercentage=50
AggressiveDrivers=false
AggressiveCyclists=false
CyclistsBreakLaws=false
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 145cfd5

Please sign in to comment.