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

Commit a9b92c8

Browse files
authored
Merge pull request #14 from inferno-collection/feature/1.5-alpha
Public Beta Version 1.5
2 parents 1b0075d + 462b8ba commit a9b92c8

8 files changed

Lines changed: 139 additions & 40 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Inferno Collection Vehicle Attachment 1.41 Beta
1+
# Inferno Collection Vehicle Attachment 1.5 Beta
22
#
33
# Copyright (c) 2019-2021, Christopher M, Inferno Collection. All rights reserved.
44
#

Client/Main.cs

Lines changed: 128 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Inferno Collection Vehicle Attachment 1.41 Beta
2+
* Inferno Collection Vehicle Attachment 1.5 Beta
33
*
44
* Copyright (c) 2019-2021, Christopher M, Inferno Collection. All rights reserved.
55
*
@@ -45,6 +45,7 @@ internal const string
4545

4646
#region General Variables
4747
internal bool
48+
_driveOn,
4849
_goFaster,
4950
_goSlower;
5051

@@ -67,7 +68,7 @@ public Main()
6768
throw new Exception("This resource requires at least OneSync \"legacy\". Use Public Beta Version 1.3 if you do not want to use OneSync.");
6869
}
6970

70-
TriggerEvent("chat:addSuggestion", "/attach [help|cancel]", "Starts the process of attaching one vehicle to another.");
71+
TriggerEvent("chat:addSuggestion", "/attach [driveon|help|cancel]", "Starts the process of attaching one vehicle to another.");
7172
TriggerEvent("chat:addSuggestion", "/detach [help|cancel]", "Starts the process of detaching one vehicle from another.");
7273

7374
#region Key Mapping
@@ -133,6 +134,12 @@ internal void OnAttach(string[] args)
133134
{
134135
ShowTowControls();
135136
}
137+
else if (args[0] == "driveon")
138+
{
139+
_driveOn = !_driveOn;
140+
141+
Screen.ShowNotification($"~o~Drive On mode {(_driveOn ? "~g~enabled" : "~r~disabled")}", true);
142+
}
136143
else if (args[0] == "cancel")
137144
{
138145
if (_attachmentStage != AttachmentStage.None)
@@ -290,15 +297,32 @@ internal void OnRemoveLastAttachment()
290297
_tempTowVehicle = towVehicle;
291298
_tempVehicleBeingTowed = vehicleBeingTowed;
292299

293-
ShowTowControls();
300+
Game.PlaySound("TOGGLE_ON", "HUD_FRONTEND_DEFAULT_SOUNDSET");
294301

295-
_tempVehicleBeingTowed.Opacity = 225;
302+
if (_driveOn)
303+
{
304+
Screen.ShowNotification($"~g~{_tempVehicleBeingTowed.LocalizedName ?? "Vehicle"} detached, drive it off.");
296305

297-
_attachmentStage = AttachmentStage.Detach;
298-
Tick += AttachmentTick;
306+
ResetTowedVehicle(_tempVehicleBeingTowed);
307+
SetVehicleAsBeingUsed(_tempVehicleBeingTowed, false);
308+
RemoveTowedVehicle(_tempTowVehicle, _tempVehicleBeingTowed);
299309

300-
Game.PlaySound("TOGGLE_ON", "HUD_FRONTEND_DEFAULT_SOUNDSET");
301-
Screen.ShowNotification("~g~Follow the instructions to detach the vehicle.");
310+
_tempTowVehicle = null;
311+
_tempVehicleBeingTowed = null;
312+
313+
Game.PlaySound("WAYPOINT_SET", "HUD_FRONTEND_DEFAULT_SOUNDSET");
314+
}
315+
else
316+
{
317+
ShowTowControls();
318+
319+
_tempVehicleBeingTowed.Opacity = 225;
320+
321+
_attachmentStage = AttachmentStage.Detach;
322+
Tick += AttachmentTick;
323+
324+
Screen.ShowNotification("~g~Follow the instructions to detach the vehicle.");
325+
}
302326
}
303327
}
304328
}
@@ -433,28 +457,45 @@ internal async Task AttachmentTick()
433457
else
434458
{
435459
Game.PlaySound("OK", "HUD_FRONTEND_DEFAULT_SOUNDSET");
436-
Screen.ShowNotification($"~g~{vehicleToBeTowed.LocalizedName ?? "vehicle"} confirmed as vehicle to be towed! Follow instructions to position vehicle.");
437460

438-
ShowTowControls();
461+
if (_driveOn)
462+
{
463+
Screen.ShowNotification($"~g~{vehicleToBeTowed.LocalizedName ?? "vehicle"} confirmed as vehicle to be towed! Drive on then confirm.");
464+
465+
vehicleToBeTowed.IsPersistent = true;
466+
467+
AddNewTowedVehicle(_tempTowVehicle, new TowedVehicle() { NetworkId = vehicleToBeTowed.NetworkId });
439468

440-
vehicleToBeTowed.Opacity = 225;
441-
vehicleToBeTowed.IsPersistent = true;
442-
vehicleToBeTowed.IsPositionFrozen = true;
443-
vehicleToBeTowed.IsCollisionEnabled = false;
444-
vehicleToBeTowed.LockStatus = VehicleLockStatus.CannotBeTriedToEnter;
445-
vehicleToBeTowed.AttachTo(_tempTowVehicle, POSITION_VECTOR, ROTATION_VECTOR);
469+
_tempVehicleBeingTowed = vehicleToBeTowed;
470+
_attachmentStage = AttachmentStage.DriveOn;
446471

447-
AddNewTowedVehicle(_tempTowVehicle, new TowedVehicle()
472+
await Delay(1000);
473+
}
474+
else
448475
{
449-
NetworkId = vehicleToBeTowed.NetworkId,
450-
AttachmentPosition = POSITION_VECTOR,
451-
AttachmentRotation = ROTATION_VECTOR
452-
});
476+
Screen.ShowNotification($"~g~{vehicleToBeTowed.LocalizedName ?? "vehicle"} confirmed as vehicle to be towed! Follow instructions to position vehicle.");
453477

454-
_tempVehicleBeingTowed = vehicleToBeTowed;
455-
_attachmentStage = AttachmentStage.Position;
478+
ShowTowControls();
456479

457-
await Delay(1000);
480+
vehicleToBeTowed.Opacity = 225;
481+
vehicleToBeTowed.IsPersistent = true;
482+
vehicleToBeTowed.IsPositionFrozen = true;
483+
vehicleToBeTowed.IsCollisionEnabled = false;
484+
vehicleToBeTowed.LockStatus = VehicleLockStatus.CannotBeTriedToEnter;
485+
vehicleToBeTowed.AttachTo(_tempTowVehicle, POSITION_VECTOR, ROTATION_VECTOR);
486+
487+
AddNewTowedVehicle(_tempTowVehicle, new TowedVehicle()
488+
{
489+
NetworkId = vehicleToBeTowed.NetworkId,
490+
AttachmentPosition = POSITION_VECTOR,
491+
AttachmentRotation = ROTATION_VECTOR
492+
});
493+
494+
_tempVehicleBeingTowed = vehicleToBeTowed;
495+
_attachmentStage = AttachmentStage.Position;
496+
497+
await Delay(1000);
498+
}
458499
}
459500
}
460501
}
@@ -504,6 +545,12 @@ internal async Task AttachmentTick()
504545
break;
505546
#endregion
506547

