4

I started to create a tiny Mod for GTA V, but I haven't found many Tutorials. The Mod is supposed to spawn a stretch-limo with a driver. When the limo is near me, I can enter the backseat with F-key and the driver will drive me to a waypoint.

At the moment, the vehicle and a driver are spawning when I press Num1. The Driver gets into the car and drives towards me. I tried to get into the backseat by doing

if (Game.Player.Character.GetVehicleIsTryingToEnter() == stretch && isEnteringCar == false)
        {
            isEnteringCar = true;
            Game.Player.Character.Task.EnterVehicle(stretch, VehicleSeat.RightRear);
            isEnteringCar = false;
        }

stretch is the object name for the limo I am spawning. "isEnteringCar" is a bool I've added, so the if, statement will only get executed once while entering the car. This if-statement is located in my onTick()-Method which gets executed every tick (obviously). But when I press F near my limo, my character gets stuck in some kind of infinite loop, even tho I tried to prevent that with my bool "isEnteringCar". The "Open Door"-Animation gets resetted every tick, therefore my character just wiggles around until I despawn the limo again.

So long story short:

When I press "F" to enter a spawned Limousine, a bool "IsEnteringCar" is set to true, so that the method Game.Player.Character.Task.EnterVehicle(stretch, VehicleSeat.RightRear); won't get executed multiple times. When I have successfully entered the vehicle, the bool gets set back to false, so I can enter the car again after getting out. But when I try to enter the car my character is stuck in the EnterVehicle()-Method, probably cause it interferes with the GTA-Code that makes me enter the vehicle at the driver seat. How can I disable the "Enter car at driver seat"-Part?

JavaGamer
  • 51
  • 8
  • 2
    I know nothing about GTA but ... can you attach a wait to `EnterVehicle` or check for a return value. If it fails or stalls then `isEntering` will be reset without the enter having happened. – Peter Smith Dec 17 '19 at 14:39

1 Answers1

1

You could try using the flags available inside the character Ped object to check if you are already inside a vehicle, you could also try with the method SetIntoVehicle instead of using a task e.g.:

if (!Game.Player.Character.IsGettingIntoVehicle && !Game.Player.Character.IsInVehicle())
{
    Game.Player.Character.SetIntoVehicle(stretch, VehicleSeat.RightRear);
}

Here is the relevant source assuming you are using ScriptHookVDotNet v3.0.2: https://github.com/crosire/scripthookvdotnet/blob/master/source/scripting_v3/GTA/Entities/Peds/Ped.cs

Isma
  • 14,604
  • 5
  • 37
  • 51