// Unity controlled. // Update: Each update, check if the game is running, // if the key is pressed, and then toggles the lock state of the helmet // as needed public void Update() { if (GameManager.GameState == GameState.Running) { // If the button is being pressed but was not pressed previously if (KeyManager.GetButtonDown(KeyManager.GetKey("Lock Helmet"))) { if (_lastButtonState == false) { // Find the local player var player = Human.AllHumans.FirstOrDefault(human => human.IsLocalPlayer); if (player == null) { Debug.LogError("HelmetLockMod: Could not find local player"); } else { // If the helmet slot has a helmet if (player.HelmetSlot.Occupant) { var helmet = player.HelmetSlot.Occupant; // Check the helmet can be locked if (helmet.HasLockState) { // Print a string to the console telling the player what is being done var consoleString = String.Format("{0}ing {1}...", helmet.IsLocked ? ActionStrings.Unlock : ActionStrings.Lock, helmet.DisplayName); ConsoleDebug.AddText(String.Format("<color=yellow>{0}</color>", consoleString)); // Get the index of the "Lock Item" action for the helmet // Then tell the player to send a command to the helmet to toggle its lock var helmetLockIndex = helmet.InteractLock.InteractableId; player.CallCmdInteractWith(helmetLockIndex, helmet.netId, player.netId, player.HelmetSlot.SlotId, false); } } } } } // Update the buttons last state _lastButtonState = KeyManager.GetButton(KeyManager.GetKey("Lock Helmet")); } }