コード例 #1
0
 private void EndDestination()
 {
     _currentDestination = null;
     API.DeleteEntity(ref _truckTrailer);
     _truckTrailer = -1;
     API.RemoveBlip(ref destBlip);
 }
コード例 #2
0
        private async Task SetupDestination(TruckingDestination dest, LoadTypes type)
        {
            _currentDestination = dest;
            var ped = Game.PlayerPed.Handle;

            Game.PlayerPed.CurrentVehicle.Position = new Vector3(807.68005371094f, -3040.2846679688f, 5.7421259880066f);
            var truck  = "Trailers2";
            var rdm    = new Random();
            var rdmInt = rdm.Next(3);

            //Determine the traielr to use.
            switch (type)
            {
            case LoadTypes.Trailer:
                rdmInt = rdm.Next(3);
                switch (rdmInt)
                {
                case 1:
                    truck = "Trailers";
                    break;

                case 2:
                    truck = "Trailers2";
                    break;

                case 3:
                    truck = "Trailers3";
                    break;
                }
                break;

            case LoadTypes.Tanker:
                rdmInt = rdm.Next(2);
                switch (rdmInt)
                {
                case 1:
                    truck = "Tanker";
                    break;

                case 2:
                    truck = "Tanker2";
                    break;
                }
                break;

            case LoadTypes.Logs:
                truck = "TrailerLogs";
                break;

            case LoadTypes.DockTrailer:
                truck = "DockTrailer";
                break;

            case LoadTypes.Cars:
                truck = "TR4";
                break;

            case LoadTypes.Boat:
                truck = "TR3";
                break;
            }
            var vehicle = (uint)API.GetHashKey(truck);

            API.RequestModel(vehicle);
            while (!API.HasModelLoaded(vehicle))
            {
                await Delay(1);
            }
            var coords = API.GetOffsetFromEntityInWorldCoords(ped, 0, -5.0f, 0);

            _truckTrailer = API.CreateVehicle(vehicle, coords.X, coords.Y, coords.Z, API.GetEntityHeading(ped), true,
                                              false);
            API.SetEntityAsMissionEntity(_truckTrailer, true, true);
            API.SetVehicleOnGroundProperly(_truckTrailer);
            API.SetModelAsNoLongerNeeded(vehicle);
            var trailirBlip = API.AddBlipForEntity(_truckTrailer);

            API.SetBlipAsFriendly(trailirBlip, true);
            API.SetBlipSprite(trailirBlip, 225);
            API.SetBlipColour(trailirBlip, 3);
            API.BeginTextCommandSetBlipName("STRING");
            API.AddTextComponentString("Trailer");
            API.EndTextCommandSetBlipName(trailirBlip);

            API.AttachVehicleToTrailer(Game.PlayerPed.CurrentVehicle.Handle, _truckTrailer, 10);

            destBlip = API.AddBlipForCoord(dest.X, dest.Y, dest.Z);
            API.SetBlipSprite(destBlip, 315);
            API.SetBlipColour(destBlip, 5);
            API.SetBlipScale(destBlip, 0.5f);
            API.SetBlipAsShortRange(destBlip, true);
            API.BeginTextCommandSetBlipName("STRING");
            API.AddTextComponentString("Trucking Destination");
            API.EndTextCommandSetBlipName(destBlip);
            API.SetBlipRoute(destBlip, true);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
            TrailerCheck();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
        }