MZ Replace Right Click and get a mouse click on WorldMap

I’m now creating a rpg maker survival game with building system. Now I have a switch menu for building where i can choose which building i will create.
B5F94685-7DA0-489A-AEC9-E738628AC15D.jpeg
This menu binded on shift(dash on game disabled)
I need a js plugin which be doing: Start a common event on right click(and disable menu on right click), which be in plugin menu
And a 2 variables: x and y world position of mouse click.


This need for placing block in mouse position, thank you in advance
Something like this? (Should work for both MV and MZ.)

JavaScript:
// Edit these for your use-case.
const commonEventId = 0;
const xVariableId = 0;
const yVariableId = 0;

const oldUpdateCallMenu = Scene_Map.prototype.updateCallMenu;
Scene_Map.prototype.updateCallMenu = function() {
    // Mask out right-clicks from the usual menu call.
    if (TouchInput.isCancelled()) {
        // Make sure there's no scripted scene running already.
        if (!$gameMap.isEventRunning() && !$gameTemp.isCommonEventReserved()) {
            $gameVariable.setValue(xVariableId, $gameMap.canvasToMapX(TouchInput.x));
            $gameVariable.setValue(yVariableId, $gameMap.canvasToMapY(TouchInput.y));
            $gameTemp.reserveCommonEvent(commonEventId);
        }
    } else {
        return oldUpdateCallMenu.apply(this, arguments);
    }
};

I didn't test that, but unless I have a typo somewhere, I'm 95% sure it'll just work.
Sorry about the lack of help text and formal plugin parameters - that always takes me a lot of time to set up properly and, for a one-off, editing these three values in the script directly seems okay in my eyes.

Original thread: https://forums.rpgmakerweb.com/threads/replace-right-click-and-get-a-mouse-click-on-worldmap.161852/