Help editing a plugin? (Probably simple, but I can't understand code)

I found a plugin that I really like that lets you display the HP bar on the map outside of battles. It fits in super well with my game and I can't find another plugin that works as well as this one does, but the creator of the plugin neglected to add the ability to hide it with an event when it's not needed. If anyone is good at coding, can you please write out the code I would need to add to the plugin to make this feature possible and tell me where in the code to put it? I'm not new to game design, but I am new to coding, so this would really help me out a lot. Thanks a bunch in advance!

This is the author of the plugin:
https://forums.rpgmakerweb.com/index.php?members/mrcopra.66846/

And here's the code I need edited:
/*:
* @plugindesc HealthBar
* @author mrcopra
*
* @Help
*
*/
(function() {


//////////////////////////////////////////////////////////////////////////////////////

var _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
_Scene_Map_start.call(this);
this._myWindow = new My_Window(100,100);
this.addWindow(this._myWindow);
};

var _Scene_Map_update = Scene_Map.prototype.update;

Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
this._myWindow.refresh();
};



function My_Window() {
this.initialize.apply(this, arguments);
}

My_Window.prototype = Object.create(Window_Base.prototype);
My_Window.prototype.constructor = My_Window;


My_Window.prototype.initialize = function(x, y) {
Window_Base.prototype.initialize.call(this, 0, 0, this.windowWidth(), this.windowHeight());
this._value = -1;
this.refresh();
};

My_Window.prototype.refresh = function(){

this.contents.clear();
this.drawActorHp($gameParty.leader(), 0, 0, 200)
};

My_Window.prototype.windowWidth = function(){
return 240;
};
My_Window.prototype.windowHeight = function(){
return 80;
};

///////////////////////////////////////////////////////////////////////////////////////////////
})();

I've moved this thread to Plugin Support. Thank you.

You want to be careful putting a call to your window's refresh method inside the map's update method. This is going to cause the window to be redrawn on every frame, rather than just when the player's HP is changed, and could make your game lag a bit.

You might notice (going from memory here as I don't have MV in front of me, so I might get this a little wrong), that there is both an update method and a refresh method for the map (I'm not sure if they're both in Scene_Map or if one is in Scene_Map and the other's in Game_Map). The refresh method is only called when certain things happen - party leader is changed, party members are changed, switches and variables are changed, some other things. When those things happen, there is a $gameMap._needsRefresh flag that's turned on, and if that's on when the map updates, it calls the refresh method. I think you would be better off putting the call to your window's refresh method in there, rather than in update, and making sure that needsRefresh flag is turned on when an actor's HP is changed.

The most simple thing you could do is just change the visible parameter based on a switch, then turn the switch on/off when you want to show/hide the window. Try this (again, I don't have MV with me, so I can't test it, so it might be completely wrong)

this._myWindow.visible = $gameSwitches.value(15);

right where you've currently got this._myWindow.refresh();
You want to be careful putting a call to your window's refresh method inside the map's update method. This is going to cause the window to be redrawn on every frame, rather than just when the player's HP is changed, and could make your game lag a bit.

You might notice (going from memory here as I don't have MV in front of me, so I might get this a little wrong), that there is both an update method and a refresh method for the map (I'm not sure if they're both in Scene_Map or if one is in Scene_Map and the other's in Game_Map). The refresh method is only called when certain things happen - party leader is changed, party members are changed, switches and variables are changed, some other things. When those things happen, there is a $gameMap._needsRefresh flag that's turned on, and if that's on when the map updates, it calls the refresh method. I think you would be better off putting the call to your window's refresh method in there, rather than in update, and making sure that needsRefresh flag is turned on when an actor's HP is changed.

The most simple thing you could do is just change the visible parameter based on a switch, then turn the switch on/off when you want to show/hide the window. Try this (again, I don't have MV with me, so I can't test it, so it might be completely wrong)

this._myWindow.visible = $gameSwitches.value(15);

right where you've currently got this._myWindow.refresh();
Thank you so much for taking the time to write out a reply, but I'm still a little confused. I tried inputing the code you gave me (Thank you so much by the way, I have no idea how to code) but I think it may have broken the plugin. Do you have any other suggestions?
You could just use SRD's HUD Maker (requires Super Tools Engine too) which I think allows switches to turn off the HUD stuff at will, watch the videos too.

http://sumrndm.site/super-tools-engine/
http://sumrndm.site/hud-maker

Original thread: https://forums.rpgmakerweb.com/threads/help-editing-a-plugin-probably-simple-but-i-cant-understand-code.106828/