Skip to content

Commit

Permalink
Add CantFallFromBike option
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Dec 21, 2021
1 parent 6ba60df commit a419403
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
59 changes: 32 additions & 27 deletions BicycleCity/BicycleCity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ped> fans = new List<Ped>();
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<Ped> fans = new List<Ped>();
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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion BicycleCity/BicycleCity.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[Main]
BikesPercentage=50
BikesPercentage=0
AggressiveDrivers=false
AggressiveCyclists=false
CyclistsBreakLaws=false
CheeringCrowds=true
CheeringCrowdsSlope=8
StopPedAttacks=false
CantFallFromBike=true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a419403

Please sign in to comment.