void cmdCar(PlayerSession session, string command, string[] args) { //Check for permission to use the plugin if (!userHasPerm(session, "vehiclemanager.use")) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_SERVER"), "red") + GetMsg("msg_permission").Replace("{perm}", "vehiclemanager.use")); return; } var allVsm = Resources.FindObjectsOfTypeAll <VehicleStatManager>().ToList(); VehicleOwnershipManager vom = Singleton <VehicleOwnershipManager> .Instance; VehicleControllerBase controller = null; RestrictedInventory restrictedInv = null; VehicleStatManager vsm = getVSMs(session, vom, allVsm, true)?[0]; if (args.Length == 0) { if (!GetConfig(true, "ShowDistanceCommand")) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_SERVER"), "red") + GetMsg("msg_showDistanceCMD")); return; } var playerVSMs = getVSMs(session, vom, allVsm, false); if (playerVSMs != null && playerVSMs.Count > 0) { foreach (var playerVSM in playerVSMs) { double distance = getPlayerToCarDistance(session, playerVSM); string distanceMsg = string.Format("{0:0}m", (int)Math.Ceiling(distance)); int index = playerVSM.gameObject.name.IndexOf('('); string vehicleName = playerVSM.gameObject.name.Substring(0, index); hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_vehicleDistance").Replace("{vehicle}", vehicleName).Replace("{distance}", distanceMsg)); } } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_noClaim")); } } else if (args.Length == 1) { if (args[0] == "claim") { if (vsm != null) { if (vsm.Owner == null) { controller = vsm.GetComponent <VehicleControllerBase>(); if (!controller.IsKittedOut()) { Singleton <AlertManager> .Instance.GenericTextNotificationServer("Alerts/Not Drivable", session.Player); return; } if (!vom.HasClaim(session.Identity)) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_claimWithButtom")); return; } List <VehicleStatManager> playerVSM = (from v in allVsm where v.Owner == session.Identity select v).ToList(); if (playerVSM.Count >= GetConfig(1, "MaxVehicleClaimsPerPlayer")) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_maxClaim").Replace("{number}", playerVSM.Count + "")); return; } vsm.Owner = session.Identity; Singleton <AlertManager> .Instance.GenericTextNotificationServer("Sucessfully claimed", session.Player); } else { Singleton <AlertManager> .Instance.GenericTextNotificationServer("Alerts/Already Owned", session.Player); } } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_notInsideVehicle")); } } else if (args[0] == "unclaim") { if (vsm != null) { if (vsm.Owner != null && vsm.Owner == session.Identity) { if (vom.GetClaimant(vsm) != string.Empty) //unclaim official vehicle { vom.Unclaim(session.Identity); } else //unclaim one of additional vehicles { vsm.Owner = null; } Singleton <AlertManager> .Instance.GenericTextNotificationServer("Sucessfully unclaimed", session.Player); } else { Singleton <AlertManager> .Instance.GenericTextNotificationServer("Alerts/Not Owner", session.Player); } } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_notInsideVehicle")); } } else if (args[0] == "help" || args[0] == "h") { // /car help | h string[] commands = { Color(GetMsg("carCmds_AVAILABLE"), "orange"), Color("/car ", "orange") + GetMsg("carCmds_carInfo"), Color("/car install <1-8> ", "orange") + GetMsg("carCmds_install"), Color("/car install <1-8> <L|R> ", "orange") + GetMsg("carCmds_installLR"), Color("/car remove <attach> ", "orange") + GetMsg("carCmds_remove"), Color("/car remove <attach> ", "orange") + GetMsg("carCmds_removeExtra"), Color("/car claim ", "orange") + GetMsg("carCmds_claim"), Color("/car unclaim ", "orange") + GetMsg("carCmds_unclaim") }; foreach (string cmd in commands) { hurt.SendChatMessage(session, null, cmd); } } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_carInfo")); } } else if (args.Length == 2 || (args.Length == 3 && (args[2].ToLower() == "l" || args[2].ToLower() == "r"))) { //Get vehicle type (roach or goat) and RestrictedInventory string vehicleType = ""; if (vsm != null) { if (vsm.Owner == null || vsm.Owner == session.Identity) { controller = vsm.GetComponent <VehicleControllerBase>(); restrictedInv = controller.GetComponent <RestrictedInventory>(); //Get vehicle type string tmp = vsm.name.ToLower(); if (tmp.Contains("roach")) { vehicleType = "roach"; } else if (tmp.Contains("kanga")) { vehicleType = "kanga"; } else if (tmp.Contains("goat")) { vehicleType = "goat"; } } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_notOwner")); return; } } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_notInsideVehicle")); return; } if (args[0] == "install") { //Check for permission to install if (!userHasPerm(session, "vehiclemanager.install")) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_SERVER"), "red") + GetMsg("msg_permission").Replace("{perm}", "vehiclemanager.install")); return; } // /car install 1-8 [mandatory for side panels: L|R] //Check if player is installing a correct vehicle attachment int slot = -1; if (!int.TryParse(args[1], out slot) || slot < 1 || slot > 8) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_carInfo")); return; } PlayerInventory playerInventory = session.WorldPlayerEntity.GetComponent <PlayerInventory>(); var playerInventory_items = playerInventory.Items; var playerItemInstance = playerInventory_items[slot - 1]; if (playerItemInstance != null) { IItem item = playerItemInstance.Item; ESlotType itemSlotType = getSlotType(item); string slotTypeString = itemSlotType.ToString().ToLower(); if (!slotTypeString.Contains(vehicleType)) { if ((vehicleType == "roach" && slotTypeString.Contains("goat")) || (vehicleType == "goat" && slotTypeString.Contains("roach")) || (vehicleType == "kanga" && slotTypeString.Contains("kanga"))) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_notCorrectVehicleAttachment").Replace("{vehicleType}", vehicleType)); } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_notVehicleAttachment")); } return; } if (itemSlotType == ESlotType.RoachSidePanel) { if (args.Length == 2 || (args.Length == 3 && (args[2].ToLower() != "l" && args[2].ToLower() != "r"))) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_roachSideIncorrect")); hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_carInfo")); return; } } //Correct item. Can install/switch. //Check if vehicle has the same attachment type installed. If not, install player's item. If yes, switch with player's item. if (controller != null) { if (restrictedInv != null) { SlotRestriction[] restrictions = restrictedInv.Restrictions; for (int k = 0; k < (int)restrictions.Length; k++) { ESlotType slotRestrictionType = restrictions[k].SlotType; if (slotRestrictionType == itemSlotType) { if (itemSlotType == ESlotType.RoachSidePanel && !sideMatchWithSlot(k, args[2].ToLower())) { continue; } //Found correct slot type if (restrictedInv.Items[restrictions[k].SlotNumber] == null) { //Vehicle doesn't have attachment on that slot. Can install. vehicleInstall(session, playerItemInstance, restrictedInv, restrictions[k].SlotNumber); hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_vehicleInstall").Replace("{attachInstalled}", Color(playerItemInstance.Item.GetNameKey(), "orange")).Replace("{vehicleType}", vehicleType)); } else { //Vehicle have attachment on that slot. Can switch. string attachSwitched = vehicleSwitch(session, playerItemInstance, restrictedInv, restrictions[k].SlotNumber); hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_vehicleSwitch").Replace("{attachSwitched}", Color(attachSwitched, "orange")).Replace("{vehicleType}", vehicleType).Replace("{attachInstalled}", Color(playerItemInstance.Item.GetNameKey(), "orange"))); } restrictedInv.Invalidate(false); return; } } } } } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_noCarAttachment").Replace("{slot}", slot + "")); } } else if (args[0] == "remove") { // /car remove bumper|front|left|right|roof|rear|tire|engine|gearbox string tmp = args[1]; //Check for permission to remove.extra if (tmp == "gear" || tmp == "gearbox" || tmp == "engine" || tmp == "tire" || tmp == "wheel") { if (!userHasPerm(session, "vehiclemanager.remove.extra")) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_SERVER"), "red") + GetMsg("msg_permission").Replace("{perm}", "vehiclemanager.remove.extra")); return; } } //Check for permission to remove if (tmp == "bumper" || tmp == "front" || tmp == "left" || tmp == "right" || tmp == "roof" || tmp == "rear" || tmp == "all") { if (!userHasPerm(session, "vehiclemanager.remove")) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_SERVER"), "red") + GetMsg("msg_permission").Replace("{perm}", "vehiclemanager.remove")); return; } } List <string> parts; if (tmp == "all") { parts = new List <string> { "bumper", "front", "left", "right", "roof", "rear" }; } else { parts = new List <string> { tmp } }; bool ignorePart = false; foreach (string attach in parts) { ignorePart = false; //Cannot remove rear if a player is on the vehicle rear if (attach == "rear" || attach == "front") { List <VehiclePassenger> passengers = GameObjectExtensions.GetComponentsByInterfaceInChildren <VehiclePassenger>(vsm.gameObject).ToList(); foreach (VehiclePassenger p in passengers) { if (p.Passenger != null) { string seat = getSeatName(p.SeatOffset); if (attach == seat) { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_removeSeatError").Replace("{seat}", seat)); ignorePart = true; break; } } } } if (ignorePart) { continue; } //Get the restrictedSlots relative to vehicle attachment player wants to remove List <int> restrictedSlots = getRestrictedSlots(attach, vehicleType, restrictedInv); var im = GlobalItemManager.Instance; foreach (int slot in restrictedSlots) { //Give vehicle attach to player inventory ItemInstance vehicleAttach = restrictedInv.Items[slot]; im.GiveItem(session.Player, vehicleAttach.Item, 1); //Remove attachment from vehicle. restrictedInv.Items[slot] = null; restrictedInv.Invalidate(false); if (tmp != "all") { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_vehicleRemove").Replace("{attachRemoved}", Color(vehicleAttach.Item.GetNameKey(), "orange")).Replace("{vehicleType}", vehicleType)); } } if (restrictedSlots.Count == 0) { if (tmp != "all") { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_removeError").Replace("{attach}", attach)); } } } if (tmp == "all") { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_vehicleRemoveAll").Replace("{vehicleType}", vehicleType)); } } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_carInfo")); } } else { hurt.SendChatMessage(session, null, Color(GetMsg("msg_INFO"), "orange") + GetMsg("msg_carInfo")); } }
private void DoInstall(PlayerSession session, string[] args, string vehicleType, VehicleInventory vehicleInventory) { string steamId = session.SteamId.ToString(); if (!permission.UserHasPermission(steamId, InstallPermission)) { Player.Message(session, GetMsg("NoPermission", steamId).Replace("{permission}", InstallPermission)); return; } //Check if player is installing a correct vehicle attachment int slot; if (!int.TryParse(args[1], out slot) || slot < 1 || slot > 8) { Player.Message(session, GetMsg("HelpCommand", steamId)); return; } PlayerInventory playerInventory = session.WorldPlayerEntity.GetComponent <PlayerInventory>(); ItemObject playerItemObject = playerInventory.GetSlot(slot - 1); if (playerItemObject != null) { ESlotType itemSlotType = GetSlotType(playerItemObject); string slotTypeString = itemSlotType.ToString().ToLower(); Puts(slotTypeString); if (!slotTypeString.Contains(vehicleType)) { Player.Message(session, GetMsg("NotVehicleAttachment", steamId)); return; } //Correct item. Can install/switch. //Check if vehicle has the same attachment type installed. If not, install player's item. If yes, switch with player's item. bool updated = false; bool notSwitched = false; for (int slotNumber = 0; slotNumber < vehicleInventory.StorageConfig.Slots.Length; ++slotNumber) { StorageSlotConfig storageSlotConfig = vehicleInventory.StorageConfig.Slots[slotNumber]; if (storageSlotConfig.SlotRestrictions.Contains(itemSlotType)) { ItemObject switchslot = vehicleInventory.GetSlot(storageSlotConfig.SlotNumber); if (switchslot == null) { //Vehicle doesn't have attachment on that slot. Can install. VehicleInstall(session, playerItemObject, vehicleInventory, storageSlotConfig.SlotNumber); Player.Message(session, GetMsg("VehicleInstall", steamId).Replace("{attachInstalled}", playerItemObject.Generator.name).Replace("{vehicleType}", GetMsg("vehicles/" + vehicleType))); updated = true; } else { ItemObject vehicleAttach = vehicleInventory.GetSlot(storageSlotConfig.SlotNumber); if (RuntimeHurtDB.Instance.GetGuid(vehicleAttach.Generator) == RuntimeHurtDB.Instance.GetGuid(playerItemObject.Generator)) { notSwitched = true; continue; } else { //Vehicle have attachment on that slot. Can switch. string attachSwitched = VehicleSwitch(session, playerItemObject, vehicleInventory, storageSlotConfig.SlotNumber); Player.Message(session, GetMsg("VehicleSwitch", steamId).Replace("{attachSwitched}", attachSwitched).Replace("{vehicleType}", GetMsg("vehicles/" + vehicleType)).Replace("{attachInstalled}", playerItemObject.Generator.name)); updated = true; } } vehicleInventory.Invalidate(false); } if (updated) { break; } } if (notSwitched && !updated) { Player.Message(session, GetMsg("VehicleAttachmentAlreadyInstalled", steamId).Replace("{attachment}", playerItemObject.Generator.name)); } } else { Player.Message(session, GetMsg("NoAttachmentFound", steamId).Replace("{slot}", slot.ToString())); } }