Skip to content

Commit

Permalink
Merge pull request #12 from ToastinYou/dev
Browse files Browse the repository at this point in the history
update to latest citizenfx refs; added disabling of certain veh class…
  • Loading branch information
ToastinYou committed Jun 9, 2019
2 parents ec4ea72 + 47336ff commit ac71c19
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,6 +3,8 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

build/

# User-specific files
*.suo
*.user
Expand Down
8 changes: 4 additions & 4 deletions Client/Client.csproj
Expand Up @@ -31,9 +31,8 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="CitizenFX.Client">
<HintPath>.\CitizenFX.Client.dll</HintPath>
<Private>False</Private>
<Reference Include="CitizenFX.Core.Client, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CitizenFX.Core.Client.1.0.1305\lib\net45\CitizenFX.Core.Client.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -54,8 +53,9 @@
<None Include="Config.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="__resource.lua">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
64 changes: 31 additions & 33 deletions Client/Main.cs
Expand Up @@ -9,22 +9,19 @@ namespace Client
public class Main : BaseScript
{
private bool _cruising;
private float _rpm;
private readonly Control _cruiseKey;
private readonly iniconfig _config = new iniconfig(API.GetCurrentResourceName().ToString(), "Config.ini");
private readonly iniconfig _config = new iniconfig(API.GetCurrentResourceName(), "Config.ini");

public Main()
{
_cruiseKey = (Control)_config.GetIntValue("keybinds", "toggle", 168);

Debug.WriteLine($"{Common.Prefix} Cruise key: {(int) _cruiseKey}");
Debug.WriteLine($"{Common.Prefix} Resource name: {API.GetCurrentResourceName().ToString()}");

Tick += Process;
Debug.WriteLine($"{Common.Prefix} Resource name: {API.GetCurrentResourceName()}");
}

/*
List<VehicleClass> vehClassesWithoutCruiseControl = new List<VehicleClass>
private List<VehicleClass> _vehClassesWithoutCruiseControl = new List<VehicleClass>
{
VehicleClass.Cycles,
VehicleClass.Motorcycles,
Expand All @@ -34,57 +31,54 @@ public Main()
VehicleClass.Trains
};

*/

[Tick]
private async Task Process()
{
if (Game.PlayerPed.CurrentVehicle != null)
{ // In a veh.
Vehicle v = Game.PlayerPed.CurrentVehicle;
Vehicle v = Game.PlayerPed?.CurrentVehicle;

if (v != null)
{
Game.DisableControlThisFrame(0, _cruiseKey);

if ((Game.IsDisabledControlJustReleased(0, _cruiseKey) || Game.IsControlJustReleased(0, _cruiseKey)) &&
Game.CurrentInputMode == InputMode.MouseAndKeyboard && v.CurrentGear != 0) //vehClassesWithoutCruiseControl.IndexOf(_vehClass) != -1
{ // Cruise key just released using mouse&keyboard, NOT gamepad.

_cruising = !_cruising; // toggle cruising mode.
v.CurrentGear != 0 && !_vehClassesWithoutCruiseControl.Contains(v.ClassType)) // current gear of 0 is reverse.
{
_cruising = !_cruising;

if (_cruising)
{
CruiseAtSpeed(v.Speed);
_rpm = v.CurrentRPM;
}
}
}
else if (_cruising)
{
_cruising = false;
}
else
{ // Not in a veh, check periodically.
await Delay(1000);
await Delay(100);
}
}

private async void CruiseAtSpeed(float s)
{
while (_cruising)
{
if (Game.PlayerPed.CurrentVehicle == null)
{ // Current veh no longer exists, no longer in a veh, stop cruising.
_cruising = false;
break;
}
else
{ // Set speed of veh to the cruise speed infinently.
Vehicle v = Game.PlayerPed.CurrentVehicle;
Vehicle v = Game.PlayerPed?.CurrentVehicle;

v.Speed = s;
v.CurrentRPM = 0.5f;
if (v != null)
{
v.Speed = s; // try: void SetDriveTaskCruiseSpeed(int /* Ped */ driver, float cruiseSpeed);
v.CurrentRPM = _rpm;

if (v.IsInWater || v.IsInBurnout || !v.IsEngineRunning || v.Driver == null ||
v.Driver != Game.PlayerPed ||
if (v.Driver == null || v.Driver != Game.PlayerPed || v.IsInWater || v.IsInBurnout || !v.IsEngineRunning ||
v.IsInAir || v.HasCollided ||
GTASpeedToMPH(v.Speed) <= 25f || GTASpeedToMPH(v.Speed) >= 100f ||
HaveAnyTiresBurst(v) ||
Game.IsControlPressed(0, Control.VehicleHandbrake) ||
Game.IsControlPressed(0, Control.VehicleBrake))
Game.IsControlPressed(0, Control.VehicleHandbrake) || Game.IsDisabledControlPressed(0, Control.VehicleHandbrake) ||
Game.IsControlPressed(0, Control.VehicleBrake) || Game.IsDisabledControlPressed(0, Control.VehicleBrake))
{ // Disable cruise if any of these.... ^
_cruising = false;
}
Expand All @@ -95,6 +89,10 @@ private async void CruiseAtSpeed(float s)
AcceleratingToNewSpeed();
}
}
else
{
return;
}

await Delay(0);
}
Expand All @@ -108,7 +106,7 @@ private async void AcceleratingToNewSpeed()
Game.IsDisabledControlPressed(0, Control.VehicleAccelerate)) &&
Game.PlayerPed.CurrentVehicle != null)
{
await Delay(500); // Wait for client to stop accelerating.
await Delay(100); // Wait for client to stop accelerating.
}

if (Game.PlayerPed.CurrentVehicle != null)
Expand All @@ -119,7 +117,7 @@ private async void AcceleratingToNewSpeed()
}

/// <summary>
/// Converts GTA's speeds to MPH.
/// Converts GTA's speeds (meters per second) to MPH.
/// </summary>
private float GTASpeedToMPH(float s)
{
Expand Down
4 changes: 2 additions & 2 deletions Client/Properties/AssemblyInfo.cs
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.1.0")]
[assembly: AssemblyFileVersion("2.1.0")]
4 changes: 4 additions & 0 deletions Client/packages.config
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CitizenFX.Core.Client" version="1.0.1305" targetFramework="net452" />
</packages>
Binary file removed refs/CitizenFX.Client.dll
Binary file not shown.
Binary file removed refs/CitizenFX.Server.dll
Binary file not shown.

0 comments on commit ac71c19

Please sign in to comment.