private void OnHudReady() { category = new HudAPIv2.MenuRootCategory("Instant Projector", HudAPIv2.MenuRootCategory.MenuFlag.AdminMenu, "Instant Projector"); menuBlockBuildTime = new HudAPIv2.MenuTextInput("Block Build Time - " + config.BlockBuildTime, category, "Enter build time per block in seconds.", OnBlockTimeSubmit); config.OnBlockBuildTimeChanged += Config_OnBlockBuildTimeChanged; menuComponentCostModifier = new HudAPIv2.MenuTextInput("Component Cost Modifier - " + config.ComponentCostModifier, category, "Enter the component cost modifier.", OnCompCostSubmit); config.OnComponentCostModifierChanged += Config_OnComponentCostModifierChanged; menuMinBlocks = new HudAPIv2.MenuTextInput("Min Blocks - " + config.MinBlocks, category, "Enter the minimum number of blocks allowed to build.", OnMinBlocksSubmit); config.OnMinBlocksChanged += Config_OnMinBlocksChanged; menuMaxBlocks = new HudAPIv2.MenuTextInput("Max Blocks - " + config.MaxBlocks, category, "Enter the maximum number of blocks allowed to build.", OnMaxBlocksSubmit); config.OnMaxBlocksChanged += Config_OnMaxBlocksChanged; menuPowerModifier = new HudAPIv2.MenuTextInput("Power Modifier - " + config.PowerModifier, category, "Enter the power modifier.", OnPowerSubmit); config.OnPowerModifierChanged += Config_OnPowerModifierChanged; menuSubgrids = new HudAPIv2.MenuItem("Subgrids - " + config.Subgrids, category, OnSubgridsClick); config.OnSubgridsChanged += Config_OnSubgridsChanged; menuExtraComp = new HudAPIv2.MenuTextInput("Extra Component - " + config.GetExtraCompName(), category, "Enter the extra component with format <typeid>/<subtypeid>", OnExtraCompSubmit); config.OnExtraComponentChanged += Config_OnExtraComponentChanged; menuExtraCompCost = new HudAPIv2.MenuTextInput("Extra Component Cost - " + config.ExtraCompCost, category, "Enter the extra component cost.", OnExtraCompCostSubmit); config.OnExtraCompCostChanged += Config_OnExtraCompCostChanged; }
private void ChatMessage(string messageText, ref bool sendToOthers) { string[] args; if (messageText.StartsWith(prefix2) || messageText.StartsWith(prefix1)) { args = messageText.Split(space, StringSplitOptions.RemoveEmptyEntries); } else { return; } sendToOthers = false; if (!IsPlayerAdmin(true)) { return; } if (args.Length < 2) { ShowHelp(); return; } MapSettings config = IPSession.Instance.MapSettings; switch (args[1]) { case "blocktime": { if (args.Length > 3) { Show("Usage: /ip blocktime <value>"); return; } if (args.Length == 2) { Show("Block Build Time: " + config.BlockBuildTime); return; } float n; if (!float.TryParse(args[2], out n)) { Show("Unable to parse '" + args[2] + "' into a number."); return; } if (n < 0 || float.IsInfinity(n) || float.IsNaN(n)) { Show("Value must be greater than 0."); return; } config.BlockBuildTime = n; Show("Block Build Time: " + n); } break; case "compcost": { if (args.Length > 3) { Show("Usage: /ip compcost <value>"); return; } if (args.Length == 2) { Show("Component Cost Modifier: " + config.ComponentCostModifier); return; } float n; if (!float.TryParse(args[2], out n)) { Show("Unable to parse '" + args[2] + "' into a number."); return; } if (n < 0 || float.IsInfinity(n) || float.IsNaN(n)) { Show("Value must be greater than 0."); return; } config.ComponentCostModifier = n; Show("Component Cost Modifier: " + n); } break; case "minblocks": { if (args.Length > 3) { Show("Usage: /ip minblocks <value>"); return; } if (args.Length == 2) { Show("Min Blocks: " + config.MinBlocks); return; } int n; if (!int.TryParse(args[2], out n)) { Show("Unable to parse '" + args[2] + "' into a number."); return; } if (n < 0 || n >= config.MaxBlocks) { Show("Value must be greater than 0 and less than" + config.MaxBlocks); return; } config.MinBlocks = n; Show("Min Blocks: " + n); } break; case "maxblocks": { if (args.Length > 3) { Show("Usage: /ip maxblocks <value>"); return; } if (args.Length == 2) { Show("Max Blocks: " + config.MaxBlocks); return; } int n; if (!int.TryParse(args[2], out n)) { Show("Unable to parse '" + args[2] + "' into a number."); return; } if (n < 0 || n <= config.MinBlocks) { Show("Value must be greater than " + config.MinBlocks); return; } config.MaxBlocks = n; Show("Max Blocks: " + n); } break; case "subgrids": { if (args.Length > 3) { Show("Usage: /ip subgrids <true|false>"); return; } if (args.Length == 2) { Show("Subgrids: " + config.Subgrids); return; } bool b; if (!bool.TryParse(args[2], out b)) { Show("Unable to parse '" + args[2] + "' into true or false."); return; } config.Subgrids = b; Show("Subgrids: " + b); } break; case "power": { if (args.Length > 3) { Show("Usage: /ip power <value>"); return; } if (args.Length == 2) { Show("Power Modifier: " + config.PowerModifier); return; } float n; if (!float.TryParse(args[2], out n)) { Show("Unable to parse '" + args[2] + "' into a number."); return; } if (n < 0 || float.IsInfinity(n) || float.IsNaN(n)) { Show("Value must be greater than 0."); return; } config.PowerModifier = n; Show("Power Modifier: " + n); } break; case "extracomp": { if (args.Length > 4) { Show("Usage: /ip extracomp [<typeid> <subtypeid>|none]"); return; } if (args.Length == 2) { Show("Extra Component: " + config.GetExtraCompName()); return; } string typeId = args[2]; string subtypeId; if (args.Length == 3) { if (typeId.Equals("null", StringComparison.OrdinalIgnoreCase) || typeId.Equals("none", StringComparison.OrdinalIgnoreCase)) { config.ExtraComponent = null; Show("Extra Component: None"); return; } if (typeId.Contains("/")) { string[] typeArgs = typeId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (typeArgs.Length != 2) { Show("Usage: /ip extracomp [<typeid> <subtypeid>|none]"); return; } typeId = typeArgs[0]; subtypeId = typeArgs[1]; } else { Show("Usage: /ip extracomp [<typeid> <subtypeid>|none]"); return; } } else { subtypeId = args[3]; } string obTypeId; if (!typeId.StartsWith("MyObjectBuilder_")) { obTypeId = "MyObjectBuilder_" + typeId; } else { obTypeId = typeId; typeId = typeId.Replace("MyObjectBuilder_", ""); } MyDefinitionId id; if (!MyDefinitionId.TryParse(obTypeId, subtypeId, out id)) { Show($"Unable to parse {typeId}/{subtypeId} into an id."); return; } MyPhysicalItemDefinition comp; if (!MyDefinitionManager.Static.TryGetPhysicalItemDefinition(id, out comp)) { Show($"Unable to find an item with id {typeId}/{subtypeId} in the game."); return; } config.ExtraComponent = id; Show("Extra Component: " + config.GetExtraCompName()); } break; case "extracompcost": { if (args.Length > 3) { Show("Usage: /ip extracompcost <value>"); return; } if (args.Length == 2) { Show("Extra Component Cost: " + config.ExtraCompCost); return; } float n; if (!float.TryParse(args[2], out n)) { Show("Unable to parse '" + args[2] + "' into a number."); return; } if (n < 0 || float.IsInfinity(n) || float.IsNaN(n)) { Show("Value must be greater than 0."); return; } config.ExtraCompCost = n; Show("Extra Component Cost: " + n); } break; default: ShowHelp(); break; } }