MZ How to make pictures clickable via javascript?(SOLVED)

So in MZ there is the built-in plugin ButtonPicture.js. It's great but I lack functionality that would be quite nice and I am wondering how I can make it useable within scripts rather than the plugin commands.

The entire code in the ButtonPicture.js looks like this, it is rather short, so that is quite nice. But since I am quite new, I've spent about 30-40 minutes trying to figure out how this actually works does but I've had no luck...

JavaScript:
(() => {
    const pluginName = "ButtonPicture";

    PluginManager.registerCommand(pluginName, "set", args => {
        const pictureId = Number(args.pictureId);
        const commonEventId = Number(args.commonEventId);
        const picture = $gameScreen.picture(pictureId);
        if (picture) {
            picture.mzkp_commonEventId = commonEventId;
        }
    });

    Sprite_Picture.prototype.isClickEnabled = function() {
        const picture = this.picture();
        return picture && picture.mzkp_commonEventId && !$gameMessage.isBusy();
    };

    Sprite_Picture.prototype.onClick = function() {
        $gameTemp.reserveCommonEvent(this.picture().mzkp_commonEventId);
    };

    Spriteset_Base.prototype.mzkp_isAnyPicturePressed = function() {
        return this._pictureContainer.children.some(sprite =>
            sprite.isPressed()
        );
    };

    const _Scene_Map_isAnyButtonPressed =
        Scene_Map.prototype.isAnyButtonPressed;
    Scene_Map.prototype.isAnyButtonPressed = function() {
        return (
            _Scene_Map_isAnyButtonPressed.apply(this, arguments) ||
            this._spriteset.mzkp_isAnyPicturePressed()
        );
    };
})();

Thanks for any help!

Best regards,
Bishiba
This is the part that performs the click action (queue common event):
JavaScript:
    Sprite_Picture.prototype.onClick = function() {
        $gameTemp.reserveCommonEvent(this.picture().mzkp_commonEventId);
    };
The picture's mzkp_commonEventId property is set via the plugin command.

It looks minimal because it leverages a variety of features that are defined in the core scripts, e.g. the isPressed method of Sprite_Picture, which it inherits from Sprite_Clickable.
This is the part that performs the click action (queue common event):
JavaScript:
    Sprite_Picture.prototype.onClick = function() {
        $gameTemp.reserveCommonEvent(this.picture().mzkp_commonEventId);
    };
The picture's mzkp_commonEventId property is set via the plugin command.

It looks minimal because it leverages a variety of features that are defined in the core scripts, e.g. the isPressed method of Sprite_Picture, which it inherits from Sprite_Clickable.
Indeed, I noticed that it was building on a lot of things in the engine. But the thing I needed was the thing you gave me. I think I was confused, because I actually found that before and just skipped it for some reason... And if you didn't tell me I don't think I would've realized my blunder for a long time!
So thanks! Now to go create some loops for this 🙂

I am very tired at this point, so it's possible I can solve it myself in the morning. But how do I get the ID of the picture I clicked?
Sprite_Picture has a _pictureId property: if you want to get the ID from within the onClick method, it would just be this._pictureId. 👋
Sprite_Picture has a _pictureId property: if you want to get the ID from within the onClick method, it would just be this._pictureId. 👋
Thanks a lot! I ended up just adding my own "lastClickedPicture" and stored the ID in there though. And I did get it from the this._pictureId 🙂

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-pictures-clickable-via-javascript-solved.138624/