internal static ComputerPlusEntity LookupVehicle(Vehicle vehicle)
        {
            if (!vehicle)
            {
                return(null);
            }
            var vehiclePersona = ComputerPlusEntity.GetPersonaForVehicle(vehicle);

            string             ownerName = Functions.GetVehicleOwnerName(vehicle);
            ComputerPlusEntity owner     = null;
            var driver = vehicle.HasDriver ? vehicle.Driver : null;

            if (driver != null)
            {
                Persona driverPersona = Functions.GetPersonaForPed(driver);
                if (!driverPersona.FullName.Equals(ownerName))
                {
                    owner = ComputerPedController.Instance.LookupPersona(ownerName);
                    if (owner == null)
                    {
                        owner = generateVehicleOwner(ownerName);
                    }
                }
                else
                {
                    owner = ComputerPedController.Instance.LookupPersona(driver);
                }
            }
            else
            {
                owner = ComputerPedController.Instance.LookupPersona(ownerName);
                if (owner == null)
                {
                    owner = generateVehicleOwner(ownerName);
                }
            }
            return(ComputerPlusEntity.CloneFrom(owner, vehicle, vehiclePersona));
        }
Exemple #2
0
        internal static ComputerPlusEntity LookupVehicle(Vehicle vehicle)
        {
            if (!vehicle)
            {
                return(null);
            }
            var vehiclePersona = ComputerPlusEntity.GetPersonaForVehicle(vehicle);

            if (Function.IsTrafficPolicerRunning())
            {
                vehiclePersona.HasInsurance = TrafficPolicerFunction.GetVehicleInsuranceStatus(vehicle) == EVehicleStatus.Valid ? true : false;
                vehiclePersona.IsRegistered = TrafficPolicerFunction.GetVehicleRegistrationStatus(vehicle) == EVehicleStatus.Valid ? true : false;
            }

            var ownerName = Functions.GetVehicleOwnerName(vehicle);

            var driver = vehicle.HasDriver ? vehicle.Driver : null;
            ComputerPlusEntity owner = ComputerPedController.Instance.LookupPersona(ownerName);

            if (owner == null && driver != null)
            {
                owner = ComputerPedController.Instance.LookupPersona(driver);
            }
            else
            {
                while (owner == null)
                {
                    //Last ditch effort to make C+ happy by just providing any ped as the owner and setting them as the owner
                    var ped = FindRandomPed();
                    owner = ComputerPlusEntity.CreateFrom(ped);
                }
            }

            if (!owner.Validate())
            {
                var parts = ownerName.Split(' ');
                while (parts.Length < 2)
                {
                    parts = LSPD_First_Response.Engine.Scripting.Entities.Persona.GetRandomFullName().Split(' ');
                }
                Functions.SetVehicleOwnerName(vehicle, String.Format("{0} {1}", parts[0], parts[1]));
                //Work some magic to fix the fact that the ped hasn't been spawned in game
                //@TODO parse ped model name for age group and randomize other props

                var ped = FindRandomPed();


                var persona = new Persona(
                    ped,
                    Gender.Random,
                    RandomDay(),
                    3,
                    parts[0],
                    parts[1],
                    ELicenseState.Valid,
                    1,
                    false,
                    false,
                    false
                    );
                Functions.SetPersonaForPed(ped, persona);
            }


            return(ComputerPlusEntity.CloneFrom(owner, vehicle, vehiclePersona));
        }