MZ Does anyone know of a way to create a custom battle menu that can cast skills via custom HUD elements?

I would like to create a custom image-based menu for the battle scene using HUD Maker Ultra Pro. However, RMMZ doesn't seem to have built-in functionality for using skills in a normal way via something like a common event. What I need is something like a plugin or script that allows me to use a skill by clicking on a custom HUD element added by HUD Maker, preferably something like a plugin command that would allow me to select a skill ID which can then be attached to a common event that would be called by clicking on the custom button. The skill would need to function in the same way as if I were using it from the normal battle menu (e.g. no "Force Action"). I've scoured the internet for the past couple hours for a solution, but to no avail.

Edit: I used ChatGPT to help out with coding a plugin. It mostly works, but I cannot for the life of me get it to provide a working target selector. The skill itself executes perfectly. Unfortunately I do not know enough about coding to see any errors with it. Perhaps someone here knows what needs to be changed?

JavaScript:
 /*:
 * @plugindesc Executes a specified skill during battle by bringing up the target selector before execution.
 * @author [Your Name]
 *
 * @ ============================================================================
 * @ Plugin Parameters
 * @ ============================================================================
 *
 * @param SkillIdField
 * @text Skill ID Field
 * @desc The field in the command arguments that specifies the Skill ID.
 * @default skillId
 *
 * @ ============================================================================
 * @ Command Plugin Calls
 * @ ============================================================================
 * @command ExecuteSkill
 * @text Execute Skill
 * @desc Executes a specified skill during battle.
 *
 * @arg skillId
 * @text Skill ID
 * @desc The ID of the skill to be executed.
 * @type skill
 * @default 1
 *
 * @ ============================================================================
 * @ Script Calls
 * @ ============================================================================
 * @ None.
 */

(function () {
  var parameters = PluginManager.parameters('ExecuteSkillCommand');
  var skillIdField = String(parameters['SkillIdField'] || 'skillId');

  PluginManager.registerCommand('ExecuteSkillCommand', 'ExecuteSkill', function (args) {
    var skillId = parseInt(args.skillId);

    if (!isNaN(skillId) && skillId > 0) {
      var actor = $gameParty.members()[0];

      if (actor && $gameParty.inBattle()) {
        actor.setAction(0, BattleManager.inputtingAction());
        actor.currentAction().setSkill(skillId);

        var originalTurnEndCallback = BattleManager._phase._turnEndCallback;

        BattleManager._phase._turnEndCallback = function () {
          BattleManager._phase._turnEndCallback = originalTurnEndCallback;

          BattleManager.inputtingAction().setTargetType('enemy');
          BattleManager.inputtingAction().setSubject(actor);
          BattleManager.inputtingAction().setTarget(1);

          BattleManager.startTargetSelection();

          BattleManager.inputtingAction().setTargetCallback(function () {
            originalTurnEndCallback();

            BattleManager.processTurn();
          });
        };

        BattleManager.selectNextCommand();
      }
    }
  });
})();

Original thread: https://forums.rpgmakerweb.com/threads/does-anyone-know-of-a-way-to-create-a-custom-battle-menu-that-can-cast-skills-via-custom-hud-elements.163357/