Skip to content
This repository was archived by the owner on Dec 25, 2022. It is now read-only.

Commit c39f710

Browse files
committed
Added vehicle remote control
1 parent 13d217b commit c39f710

File tree

6 files changed

+95
-5
lines changed

6 files changed

+95
-5
lines changed

Client/Autopilot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static bool IsOwnedAutopilot(int driver)
115115
return IsAutopilot(driver) && API.DecorGetInt(driver, PlayerDecor) == API.PlayerId();
116116
}
117117

118-
private static async Task Spawn(int vehicle)
118+
public static async Task Spawn(int vehicle)
119119
{
120120
await Common.RequestModel(Model);
121121
var playerID = API.PlayerId();

Client/Main.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ private static void SetupMenu()
151151

152152
if (Permission.CanDo(Ability.TurboBoost))
153153
_menu.AddMenuListItem("Upgrade", "Turbo Boost (toggle)", UpgradeMenu.ToggleTurboBoost);
154+
155+
if (Permission.CanDo(Ability.RemoteControl))
156+
_menu.AddMenuListItem("Upgrade", "Remote control (toggle)", UpgradeMenu.ToggleRemoteControl);
154157
#endregion
155158

156159
#region Extra

Client/Menus/UpgradeMenu.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ public static void ToggleAntiGravity()
9393

9494
var state = Vehicles.IsFeatureEnabled(vehicle, Vehicles.FeatureFlag.AntiGravity);
9595
Vehicles.SetFeatureEnabled(vehicle, Vehicles.FeatureFlag.AntiGravity, !state);
96+
97+
if (!state)
98+
Common.Notification("Anti-gravity enabled");
99+
}
100+
101+
public static void ToggleRemoteControl()
102+
{
103+
if (!Common.EnsurePlayerIsVehicleDriver(out int player, out int vehicle))
104+
return;
105+
106+
var state = Vehicles.IsFeatureEnabled(vehicle, Vehicles.FeatureFlag.RemoteControl);
107+
Vehicles.SetFeatureEnabled(vehicle, Vehicles.FeatureFlag.RemoteControl, !state);
108+
109+
if (!state)
110+
Common.Notification("Remote control enabled (use arrow keys)");
96111
}
97112
}
98113
}

Client/Vehicles.cs

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public enum FeatureFlag
3434
{
3535
BackToTheFuture = 1,
3636
TurboBoost = 2,
37-
AntiGravity = 4
37+
AntiGravity = 4,
38+
RemoteControl = 8
3839
}
3940

4041
public enum Light
@@ -604,6 +605,15 @@ private static async Task UpdateEffects()
604605
}
605606
}
606607

