MZ Show image instead of flash color for battle

Hi folks,

I have currently tweaked the color of the flash that happens for battle with this code:

JavaScript:
Scene_Map.prototype.startFlashForEncounter = function(duration) {
    const color = [103, 75, 128, 200];
    $gameScreen.startFlash(color, duration);
};

However, I would like to flash an image on the screen (with the same fade in/fade out that the color usually has).

I tried changing it to this:

JavaScript:
Scene_Map.prototype.startFlashForEncounter = function(duration) {
    $gameScreen.showPicture(71, "Sleep", 0, 0, 0, 100, 100, 0, 0);
    $gameScreen.movePicture(71, "Sleep", 0, 0, 0, 100, 100, 255, 0, 30, 0);
    $gameScreen.movePicture(71, "Sleep", 0, 0, 0, 100, 100, 0, 0, 30, 0);
    $gameScreen.erasePicture(71);
};

...but that doesn't work. I figure I probably need to change some different part of the code, but I'm just messing with stuff that other folks have written as I know nothing about JS or how any of this works.

Is there a simple way to tweak this code to instead flash a designated image? The idea would be to use an image that is the same size as the screen.

Thanks!
The second movePicture will override the first, then the erasePicture at the end will erase the picture before it has a chance to display at all. There's no "Wait for completion" checkbox here.

What if you started the picture at 100% opacity immediately, like Flash Screen does? E.g. (untested):
JavaScript:
Scene_Map.prototype.startFlashForEncounter = function(duration) {
  const id = 71;
  const name = "Sleep";
  const origin = 0;      // 0~1: Top Left, Center
  const x = 0;
  const y = 0;
  const scaleX = 100;
  const scaleY = 100;
  const opacity0 = 255;  // starting opacity 0~255
  const opacity1 = 0;    // ending opacity 0~255
  const blendMode = 0;   // 0~3: Normal, Add, Multiply, Screen
  const frames = 30;     // fade duration (frames)
  const easing = 0;      // 0~3: None, Slow start, Slow end, Slow start & end
  $gameScreen.showPicture(
    id, name, origin, x, y, scaleX, scaleY, opacity0, blendMode
  );
  $gameScreen.movePicture(
    id, origin, x, y, scaleX, scaleY, opacity1, blendMode, frames, easing
  );
};

[Edit: renamed const duration to const frames, to fix issue pointed out by OP.]
The second movePicture will override the first, then the erasePicture at the end will erase the picture before it has a chance to display at all. There's no "Wait for completion" checkbox here.

What if you started the picture at 100% opacity immediately, like Flash Screen does? E.g. (untested):
JavaScript:
Scene_Map.prototype.startFlashForEncounter = function(duration) {
  const id = 71;
  const name = "Sleep";
  const origin = 0;      // 0~1: Top Left, Center
  const x = 0;
  const y = 0;
  const scaleX = 100;
  const scaleY = 100;
  const opacity0 = 255;  // starting opacity 0~255
  const opacity1 = 0;    // ending opacity 0~255
  const blendMode = 0;   // 0~3: Normal, Add, Multiply, Screen
  const duration = 30;   // fade duration (frames)
  const easing = 0;      // 0~3: None, Slow start, Slow end, Slow start & end
  $gameScreen.showPicture(
    id, name, origin, x, y, scaleX, scaleY, opacity0, blendMode
  );
  $gameScreen.movePicture(
    id, origin, x, y, scaleX, scaleY, opacity1, blendMode, duration, easing
  );
};

Awesome, this worked! I had to change the name of "duration" since it was already declared, but then it all worked perfectly.

Original thread: https://forums.rpgmakerweb.com/threads/show-image-instead-of-flash-color-for-battle.175203/