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
0 commit comments