608+
private static bool IsAnyRemoteControlPressed()
609+
{
610+
return
611+
API.IsControlPressed(0, 172) ||
612+
API.IsControlPressed(0, 173) ||
613+
API.IsControlPressed(0, 174) ||
614+
API.IsControlPressed(0, 175);
615+
}
616+
607617
private static Task UpdateControls()
608618
{
609619
var player = API.GetPlayerPed(-1);
@@ -616,9 +626,6 @@ private static Task UpdateControls()
616626

617627
if (API.IsPedInFlyingVehicle(player) && API.DecorExistOn(vehicle, AircraftHornDecor))
618628
{
619-
if (API.GetPedInVehicleSeat(vehicle, -1) != player || API.IsEntityDead(vehicle) || !API.DecorExistOn(vehicle, AircraftHornDecor))
620-
return Delay(1000);
621-
622629
if (API.IsControlJustPressed(0, 86)) // INPUT_VEH_HORN
623630
{
624631
TriggerServerEvent("PocceMod:ToggleHorn", API.VehToNet(vehicle), true);
@@ -651,6 +658,69 @@ private static Task UpdateControls()
651658
TriggerServerEvent("PocceMod:ToggleTurboBoost", API.VehToNet(vehicle), false);
652659
}
653660

661+
if (driver != player && IsFeatureEnabled(vehicle, FeatureFlag.RemoteControl) && IsAnyRemoteControlPressed())
662+
{
663+
if (API.IsVehicleSeatFree(vehicle, -1))
664+
return Autopilot.Spawn(vehicle);
665+
666+
var model = (uint)API.GetEntityModel(vehicle);
667+
if (API.IsThisModelAPlane(model) || API.IsThisModelAHeli(model))
668+
{
669+
var force = 1f;
670+
if (API.IsControlPressed(0, 172)) // up
671+
{
672+
API.ApplyForceToEntity(vehicle, 1, 0f, 0f, -force, 0f, 1f, 0f, -1, true, true, true, false, false);
673+
API.ApplyForceToEntity(vehicle, 1, 0f, 0f, force, 0f, -1f, 0f, -1, true, true, true, false, false);
674+
}
675+
else if (API.IsControlPressed(0, 173)) // down
676+
{
677+
API.ApplyForceToEntity(vehicle, 1, 0f, 0f, force, 0f, 1f, 0f, -1, true, true, true, false, false);
678+
API.ApplyForceToEntity(vehicle, 1, 0f, 0f, -force, 0f, -1f, 0f, -1, true, true, true, false, false);
679+
}
680+
681+
if (API.IsControlPressed(0, 174)) // left
682+
{
683+
API.ApplyForceToEntity(vehicle, 1, 0f, 0f, force, 1f, 0f, 0f, -1, true, true, true, false, false);
684+
API.ApplyForceToEntity(vehicle, 1, 0f, 0f, -force, -1f, 0f, 0f, -1, true, true, true, false, false);
685+
}
686+
else if (API.IsControlPressed(0, 175)) // right
687+
{
688+
API.ApplyForceToEntity(vehicle, 1, 0f, 0f, -force, 1f, 0f, 0f, -1, true, true, true, false, false);
689+
API.ApplyForceToEntity(vehicle, 1, 0f, 0f, force, -1f, 0f, 0f, -1, true, true, true, false, false);
690+
}
691+
692+
return Delay(33);
693+
}
694+
else // non-aircraft
695+
{
696+
if (API.IsControlPressed(0, 172)) // up
697+
{
698+
API.TaskVehicleTempAction(driver, vehicle, 9, 1);
699+
700+
if (API.IsControlPressed(0, 174)) // left
701+
API.TaskVehicleTempAction(driver, vehicle, 7, 1);
702+
else if (API.IsControlPressed(0, 175)) // right
703+
API.TaskVehicleTempAction(driver, vehicle, 8, 1);
704+
}
705+
else if (API.IsControlPressed(0, 173)) // down
706+
{
707+
API.TaskVehicleTempAction(driver, vehicle, 22, 1);
708+
709+
if (API.IsControlPressed(0, 174)) // left
710+
API.TaskVehicleTempAction(driver, vehicle, 13, 1);
711+
else if (API.IsControlPressed(0, 175)) // right
712+
API.TaskVehicleTempAction(driver, vehicle, 14, 1);
713+
}
714+
else
715+
{
716+
if (API.IsControlPressed(0, 174)) // left
717+
API.TaskVehicleTempAction(driver, vehicle, 4, 1);
718+
else if (API.IsControlPressed(0, 175)) // right
719+
API.TaskVehicleTempAction(driver, vehicle, 5, 1);
720+
}
721+
}
722+
}
723+
654724
return Task.FromResult(0);
655725
}
656726
}

Shared/Ability.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public enum Ability
3333
CompressVehicle,
3434
AntiGravity,
3535
TurboBoost,
36+
RemoteControl,
3637
Balloons,
3738
FreezePosition,
3839
IdentifySkins,

config/config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ BackToTheFuture=0
5757
CompressVehicle=0
5858
AntiGravity=0
5959
TurboBoost=0
60+
RemoteControl=0
6061
Balloons=0
6162
FreezePosition=0
6263
IdentifySkins=0

0 commit comments

Comments
 (0)