548+
#region Drive On
549+
case AttachmentStage.DriveOn:
550+
Screen.DisplayHelpTextThisFrame("~INPUT_FRONTEND_RDOWN~ to confirm position");
551+
break;
552+
#endregion
553+
507554
#region Position/Detach
508555
default:
509556
if (Game.IsControlPressed(0, Control.Sprint))
@@ -555,16 +602,20 @@ internal async void ResetTowedVehicle(Entity entity)
555602

556603
vehicle.Opacity = 0;
557604
vehicle.Detach();
558-
559-
position = vehicle.Position;
560605

561-
vehicle.PlaceOnGround();
562-
vehicle.IsCollisionEnabled = true;
563-
vehicle.IsPositionFrozen = false;
606+
if (!_driveOn)
607+
{
608+
position = vehicle.Position;
609+
610+
vehicle.PlaceOnGround();
611+
vehicle.IsCollisionEnabled = true;
612+
vehicle.IsPositionFrozen = false;
564613

565-
await Delay(1000);
614+
await Delay(1000);
615+
616+
vehicle.Position = position;
617+
}
566618

567-
vehicle.Position = position;
568619
vehicle.ResetOpacity();
569620
vehicle.LockStatus = VehicleLockStatus.Unlocked;
570621
vehicle.ApplyForce(new Vector3(0.0f, 0.0f, 0.001f));
@@ -596,6 +647,52 @@ internal void OnControl(AttachmentControl attachmentControl)
596647
{
597648
if (_attachmentStage != AttachmentStage.Position && _attachmentStage != AttachmentStage.Detach)
598649
{
650+
if (_attachmentStage != AttachmentStage.DriveOn || attachmentControl != AttachmentControl.Confirm)
651+
{
652+
return;
653+
}
654+
655+
TowedVehicle towedVehicle = GetTowedVehicles(_tempTowVehicle).Last();
656+
657+
if (_tempTowVehicle.Position.DistanceToSquared(_tempVehicleBeingTowed.Position) > _config.MaxDistanceFromTowVehicle)
658+
{
659+
Screen.ShowNotification("~r~Cannot attach there, too far from tow vehicle!", true);
660+
return;
661+
}
662+
663+
if (Game.PlayerPed.CurrentVehicle == _tempVehicleBeingTowed)
664+
{
665+
Game.PlayerPed.Task.LeaveVehicle();
666+
}
667+
668+
Vector3
669+
position = _tempTowVehicle.GetPositionOffset(_tempVehicleBeingTowed.Position),
670+
rotation = _tempVehicleBeingTowed.Rotation - _tempTowVehicle.Rotation;
671+
672+
_tempVehicleBeingTowed.LockStatus = VehicleLockStatus.CannotBeTriedToEnter;
673+
_tempVehicleBeingTowed.AttachTo(_tempTowVehicle, position, rotation);
674+
675+
TowedVehicle updatedTowedVehicle = new TowedVehicle()
676+
{
677+
NetworkId = towedVehicle.NetworkId,
678+
AttachmentPosition = position,
679+
AttachmentRotation = rotation
680+
};
681+
682+
UpdateTowedVehicle(_tempTowVehicle, _tempVehicleBeingTowed, updatedTowedVehicle);
683+
684+
SetVehicleAsBeingUsed(_tempTowVehicle, false);
685+
SetVehicleAsBeingUsed(_tempVehicleBeingTowed, false);
686+
687+
Screen.ShowNotification("~g~Attachment complete! Drive safe.");
688+
689+
_tempTowVehicle = null;
690+
_tempVehicleBeingTowed = null;
691+
692+
Game.PlaySound("WAYPOINT_SET", "HUD_FRONTEND_DEFAULT_SOUNDSET");
693+
694+
Tick -= AttachmentTick;
695+
_attachmentStage = AttachmentStage.None;
599696
return;
600697
}
601698

Client/Models/AttachmentStage.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Inferno Collection Vehicle Attachment 1.41 Beta
2+
* Inferno Collection Vehicle Attachment 1.5 Beta
33
*
44
* Copyright (c) 2019-2021, Christopher M, Inferno Collection. All rights reserved.
55
*
@@ -19,6 +19,7 @@ public enum AttachmentStage
1919
TowTruck,
2020
VehicleToBeTowed,
2121
Position,
22+
DriveOn,
2223
Detach,
2324
Cancel
2425
}

