MV "Bribe" plugin

I am learning RMMV JS Plugin Development. I want to create a plugin where you bribe the enemy to leave the field and give you rare treasures, just like in Final Fantasy X. But I am stuck now.

Now, I didn't do as much as I could do. Please don't comment on other codes that I didn't do right. But if my current code is the way I want it to and there is a better way to do so then please do comment it. But since I am stuck, I would want to proceed after I fix this problem. Here is the code:

Spoiler: Code
JavaScript:
var earnItem = false;

var _Game_Action = Game_Action.prototype.apply;
Game_Action.prototype.apply = function (target) {
    console.log($dataSkills[1]);
    if (target.isEnemy()) {
        $gameMessage.setNumberInput(1, 4); //This happens after the statements below happen and adding a message following this doesn't make this appear
        target.hide();
        BattleManager._rewards.items = target.makeDropItems();
        BattleManager.displayDropItems();
        BattleManager.gainDropItems();
    }
    else _Game_Action.call(this, target);
}

var _makeDropItems = Game_Enemy.prototype.makeDropItems;
Game_Enemy.prototype.makeDropItems = function () {
    var items = _makeDropItems.call(this);;
    items.push(this.itemObject(1, 3));
    return items;
};

I honestly do not know what to do. I ask the money to be inputted but it appears only after the following code do. Adding a message doesn't do the job either. I have improved in this plugin and have managed to do more than before I have tried making this plugin. I am still a beginner to this language (JS) and this framework (RMMV). Help would be greatly appreciated.
After the call to setNumberInput, try

$gameTroop._interpreter.setWaitMode("message")
After the call to setNumberInput, try

$gameTroop._interpreter.setWaitMode("message")
I've tried it now, it didn't work.
This is an async problem: $gameMessage.setNumberInput does not freeze the game until input is received, it just sets a couple of values. So all your code gets executed within one frame.

Why not just put this stuff in a Common Event effect on your "Bribe" skill? You can use the Input Number command to get number input. If "Bribe" can only target enemies (you could make another one for enemies if necessary), I think you can get your target variable in a Script command like this:
JavaScript:
var target = $gameTroop.members()[BattleManager._subject._lastTargetIndex];

I'd also suggest using target.escape() instead of target.hide(). 👋
@caethyril I have done so and yet the command to input a number still happens after the commands following it do.
@caethyril I have done so and yet the command to input a number still happens after the commands following it do.
I just tested with this common event attached to skill 1 (Attack):

◆Input Number:Input, 4 digits ◆Script:var subject = BattleManager._subject; : :if (subject && subject.isActor()) { : : var index = subject._lastTargetIndex; : : var enemy = $gameTroop.members()[index]; : : if (enemy) alert(enemy.name()); : :}
Spoiler: easy-copy script call
JavaScript:
var subject = BattleManager._subject;
if (subject && subject.isActor()) {
  var index = subject._lastTargetIndex;
  var enemy = $gameTroop.members()[index];
  if (enemy) alert(enemy.name());
}
This always waits for the player to confirm the number input before running the Script command. If that is not what you are seeing, then:
  1. Turn off all your plugins, save your project to apply Plugin Manager changes, then test.
    • If this works, then one or more of your plugins (maybe this one that you were trying to make for a Bribe effect) have changed how the interpreter updates. This could have unwanted effects on other elements of your game, e.g. Show Text.

  2. If it still fails with plugins disabled, make a new project and test there.
    • If this works, then your current project's core scripts have probably been edited and/or corrupted in some way. You can restore them by copying over the relevant files from a new project, as mentioned in this announcement under "Updating your Projects":
      This will remove any edits you have made to your project's core scripts. Intentional edits should generally be done in the form of plugins.

  3. If it still fails in a new project with 0 plugins, consider reinstalling RPG Maker MV. Then test again in a new project.
I had it once I made a plugin and change it and nothing working, like the JS file is corrupted,
pasting it in a new document and saved as JS did the job, no idea how a js file could stop working
after an edit.

so you can try this first after updating/re-install MV if needed.

also make sure you have a backup of your project just in case.

Original thread: https://forums.rpgmakerweb.com/threads/bribe-plugin.138041/