22using Newtonsoft . Json . Linq ;
33using System ;
44using System . Linq ;
5+ using Rocket . Unturned . Player ;
6+ using SDG . Unturned ;
57using Tavstal . TShop . Models ;
68using UnityEngine ;
79
@@ -99,7 +101,7 @@ public static string GetVehiclesInJson()
99101 /// <exception cref="Exception">
100102 /// Logs an error if there is an issue retrieving the vehicle spawn modifier.
101103 /// </exception>
102- public static Vector3 GetVehicleSpawnModifier ( )
104+ private static Vector3 GetVehicleSpawnModifier ( )
103105 {
104106 try
105107 {
@@ -110,7 +112,23 @@ public static Vector3 GetVehicleSpawnModifier()
110112 TShop . Logger . LogError ( "Failed to get vehicle spawn modifier. Using default value..." ) ;
111113 }
112114
113- return new Vector3 ( 0 , 5 , 0 ) ;
115+ return new Vector3 ( 0 , 5 , 5 ) ;
116+ }
117+
118+ /// <summary>
119+ /// Spawns a vehicle owned by the specified player at the player's current position,
120+ /// rotated to match the direction the player is looking.
121+ /// </summary>
122+ /// <param name="id">The ID of the vehicle to spawn.</param>
123+ /// <param name="owner">The player who will own the spawned vehicle.</param>
124+ /// <returns>
125+ /// The spawned <see cref="InteractableVehicle"/> instance.
126+ /// </returns>
127+ public static InteractableVehicle SpawnOwnedVehicle ( ushort id , UnturnedPlayer owner )
128+ {
129+ Quaternion playerRotation = Quaternion . LookRotation ( owner . Player . look . aim . forward ) ;
130+ Vector3 spawnPosition = owner . Position + ( playerRotation * GetVehicleSpawnModifier ( ) ) ;
131+ return VehicleManager . spawnLockedVehicleForPlayerV2 ( id , spawnPosition , owner . Player . transform . rotation , owner . Player ) ;
114132 }
115133 }
116134}
0 commit comments