private async Task StartDelivery(DeliveryType aDeliveryType) { SavePlayerSkin(); LoadWorkPlayerSkin(aDeliveryType); RequestModel((uint)GetHashKey("prop_paper_bag_01")); await SpawnDeliveryVehicle(aDeliveryType); m_delivery_state = DELIVERY_STATE.PLAYER_STARTED_DELIVERY; CreateRoute(aDeliveryType); GetNextDeliveryPoint(true); m_active_delivery_type = aDeliveryType; int safe_deposit = DeliveryData.SAFE_DEPOSIT_SCOOTER; if (aDeliveryType == DeliveryType.Van) { safe_deposit = DeliveryData.SAFE_DEPOSIT_VAN; } if (aDeliveryType == DeliveryType.Truck) { safe_deposit = DeliveryData.SAFE_DEPOSIT_TRUCK; } TriggerServerEvent("esx_deliveries:RemoveBankMoney", safe_deposit); Screen.ShowNotification(DeliveryData._U["SAFE_DEPOSIT_RECEIVED"]); }
private void FinishDelivery(DeliveryType aDeliveryType, SafeDepositReturn aReturnType) { if (m_delivery_vehicle != null) { /* Remove all vehicle attatchments */ for (int i = 0; i < m_vehicle_attatchments.Count; i++) { m_vehicle_attatchments[i].Detach(); m_vehicle_attatchments[i].Delete(); } m_vehicle_attatchments.Clear(); /* Remove vehicle */ m_delivery_vehicle.Delete(); } m_delivery_state = DELIVERY_STATE.DELIVERY_INACTIVE; m_delivery_vehicle = null; m_delivery_route.Clear(); m_delivery_point_complete.Clear(); if (m_active_blip != null) { m_active_blip.Delete(); } m_active_blip = null; m_active_delivery_point = null; m_active_delivery_type = DeliveryType.NotSelected; if (aReturnType == SafeDepositReturn.YES) { int safe_deposit = DeliveryData.SAFE_DEPOSIT_SCOOTER; if (aDeliveryType == DeliveryType.Van) { safe_deposit = DeliveryData.SAFE_DEPOSIT_VAN; } if (aDeliveryType == DeliveryType.Truck) { safe_deposit = DeliveryData.SAFE_DEPOSIT_TRUCK; } TriggerServerEvent("esx_deliveries:AddBankMoney", safe_deposit); Screen.ShowNotification(DeliveryData._U["SAFE_DEPOSIT_RETURNED"]); } if (aReturnType == SafeDepositReturn.NO) { Screen.ShowNotification(DeliveryData._U["SAFE_DEPOSIT_WITHHELD"]); } LoadDefaultPlayerSkin(); m_active_blip.Delete(); }
private async Task HandleMarkers() { // Draw Mission Start Markers Vector3 pCoords = Game.PlayerPed.Position; /* Check if a delivery is active */ if (m_delivery_state != DELIVERY_STATE.DELIVERY_INACTIVE) { /* Check if player reached the vehicle return location */ World.DrawMarker(MarkerType.ChevronUpx1, m_baselocation_deleter, Vector3.Zero, Vector3.Zero, new Vector3(1.5f, 1.5f, 1.5f), System.Drawing.Color.FromArgb(150, 255, 50, 0), true, true); if (World.GetDistance(pCoords, m_baselocation_deleter) < 1.5f) { Screen.DisplayHelpTextThisFrame(DeliveryData._U["END_DELIVERY"]); if (Game.IsControlJustReleased(0, Control.Context)) { EndDelivery(); return; } } if (m_delivery_state == DELIVERY_STATE.PLAYER_STARTED_DELIVERY) { if (!isPlayerInsideDeliveryVehicle()) { Vector3 vehpos = m_delivery_vehicle.Position; vehpos.Z += 1.0f; if (m_active_delivery_type == DeliveryType.Van) { vehpos.Z += 1.0f; } if (m_active_delivery_type == DeliveryType.Truck) { vehpos.Z += 2.0f; } World.DrawMarker(MarkerType.ChevronUpx1, vehpos, Vector3.Zero, Vector3.Zero, new Vector3(0.8f, 0.8f, 0.8f), System.Drawing.Color.FromArgb(150, 255, 128, 0), true, true, true); } else { if (World.GetDistance(pCoords, m_active_delivery_point.Item1) < 150.0f) { World.DrawMarker(MarkerType.ChevronUpx1, m_active_delivery_point.Item1, Vector3.Zero, Vector3.Zero, new Vector3(1.5f, 1.5f, 1.5f), System.Drawing.Color.FromArgb(150, 255, 128, 0), true, true); } } } if (m_delivery_state == DELIVERY_STATE.PLAYER_REACHED_VEHICLE_POINT) { if (!isPlayerInsideDeliveryVehicle()) { Vector3 trunkPos = m_delivery_vehicle.Position; Vector3 trunkForwardVector = GetEntityForwardVector(m_delivery_vehicle.Handle); float scaleFactor = 1.0f; if (m_active_delivery_type == DeliveryType.Scooter) { scaleFactor = DeliveryData.COLLECT_GOODS_SCALE_VECTOR_SCOOTER; } if (m_active_delivery_type == DeliveryType.Van) { scaleFactor = DeliveryData.COLLECT_GOODS_SCALE_VECTOR_VAN; } if (m_active_delivery_type == DeliveryType.Truck) { scaleFactor = DeliveryData.COLLECT_GOODS_SCALE_VECTOR_TRUCK; } trunkPos -= trunkForwardVector * scaleFactor; trunkPos.Z += 0.7f; Vector3 arrowSize = new Vector3(0.8f); if (m_active_delivery_type == DeliveryType.Scooter) { arrowSize = new Vector3(0.15f); } World.DrawMarker(MarkerType.ChevronUpx1, trunkPos, Vector3.Zero, Vector3.Zero, arrowSize, System.Drawing.Color.FromArgb(150, 255, 128, 0), true, true, true); if (World.GetDistance(pCoords, trunkPos) < 1.0f) { Screen.DisplayHelpTextThisFrame(DeliveryData._U["REMOVE_GOODS"]); if (Game.IsControlJustReleased(0, Control.Context)) { await GetPlayerPropsForDelivery(m_active_delivery_type); m_delivery_state = DELIVERY_STATE.PLAYER_REMOVED_GOODS_FROM_VEHICLE; } } } } if (m_delivery_state == DELIVERY_STATE.PLAYER_REMOVED_GOODS_FROM_VEHICLE) { World.DrawMarker(MarkerType.ChevronUpx1, m_active_delivery_point.Item2, Vector3.Zero, Vector3.Zero, new Vector3(1.5f, 1.5f, 1.5f), System.Drawing.Color.FromArgb(150, 255, 128, 0), true, true); } if (m_delivery_state == DELIVERY_STATE.PLAYER_RETURNING_TO_BASE) { World.DrawMarker(MarkerType.ChevronUpx1, m_baselocation_deleter, Vector3.Zero, Vector3.Zero, new Vector3(1.5f, 1.5f, 1.5f), System.Drawing.Color.FromArgb(150, 255, 128, 0), true, true); } } if (m_delivery_state == DELIVERY_STATE.DELIVERY_INACTIVE) { if (World.GetDistance(pCoords, m_baselocation_coords) < 150.0f) { World.DrawMarker(MarkerType.MotorcycleSymbol, m_baselocation_scooter, Vector3.Zero, Vector3.Zero, new Vector3(2.5f, 2.5f, 2.5f), System.Drawing.Color.FromArgb(150, 255, 128, 0), true, true); World.DrawMarker(MarkerType.CarSymbol, m_baselocation_van, Vector3.Zero, Vector3.Zero, new Vector3(2.5f, 2.5f, 2.5f), System.Drawing.Color.FromArgb(150, 255, 128, 0), true, true); World.DrawMarker(MarkerType.TruckSymbol, m_baselocation_truck, Vector3.Zero, Vector3.Zero, new Vector3(2.5f, 2.5f, 2.5f), System.Drawing.Color.FromArgb(150, 255, 128, 0), true, true); if (World.GetDistance(pCoords, m_baselocation_scooter) < 1.5f) { Screen.DisplayHelpTextThisFrame(DeliveryData._U["START_DELIVERY"] + DeliveryData.SAFE_DEPOSIT_SCOOTER.ToString()); if (Game.IsControlJustReleased(0, Control.Context)) { await StartDelivery(DeliveryType.Scooter); PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", false, 0, true); } } if (World.GetDistance(pCoords, m_baselocation_van) < 1.5f) { Screen.DisplayHelpTextThisFrame(DeliveryData._U["START_DELIVERY"] + DeliveryData.SAFE_DEPOSIT_VAN.ToString()); if (Game.IsControlJustReleased(0, Control.Context)) { m_active_delivery_type = DeliveryType.Van; await StartDelivery(DeliveryType.Van); PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", false, 0, true); } } if (World.GetDistance(pCoords, m_baselocation_truck) < 1.5f) { Screen.DisplayHelpTextThisFrame(DeliveryData._U["START_DELIVERY"] + DeliveryData.SAFE_DEPOSIT_TRUCK.ToString()); if (Game.IsControlJustReleased(0, Control.Context)) { m_active_delivery_type = DeliveryType.Truck; await StartDelivery(DeliveryType.Truck); PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", false, 0, true); } } } } }
private async Task HandleLogic() { try { if (m_delivery_state != DELIVERY_STATE.DELIVERY_INACTIVE) { /* Check Vehicle and Player health */ if (IsPedDeadOrDying(Game.PlayerPed.Handle, true)) { FinishDelivery(m_active_delivery_type, SafeDepositReturn.NO); return; } if (GetVehicleEngineHealth(m_delivery_vehicle.Handle) < 20 && m_delivery_vehicle != null) { FinishDelivery(m_active_delivery_type, SafeDepositReturn.NO); return; } var playerPed = Game.PlayerPed; Vector3 pCoords = Game.PlayerPed.Position; /* Moving towards vehicle delivery point logic */ if (m_delivery_state == DELIVERY_STATE.PLAYER_STARTED_DELIVERY) { /* Check if the player is still inside the delivery vehicle */ if (!isPlayerInsideDeliveryVehicle()) { Screen.ShowSubtitle(DeliveryData._U["GET_BACK_IN_VEHICLE"]); } /* Check if player reached the vehicle delivery point */ if (World.GetDistance(pCoords, m_active_delivery_point.Item1) < 1.5f) { m_delivery_state = DELIVERY_STATE.PLAYER_REACHED_VEHICLE_POINT; PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", false, 0, true); } } /* Make player grab the props for delivery */ if (m_delivery_state == DELIVERY_STATE.PLAYER_REACHED_VEHICLE_POINT) { } /* Delivering the goods logic */ if (m_delivery_state == DELIVERY_STATE.PLAYER_REMOVED_GOODS_FROM_VEHICLE) { /* Display delivery hint for vans and trucks */ if (m_active_delivery_type == DeliveryType.Van || m_active_delivery_type == DeliveryType.Truck) { Screen.ShowSubtitle(DeliveryData._U["DELIVER_INSIDE_SHOP"]); if (m_active_delivery_type == DeliveryType.Van && !IsEntityPlayingAnim(Game.PlayerPed.Handle, "anim@heists@box_carry@", "walk", 3)) { ForceCarryAnimation(); } } /* Check if player reached the delivery point */ if (World.GetDistance(pCoords, m_active_delivery_point.Item2) < 1.5f) { /* Complete payment*/ int reward_amount = 0; var rnd = new Random(DateTime.Now.Millisecond); int rndMoney = rnd.Next(0, 24); if (m_active_delivery_type == DeliveryType.Scooter) { reward_amount = DeliveryData.DELIVERIES_REWARD_SCOOTER - rndMoney; Screen.ShowNotification(DeliveryData._U["DELIVERY_POINT_REWARD"] + (DeliveryData.DELIVERIES_REWARD_SCOOTER - rndMoney).ToString()); } if (m_active_delivery_type == DeliveryType.Van) { reward_amount = DeliveryData.DELIVERIES_REWARD_VAN - rndMoney; Screen.ShowNotification(DeliveryData._U["DELIVERY_POINT_REWARD"] + (DeliveryData.DELIVERIES_REWARD_VAN - rndMoney).ToString()); } if (m_active_delivery_type == DeliveryType.Truck) { reward_amount = DeliveryData.DELIVERIES_REWARD_TRUCK - rndMoney; Screen.ShowNotification(DeliveryData._U["DELIVERY_POINT_REWARD"] + (DeliveryData.DELIVERIES_REWARD_TRUCK - rndMoney).ToString()); } TriggerServerEvent("esx_deliveries:AddCashMoney", reward_amount); PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", false, 0, true); /* Check if this is the last delivery */ if (IsLastDelivery()) { RemovePlayerProps(); m_active_blip.Delete(); CitizenFX.Core.Debug.WriteLine("Player completed all deliveries. Calling ReturnToVehicle"); m_active_delivery_point = new Tuple <Vector3, Vector3>(m_baselocation_return_point, Vector3.Zero); ReturnToBase(m_active_delivery_type); Screen.ShowSubtitle(DeliveryData._U["GET_BACK_TO_DELIVERYHUB"]); m_delivery_state = DELIVERY_STATE.PLAYER_RETURNING_TO_BASE; return; } else { RemovePlayerProps(); GetNextDeliveryPoint(false); m_delivery_state = DELIVERY_STATE.PLAYER_STARTED_DELIVERY; PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", false, 0, true); } } } /* Return to base logic */ if (m_delivery_state == DELIVERY_STATE.PLAYER_RETURNING_TO_BASE) { } await Delay(500); } else { await Delay(1000); } } catch (Exception e) { CitizenFX.Core.Debug.WriteLine($"{e.Message} : Exception thrown on HandleLogic()"); } }