Skip to content

Hiding commands that cannot be used using the command manager #206

@HimeWorks

Description

@HimeWorks

We have a problem where someone wants to use a skill as a command, but the command should not appear unless certain conditions are met.

By default, the "use_skill" command will simply disable the command if it cannot be used.

There are several solutions. Personally I would prefer to simply define a custom command type, even if it will only be used once.

I use the standard command plugin API to define my command, except because I know it will function the same way as the use_skill command, I can basically have this command invoke the other command.

In this case, I want to define a command that will be hidden if it's not usable:

CommandManager.register(:hide_use_skill, :actor, "1.0")

class Command_HideUseSkill < Game_BattlerCommand
  def enabled?(user)
    user.usable?($data_skills[@ext])
  end
end

class Game_Actor < Game_Battler
  def add_command_hide_use_skill(args)
    id = args[0].to_i
    name = $data_skills[id].name
    cmd = Command_HideUseSkill.new(name, :use_skill, id)
    add_command(cmd)
  end
end

Now instead of saying

<cmd: use_skill 43>

I can instead say

<cmd: hide_use_skill 43>

And it will do basically the same thing except it will not be visible if it can't be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions