VX Ace Help: Moving the Guard Command from the Actor Command Menu to the Party Command Menu

I've been working on a project for a friend for over a year. Due to the NDA I signed with them, I cannot discuss any other details about the project other than what I am asking for here.

I also want to clarify that due to the nature of the project, I am NOT ALLOWED to use Menu Scripting engines such as the popular YanFly Engine. We are focusing on in-house proprietary scripting, so please consider this in your reply.

That all being said, I am trying to move the Guard Command from the Actor Command Menu to the Party Command Menu, and in turn, toggle the Guard State on and off for ALL party members. Kind of like a pre-emptive shields up / down function is the best way I can describe it without violating the NDA.

I managed to create a "Party Guard" option in the party menu and of course, it has no function at the moment. I also created the if/then condition for the party-wide guard State toggle when selected. I also created the vocabulary entries in the Vocab module. I just need to know what class or module I need to point to so that the if/then toggle condition can be activated by the command. The rest of the details on how the guard state will actually work will be decided as our in-house engine is developed.

Any help would be greatly appreciated. Thank you for your time.
Look at the Scene_Battle. This is how the party command is coded
Ruby:
  def create_party_command_window
    @party_command_window = Window_PartyCommand.new
    @party_command_window.viewport = @info_viewport
    @party_command_window.set_handler(:fight,  method(:command_fight))
    @party_command_window.set_handler(:escape, method(:command_escape))
    @party_command_window.unselect
  end
As you can see, there is set_handler
For example, :fight is the command symbol/sign, and method(:command_fight) is the function/method name that you call when the command is selected.

For example, you want to add a party guard. You can do this.
Ruby:
  def create_party_command_window
    @party_command_window = Window_PartyCommand.new
    @party_command_window.viewport = @info_viewport
    @party_command_window.set_handler(:fight,  method(:command_fight))
    @party_command_window.set_handler(:escape, method(:command_escape))
    @party_command_window.set_handler(:guard, method(:command_party_guard))
    @party_command_window.unselect
  end
Then you add a code
Ruby:
def command_party_guard
    # Your code here
end
Look at the Scene_Battle. This is how the party command is coded
Ruby:
  def create_party_command_window
    @party_command_window = Window_PartyCommand.new
    @party_command_window.viewport = @info_viewport
    @party_command_window.set_handler(:fight,  method(:command_fight))
    @party_command_window.set_handler(:escape, method(:command_escape))
    @party_command_window.unselect
  end
As you can see, there is set_handler
For example, :fight is the command symbol/sign, and method(:command_fight) is the function/method name that you call when the command is selected.

For example, you want to add a party guard. You can do this.
Ruby:
  def create_party_command_window
    @party_command_window = Window_PartyCommand.new
    @party_command_window.viewport = @info_viewport
    @party_command_window.set_handler(:fight,  method(:command_fight))
    @party_command_window.set_handler(:escape, method(:command_escape))
    @party_command_window.set_handler(:guard, method(:command_party_guard))
    @party_command_window.unselect
  end
Then you add a code
Ruby:
def command_party_guard
    # Your code here
end
Thank you for your suggestion. I will look into it when I get home (I am at work atm.) If this works, I will be eternally grateful.

UPDATE:
Okay... I managed to get the command to work, but I think I may be setting up the if/else statement improperly. I'm a novice programmer at best, so I'd appreciate any advice you can offer me on this.

The state will now apply and consume a party action. The problem is, it's constantly doing this rather than toggling between guard up and down on command. Here's a screenshot of my code:
1677554491812.png

I'm sure I'm missing something. Do you have any pointers? I'd appreciate the help.
but I think I may be setting up the if/else statement improperly.
What do you expect to check in the if statement?

Also, you don't need to directly edit Scene_Battle. It is going to be hard to track what is changed.
Make a new script slot, and put all your modifications there. If you want to rollback the change, you can just comment on the entire script or put it at the bottom of the main slot.
The condition I am trying to check is whether or not all the members in a battle party are in the guard state or not. As far as where I placed the script, I've been modifying the other scripts in the same way (again, doing a sort of total conversion of the engine), and been writing down where everything was modified accordingly.
The condition I am trying to check is whether or not all the members in a battle party are in the guard state or not.
Then use the function .all? or .any?

Code:
$game_party.alive_members.any? {|a| !a.state?(9)}
This checks if one of them does not have a guard state
Code:
$game_party.alive_members.all? {|a| !a.state?(9)}
This checks if all of them do not have a guard state

You might want to use alive members because otherwise, it would also check dead members.
I see what you're saying. I knew I was missing some sort of command. I will try that and see if it works.

I thank you once more for your help in this matter.

UPDATE: It's all working now! I thank you so much.

The only thing remaining is that the guard does not go down before the turn starts. Is there a tweak I can make that will turn off the status before the turn starts?
It might be easier to use a troop event to turn it off at the very beginning of the turn, before anyone has done anything. You won't need a conditional to check if anyone has the guard state, just simply do it.
I appreciate the thought, but I would like the player to be able to turn it on and off at will.
Probably the easiest way is to change the command_fight to behave differently. If everyone already has a guard, start the turn. Otherwise, input action as usual. So, you don't need to put turn_start at the command guard. I'm not sure if this is what you want.
I can look into that. Again, I appreciate your help with this.

UPDATE: I found the code I needed to fix it! All I had to do was use this:
Ruby:
@status_window.refresh

And it updated the status immediately before the turn started. I have the Party Guard command working exactly as intended now. I have to make a few tweaks to make it perfect, but I can go from here.

Thank you all so much for your help. I appreciate it!

Original thread: https://forums.rpgmakerweb.com/threads/vx-ace-help-moving-the-guard-command-from-the-actor-command-menu-to-the-party-command-menu.155355/