public void SaveFactionVehicle(Client player, int factionid = -1) { Faction faction; Player user = Player.PlayerData[player]; try { faction = Faction.FactionData.Single(f => f.Id == user.FactionId); } catch { API.sendChatMessageToPlayer(player, "~r~ERROR: You are not in a faction."); return; } if (factionid != -1) { if (user.MasterAccount.AdminLevel > 2) { if (user.Client.isInVehicle) { if (Vehicle.VehicleData[player.vehicle].IsAdminVehicle) { NetHandle veh = Vehicle.VehicleData[player.vehicle].Entity.handle; Vehicle.VehicleData[veh].IsAdminVehicle = false; Vehicle.VehicleData[veh].LicensePlate = "PD 001"; Vehicle.VehicleData[veh].Health = 1000; Vehicle.VehicleData[veh].LicensePlateStyle = 4; Vehicle.VehicleData[veh].DoorData = new int[4] { 0, 0, 0, 0 }; Vehicle.VehicleData[veh].WindowData = new int[4] { 0, 0, 0, 0 }; Vehicle.VehicleData[veh].FactionId = factionid; Vehicle.VehicleData[veh].SavePosition = Vehicle.VehicleData[player.vehicle].Entity.position; Vehicle.VehicleData[veh].SaveRotation = Vehicle.VehicleData[player.vehicle].Entity.rotation; VehicleRepository.AddNewVehicle(Vehicle.VehicleData[veh]); API.sendChatMessageToPlayer(player, String.Format("~y~You successfully saved the position of the {0}", player.vehicle.displayName)); } } } else { Message.NotAuthorised(player); return; } } else { if (user.MasterAccount.AdminLevel > 2 || faction.Ranks[user.FactionRank - 1].RepositionVehicles) { if (Vehicle.VehicleData[player.vehicle].FactionId == user.FactionId) { NetHandle veh = Vehicle.VehicleData[player.vehicle].Entity.handle; Vehicle.VehicleData[veh].SavePosition = Vehicle.VehicleData[player.vehicle].Entity.position; Vehicle.VehicleData[veh].SaveRotation = Vehicle.VehicleData[player.vehicle].Entity.rotation; VehicleRepository.UpdateAsync(Vehicle.VehicleData[veh]); API.sendChatMessageToPlayer(player, String.Format("~y~You successfully saved the position of the {0}", player.vehicle.displayName)); } } } }
public static void GaragePaymentCash(Player p, Inventory inv) { Vehicle veh = Vehicle.VehicleData[p.Client.vehicle]; if (long.Parse(inv.Value) >= veh.RepairCost) { inv.Value = (long.Parse(inv.Value) - (long)veh.RepairCost).ToString(); if (inv.Value == "0") { p.Inventory.Remove(inv); InventoryRepository.RemoveInventoryItem(inv); } else { InventoryRepository.UpdateAsync(inv); } switch (veh.RepairType) { case VehicleRepairType.Engine: PerformEngineRepair(veh); break; case VehicleRepairType.Body: PerformBodyRepair(veh); break; case VehicleRepairType.Tyres: PerformTyreRepair(veh); break; } VehicleRepository.UpdateAsync(veh); p.Client.warpOutOfVehicle(); veh.Entity.Delete(false); p.Client.position = p.BusinessInteractingWith.EnterPosition; p.Client.dimension = 0; API.shared.triggerClientEvent(p.Client, "closeShopUI"); InventoryManager.HidePlayerInventory(p); API.shared.ShowPopupMessage(p.Client, "Repair In Progress...", String.Format("Your {0} is now booked in for repair!<br />The vehicle should be available for collection anytime after {1}.", veh.Name, veh.RepairTime.ToString("dd/MM/yy HH:mm"))); p.InEvent = PlayerEvent.None; } else { API.shared.SendErrorNotification(p.Client, "Insufficient funds."); API.shared.SendInfoNotification(p.Client, "Select new payment method:"); InventoryManager.UpdatePlayerInventory(p); } }
public void ToggleVehicleEngine(Client player) { Player user = Player.PlayerData[player]; if (player.isInVehicle) { if (user.Inventory.Count(k => k.Value == Vehicle.VehicleData[player.vehicle].Key) == 1 || Vehicle.VehicleData[player.vehicle].FactionId == user.FactionId || Vehicle.VehicleData[player.vehicle].KeyInIgnition) { Vehicle veh = Vehicle.VehicleData[player.vehicle]; if (veh.OwnerId != -1) { Inventory key = null; if (!veh.IsEngineOn) { key = veh.TrunkItems.FirstOrDefault(k => k.Value == veh.Key && k.OwnerId == veh.Id && k.OwnerType == InventoryOwnerType.Vehicle); if (key != null) { if (!key.AddToPlayer(user, true)) { API.SendWarningNotification(player, "You don't have enough space in your inventory for a this car key"); return; } key.OwnerId = user.Id; key.OwnerType = InventoryOwnerType.Player; user.Inventory.Add(key); if (user.OwnedVehicles.All(v => v.Id != veh.Id)) { API.SendInfoNotification(user.Client, $"The key to this {veh.Entity.displayName} has been added to you inventory."); } veh.TrunkItems.Remove(key); veh.KeyInIgnition = false; veh.IsEngineOn = false; InventoryRepository.UpdateAsync(key); VehicleRepository.UpdateAsync(veh); return; } key = user.Inventory.FirstOrDefault(k => k.Value == veh.Key); if (key != null) { if (veh.Fuel > 0 && veh.Health > 110) { veh.CalculateTaintedFuel(); veh.KeyInIgnition = true; key.OwnerId = veh.Id; key.OwnerType = InventoryOwnerType.Vehicle; user.Inventory.Remove(key); veh.TrunkItems.Add(key); //API.triggerClientEvent(player, "dashboard_update_fuel", veh.Fuel); } else { API.SendErrorNotification(player, "Engine failed to start..."); return; } InventoryRepository.UpdateAsync(key); } } else { key = veh.TrunkItems.FirstOrDefault(k => k.Value == veh.Key && k.OwnerId == veh.Id && k.OwnerType == InventoryOwnerType.Vehicle); if (key != null) { if (!key.AddToPlayer(user, true)) { API.SendWarningNotification(player, "You don't have enough space in your inventory for a this car key"); return; } key.OwnerId = user.Id; key.OwnerType = InventoryOwnerType.Player; user.Inventory.Add(key); if (user.OwnedVehicles.All(v => v.Id != veh.Id)) { API.sendNotificationToPlayer(user.Client, $"The key to this {veh.Entity.displayName} has been added to you inventory."); } veh.TrunkItems.Remove(key); veh.KeyInIgnition = false; InventoryRepository.UpdateAsync(key); } } } veh.IsEngineOn = !veh.IsEngineOn; API.setVehicleEngineStatus(player.vehicle, veh.IsEngineOn); API.sendNotificationToPlayer(player, veh.IsEngineOn ? "~g~Engine On" : "~r~Engine Off", true); VehicleRepository.UpdateAsync(veh); } if (Vehicle.VehicleData[player.vehicle].SidejobUserId == user.Id) { Vehicle veh = Vehicle.VehicleData[player.vehicle]; veh.IsEngineOn = !veh.IsEngineOn; API.setVehicleEngineStatus(player.vehicle, veh.IsEngineOn); API.sendNotificationToPlayer(player, veh.IsEngineOn ? "~g~Engine On" : "~r~Engine Off", true); Vehicle.VehicleData[player.vehicle] = veh; return; } } }
private void OnRepairShopClientEventTrigger(Client sender, string eventName, params object[] arguments) { if (eventName == "PerformGarageRepair") { Vehicle veh = Vehicle.VehicleData[sender.vehicle]; veh.RepairType = (VehicleRepairType)arguments[0]; for (int i = 0; i < 7; i++) { veh.TyresData[i] = API.isVehicleTyrePopped(veh.Entity, i) ? 1 : 0; } string typeName = ""; switch (veh.RepairType) { case VehicleRepairType.Engine: veh.RepairCost = Math.Round((veh.Entity.Price() * 0.3) * ((1000 - veh.Entity.health) / 1000)); veh.RepairTime = Server.Date.AddMinutes(12); typeName = "Engine"; break; case VehicleRepairType.Body: veh.RepairTime = Server.Date.AddMinutes(12); typeName = "Body"; break; case VehicleRepairType.Tyres: int poppedTyres = veh.TyresData.Where(t => API.isVehicleTyrePopped(veh.Entity, t)).Count(); veh.RepairCost = 60 * poppedTyres; typeName = "Tyres"; veh.RepairTime = Server.Date.AddMinutes(poppedTyres); break; } API.ShowPopupPrompt(sender, "ConfirmGarageRepair", String.Format("Confirm {0} Repair?", typeName), String.Format("You are about to repair the {0} of your {1}, this will cost {2}.<br />Do you want to continue?", typeName.ToLower(), veh.Name, veh.RepairCost.ToString("C"))); } else if (eventName == "ConfirmGarageRepair") { Player player = Player.PlayerData[sender]; if ((int)arguments[0] == 1) { player.SelectedCardAccount = null; player.SelectedCash = null; player.AwaitingInventorySelection = InventoryType.Money; API.SendInfoNotification(sender, "Please select your payment method.", 7); InventoryManager.UpdatePlayerInventory(player); } else { Vehicle veh = Vehicle.VehicleData[sender.vehicle]; veh.RepairType = 0; VehicleRepository.UpdateAsync(veh); } } else if (eventName == "RetrieveVehicleFromRepairGarage") { Player p = Player.PlayerData[sender]; try { Vehicle veh = Vehicle.VehicleData.Values.FirstOrDefault(v => v.Id == (int)arguments[0]); if (!veh.RepairComplete) { return; } string repairType = ""; switch (veh.RepairType) { case VehicleRepairType.Engine: repairType = "engine"; break; case VehicleRepairType.Body: repairType = "body"; break; case VehicleRepairType.Tyres: repairType = "tyres"; break; } API.ShowPopupMessage(sender, "Repair complete!", string.Format("Your {0}'s ", veh.Name) + string.Format("{0} {1} successfully repaired<br/> ", repairType, veh.RepairType == VehicleRepairType.Tyres ? "were" : "was") + string.Format("Repair Cost: {0:C}<br/> Time of collection: {1:dd/MM/yy HH:mm}<br/> ", veh.RepairCost, Server.Date) + string.Format("Collected by: {0}", sender.name)); API.triggerClientEvent(sender, "closeShopUI"); veh.RepairType = 0; veh.Dimension = 0; VehicleRepository.UpdateAsync(veh); veh = p.ReloadPlayerVehicle(veh); API.delay(500, true, () => { SpawnOutsideOfGarage(sender, veh); }); } catch (Exception ex) { Console.WriteLine(ex.InnerException); } } else if (eventName == "ExitRepairShop") { Player p = Player.PlayerData[sender]; sender.FadeOut(200); Vehicle veh = Vehicle.VehicleData[sender.vehicle]; veh.RepairType = 0; SpawnOutsideOfGarage(sender, veh); } }
private async void OnResourceStart() { Faction.FactionData = await FactionRepository.GetAllFactions(); foreach (Faction f in Faction.FactionData) { f.Ranks = await RankRepository.GetRanksByFactionId(f.Id); f.Vehicles = await VehicleRepository.GetAllVehiclesByFactionId(f.Id); await Task.Run(async() => { foreach (Vehicle v in f.Vehicles) { GrandTheftMultiplayer.Server.Elements.Vehicle vehicle = API.createVehicle((VehicleHash)v.Model, v.SavePosition, v.SaveRotation, 0, 0, v.Dimension); v.Entity = vehicle; v.UnoccupiedPosition = v.SavePosition; v.UnoccupiedRotation = v.SaveRotation; if (v.Color1.Length > 3) { v.Entity.customPrimaryColor = v.CustomColor(v.Color1); } else { v.Entity.primaryColor = int.Parse(v.Color1); } if (v.Color2.Length > 3) { v.Entity.customSecondaryColor = v.CustomColor(v.Color2); } else { v.Entity.secondaryColor = int.Parse(v.Color2); } for (int i = 0; i < 2000; i++) { if (Vehicle.IDs[i] != null) { continue; } Vehicle.IDs[i] = vehicle; break; } v.TrunkItems = new List <Inventory>(); v.IsEngineOn = false; vehicle.engineStatus = v.IsEngineOn; vehicle.health = (float)v.Health; vehicle.invincible = false; vehicle.numberPlate = v.LicensePlate; vehicle.numberPlateStyle = v.LicensePlateStyle; v.IsAdminVehicle = false; v.IsDealerVehicle = false; //for (int w = 0; w < v.WindowData.Length; w++) // API.breakVehicleWindow(vehicle, w, v.WindowData[w] == 1 ? true : false); API.setVehicleLocked(vehicle, v.Locked); //c = 1; //foreach (int d in v.DoorData) { // if (d == 1) // vehicle.breakDoor(c); // c++; //} v.Entity = vehicle; Vehicle.VehicleData.Add(vehicle, v); await Task.Delay(100); } }); } }