diff --git a/TASK/TaskWarpPedIntoVehicle.md b/TASK/TaskWarpPedIntoVehicle.md index 149caee90..040e544f0 100644 --- a/TASK/TaskWarpPedIntoVehicle.md +++ b/TASK/TaskWarpPedIntoVehicle.md @@ -21,75 +21,110 @@ Warp a ped into a vehicle. ## Examples ```lua --- Get the player's ped ID +-- This example creates a vehicle and warps the player into the driver's seat + +-- Retrieve the player ped local playerPed = PlayerPedId() --- Check if the model exist in the game for the client -local modelHash = `adder` -- Use Compile-time hashes to get the hash of this model +-- Define the vehicle model and check if it exists in the game files +local modelHash = `adder` -- Use Compile-time hashes to get the model hash if not IsModelInCdimage(modelHash) then return end -RequestModel(modelHash) -- Request the model +-- Request the model and wait for it to load +RequestModel(modelHash) repeat - Wait(0) -- Wait until the model is loaded + Wait(0) until HasModelLoaded(modelHash) -- Create the vehicle at the player's coordinates with a heading of 0.0 local coordsPlayer, heading = GetEntityCoords(playerPed), 0.0 local vehicle = CreateVehicle(modelHash, coordsPlayer, heading, true, false) -local seatIndex = -1 -- -1 for driver seat +-- Define the seat index for the Ped (e.g., -1 for the driver's seat) +local seatIndex = -1 + +-- Check if the vehicle exists and the player is alive +if not DoesEntityExist(vehicle) or IsEntityDead(playerPed) then + return +end -if not DoesEntityExist(vehicle) or IsEntityDead(playerPed) then return end -- Check if the vehicle exist and if the player is not dead --- Warp the ped into the specified vehicle at the designated seat +-- Warp the Ped into the specified vehicle seat TaskWarpPedIntoVehicle(playerPed, vehicle, seatIndex) ``` ```js -// Get the player's ped ID +// This example creates a vehicle and warps the player into the driver's seat + +// Retrieve the player ped const playerPed = PlayerPedId(); -// Check if the model exist in the game for the client -const modelHash = GetHashKey('adder'); // Use Compile-time hashes to get the hash of this model -if (!IsModelInCdimage(modelHash)) return; +// Define the vehicle model and check if it exists in the game files +const modelHash = GetHashKey("adder"); +if (!IsModelInCdimage(modelHash)) { + return; +} -RequestModel(modelHash); // Request the model -while (!HasModelLoaded(modelHash)) Wait(0); // Wait until the model is loaded +// Request the model and wait for it to load +RequestModel(modelHash); +while (!HasModelLoaded(modelHash)) { + Wait(0); +} // Create the vehicle at the player's coordinates with a heading of 0.0 const coordsPlayer = GetEntityCoords(playerPed); const heading = 0.0; const vehicle = CreateVehicle(modelHash, coordsPlayer, heading, true, false); -const seatIndex = -1; // -1 for driver seat +// Define the seat index for the Ped (e.g., -1 for the driver's seat) +const seatIndex = -1; + +// Check if the vehicle exists and the player is alive +if (!DoesEntityExist(vehicle) || IsEntityDead(playerPed)) { + return; +} -if (!DoesEntityExist(vehicle) || IsEntityDead(playerPed)) return; // Check if the vehicle exist and if the player is not dead -// Warp the ped into the specified vehicle at the designated seat +// Warp the Ped into the specified vehicle seat TaskWarpPedIntoVehicle(playerPed, vehicle, seatIndex); ``` ```cs +// This example creates a vehicle and warps the player into the driver's seat using static CitizenFX.Core.Native.API; -// Get the player's ped ID +// Retrieve the player ped Ped playerPed = PlayerPedId(); -// Check if the model exist in the game for the client +// Define the vehicle model and check if it exists in the game files uint modelHash = (uint)GetHashKey("adder"); -if (!IsModelInCdimage(modelHash)) return; -RequestModel(modelHash); // Request the model -while (!HasModelLoaded(modelHash)) Delay(0); // Wait until the model is loaded +if (!IsModelInCdimage(modelHash)) +{ + return; +} + +// Request the model and wait for it to load +RequestModel(modelHash); +while (!HasModelLoaded(modelHash)) +{ + Delay(0); +} // Create the vehicle at the player's coordinates with a heading of 0.0 Vector3 coordsPlayer = GetEntityCoords(playerPed); float heading = 0.0f; Vehicle vehicle = CreateVehicle(modelHash, coordsPlayer, heading, true, false); -int seatIndex = -1; // -1 for driver seat +// Define the seat index for the Ped (e.g., -1 for the driver's seat) +int seatIndex = -1; + +// Check if the vehicle exists and the player is alive +if (!DoesEntityExist(vehicle) || IsEntityDead(playerPed)) +{ + return; +} -if (!DoesEntityExist(vehicle) || IsEntityDead(playerPed)) return; // Check if the vehicle exist and if the player is not dead -// Warp the ped into the specified vehicle at the designated seat +// Warp the Ped into the specified vehicle seat TaskWarpPedIntoVehicle(playerPed, vehicle, seatIndex); ``` \ No newline at end of file