Advertisement
Guest User

GTA:IV C# vehicle spawn example.

a guest
Aug 17th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. /// <summary>
  2. /// Spawns a vehicle with a given name, a certain offset from the player.
  3. /// </summary>
  4. /// <param name="vehName">Name of the vehicle to spawn.</param>
  5. /// <param name="offsetPos">The offset position from the player. (Positive X is right, positive Y is front, positive Z is top)</param>
  6. /// <param name="headingOffset">The heading offset in degrees.</param>
  7. /// <returns>0 on success, 1 on failed spawn.</returns>
  8.         private int spawnVehExample(string vehName, Vector3 offsetPos, float headingOffset)
  9.         {
  10.             // Get the player heading.
  11.             float vehHeading = Player.Character.Heading;
  12.  
  13.             // Offset the heading.
  14.             vehHeading += headingOffset;
  15.  
  16.             // Get the spawn position.
  17.             Vector3 vehPos = Player.Character.GetOffsetPosition(offsetPos);
  18.  
  19.             // Spawn the vehicle.
  20.             GTA.Vehicle veh = World.CreateVehicle(vehName, vehPos);
  21.  
  22.             // Check if vehicle is spawned correctly.
  23.             if (veh == null || !veh.Exists())
  24.             {
  25.                 // Error code 1: failed to spawn vehicle!
  26.                 return 1;
  27.             }
  28.  
  29.             // Set heading.
  30.             veh.Heading = vehHeading;
  31.            
  32.             // Success
  33.             return 0;
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement