Skip to content

Commit a419403

Browse files
committed
Add CantFallFromBike option
1 parent 6ba60df commit a419403

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

BicycleCity/BicycleCity.cs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,33 @@ namespace BicycleCity
1010
{
1111
public class BicycleCity : Script
1212
{
13-
int bikesPercentage;
14-
bool aggressiveDrivers;
15-
bool aggressiveCyclists;
16-
bool cyclistsBreakLaws;
17-
bool cheeringCrowds;
18-
int cheeringCrowdsSlope;
19-
bool stopPedAttacks;
20-
int lastTime = Environment.TickCount;
21-
int lastPaparazzi = Environment.TickCount;
22-
List<Ped> fans = new List<Ped>();
23-
string[] availableBicycles = { "BMX", "CRUISER", "FIXTER", "SCORCHER", "TRIBIKE", "TRIBIKE2", "TRIBIKE3" };
24-
VehicleDrivingFlags aggressiveDrivingStyle = VehicleDrivingFlags.AvoidEmptyVehicles |
25-
VehicleDrivingFlags.AvoidObjects |
26-
VehicleDrivingFlags.AvoidPeds |
27-
VehicleDrivingFlags.AvoidVehicles |
28-
VehicleDrivingFlags.StopAtTrafficLights;
29-
VehicleDrivingFlags lawBreakerDrivingStyle = VehicleDrivingFlags.AllowGoingWrongWay |
30-
VehicleDrivingFlags.AllowMedianCrossing |
31-
VehicleDrivingFlags.AvoidEmptyVehicles |
32-
VehicleDrivingFlags.AvoidObjects |
33-
VehicleDrivingFlags.AvoidVehicles;
13+
private readonly int bikesPercentage;
14+
private readonly bool aggressiveDrivers;
15+
private readonly bool aggressiveCyclists;
16+
private readonly bool cyclistsBreakLaws;
17+
private readonly bool cheeringCrowds;
18+
private readonly int cheeringCrowdsSlope;
19+
private readonly bool stopPedAttacks;
20+
private readonly bool cantFallFromBike;
21+
private int lastTime = Environment.TickCount;
22+
private int lastPaparazzi = Environment.TickCount;
23+
private readonly List<Ped> fans = new List<Ped>();
24+
private readonly string[] availableBicycles = { "BMX", "CRUISER", "FIXTER", "SCORCHER", "TRIBIKE", "TRIBIKE2", "TRIBIKE3" };
25+
private readonly VehicleDrivingFlags aggressiveDrivingStyle = VehicleDrivingFlags.AvoidEmptyVehicles |
26+
VehicleDrivingFlags.AvoidObjects |
27+
VehicleDrivingFlags.AvoidPeds |
28+
VehicleDrivingFlags.AvoidVehicles |
29+
VehicleDrivingFlags.StopAtTrafficLights;
30+
private readonly VehicleDrivingFlags lawBreakerDrivingStyle = VehicleDrivingFlags.AllowGoingWrongWay |
31+
VehicleDrivingFlags.AllowMedianCrossing |
32+
VehicleDrivingFlags.AvoidEmptyVehicles |
33+
VehicleDrivingFlags.AvoidObjects |
34+
VehicleDrivingFlags.AvoidVehicles;
3435

3536
public BicycleCity()
3637
{
3738
ScriptSettings settings = ScriptSettings.Load(@".\Scripts\BicycleCity.ini");
38-
bikesPercentage = settings.GetValue("Main", "BikesPercentage", 50);
39+
bikesPercentage = settings.GetValue("Main", "BikesPercentage", 0);
3940
if (bikesPercentage < 0) bikesPercentage = 0;
4041
if (bikesPercentage > 100) bikesPercentage = 100;
4142
aggressiveDrivers = settings.GetValue("Main", "AggressiveDrivers", false);
@@ -44,11 +45,12 @@ public BicycleCity()
4445
cheeringCrowds = settings.GetValue("Main", "CheeringCrowds", true);
4546
cheeringCrowdsSlope = settings.GetValue("Main", "CheeringCrowdsSlope", 8);
4647
stopPedAttacks = settings.GetValue("Main", "StopPedAttacks", false);
48+
cantFallFromBike = settings.GetValue("Main", "CantFallFromBike", true);
4749
Tick += OnTick;
4850
Aborted += OnAbort;
4951
}
5052

51-
void OnTick(object sender, EventArgs e)
53+
private void OnTick(object sender, EventArgs e)
5254
{
5355
if (Environment.TickCount >= lastTime + 1000)
5456
{
@@ -152,7 +154,7 @@ void OnTick(object sender, EventArgs e)
152154
{
153155
if (fan != null)
154156
{
155-
if (fan.Position.DistanceTo(Game.Player.Character.Position) > 150f || isEnemy(fan))
157+
if (fan.Position.DistanceTo(Game.Player.Character.Position) > 150f || IsEnemy(fan))
156158
{
157159
fan.Delete();
158160
fans.Remove(fan);
@@ -165,7 +167,7 @@ void OnTick(object sender, EventArgs e)
165167

166168
if (stopPedAttacks)
167169
foreach (Ped ped in World.GetNearbyPeds(Game.Player.Character, 100f))
168-
if (isEnemy(ped))
170+
if (IsEnemy(ped))
169171
ped.Delete();
170172

171173
lastTime = Environment.TickCount;
@@ -175,14 +177,17 @@ void OnTick(object sender, EventArgs e)
175177
foreach (Ped fan in fans)
176178
if (fan != null && !fan.IsRunning)
177179
fan.Heading = (Game.Player.Character.Position - fan.Position).ToHeading();
180+
181+
if (cantFallFromBike)
182+
Function.Call(Hash.SET_PED_CAN_BE_KNOCKED_OFF_VEHICLE, Game.Player.Character, 1);
178183
}
179184

180-
bool isEnemy(Ped ped)
185+
private bool IsEnemy(Ped ped)
181186
{
182187
return (ped.GetRelationshipWithPed(Game.Player.Character) == Relationship.Hate && ped.IsHuman) || ped.IsInCombat || ped.IsInMeleeCombat || ped.IsShooting;
183188
}
184189

185-
void OnAbort(object sender, EventArgs e)
190+
private void OnAbort(object sender, EventArgs e)
186191
{
187192
Tick -= OnTick;
188193

BicycleCity/BicycleCity.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[Main]
2-
BikesPercentage=50
2+
BikesPercentage=0
33
AggressiveDrivers=false
44
AggressiveCyclists=false
55
CyclistsBreakLaws=false
66
CheeringCrowds=true
77
CheeringCrowdsSlope=8
88
StopPedAttacks=false
9+
CantFallFromBike=true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Replace cars by bikes (GTA V mod)
1212
- **CheeringCrowds** - cheering peds will be spawned on climbs
1313
- **CheeringCrowdsSlope** - minimum slope for cheering crowds
1414
- **StopPedAttacks** - attacking peds will be removed
15+
- **CantFallFromBike** - player can't be knocked off the bike
1516

1617
## Download
1718
https://github.com/oldnapalm/BicycleCity/releases/latest

0 commit comments

Comments
 (0)