Client/Models/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Inferno Collection Vehicle Attachment 1.41 Beta
2+
* Inferno Collection Vehicle Attachment 1.5 Beta
33
*
44
* Copyright (c) 2019-2021, Christopher M, Inferno Collection. All rights reserved.
55
*

Client/Models/TowedVehicle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Inferno Collection Vehicle Attachment 1.41 Beta
2+
* Inferno Collection Vehicle Attachment 1.5 Beta
33
*
44
* Copyright (c) 2019-2021, Christopher M, Inferno Collection. All rights reserved.
55
*

Client/fxmanifest.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Inferno Collection Vehicle Attachment 1.41 Beta
1+
-- Inferno Collection Vehicle Attachment 1.5 Beta
22
--
33
-- Copyright (c) 2019-2021, Christopher M, Inferno Collection. All rights reserved.
44
--
@@ -15,7 +15,7 @@ description "A lightweight vehicle attachment/tow script for FiveM."
1515

1616
author "Inferno Collection (inferno-collection.com)"
1717

18-
version "1.41 Beta"
18+
version "1.5 Beta"
1919

2020
url "https://inferno-collection.com"
2121

LICENCE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Inferno Collection Vehicle Attachment 1.41 Beta
1+
Inferno Collection Vehicle Attachment 1.5 Beta
22

33
Copyright (c) 2019-2021, Christopher M, Inferno Collection. All rights reserved.
44

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Inferno Collection: Vehicle Attachment
33
[![Build Status](https://travis-ci.com/inferno-collection/Vehicle-Attachment.svg?branch=master)](https://travis-ci.com/inferno-collection/Vehicle-Attachment)
44

5-
__Public Beta Version 1.41__
5+
__Public Beta Version 1.5__
66

77
A lightweight vehicle attachment/tow script for FiveM. Attach vehicles to other vehicles and adjust the positioning with easy to use keybinds. Multiple attachments to the same vehicles (such as a flatbed trailer) are also possible.
88

@@ -17,9 +17,10 @@ Presently, the following can be customized:
1717
- Max number of vehicles attached to one tow vehicle
1818
- Max distance from tow vehicles other vehicles can be attached.
1919
- Control over how fast/slow attachment positioning is.
20+
- Option to drive vehicles onto towing vehicle to confirm position (`/attach driveon`)
2021

2122
Usage:
22-
- Go up to a vehicle and type `/attach`
23+
- Go up to a vehicle and type `/attach` or `/attach driveon`
2324
- Select the tow vehicle, and then vehicle to be towed with the `Enter` key
2425
- Follow on screen instructions to position the vehicle
2526
- Repeat for as many vehicles as you would like to attach

0 commit comments

Comments
 (0)