MZ Hello and question!

Hi people!

Recently have dove into the wonderful world of RMMZ and having a blast. Absolute beginner at this stage mostly working on the maps, menus, databases for items and weapons and slowly working on scripting in events, quests and specific zone/map features.

My Java script knowledge is a bit sketch as most of my previous programming experience (self taught) has been dabbling in various C languages, so I have a few things I’m trying to implement in my first game that I’m having trouble finding in the software and/or finding help writing code for.

What I’m trying to do is have HP regen halted while in a certain maps only (dungeons) and have it work normally otherwise. I’d like this to either toggle on/off when entering/leaving these areas or to have that specific map have a state of no regen constantly. Not sure if the best way to achieve this.

I found this code doing some Google searching

const disableMapRegen = Game_Battler.prototype.regenerateHp;
Game_Battler.prototype.regenerateHp = function() {
if (!$gameParty.inBattle()) return;
disableMapRegen.apply(this);
};


Which turns off regen like expected but it’s global and not just in the map I’ve chosen. With my lack of JavaScript knowledge Im not exactly sure how to change it to work like I want and still lack the knowledge to write a script from scratch myself. I’ve been reading other peoples code to try and understand syntax and how the code functions, to some success (can generally make out what the code is *doing* but syntax is my Achilles heel right now)

Would someone be kind enough to either help with coding this, show me if this is possible in the editor and/or possibly point me to a resource that can help me learn more about the different code elements to better understand things like functions, tags, syntax etc?

Many thanks in advance!

Caco.
I found this code doing some Google searching

const disableMapRegen = Game_Battler.prototype.regenerateHp;
Game_Battler.prototype.regenerateHp = function() {
if (!$gameParty.inBattle()) return;
disableMapRegen.apply(this);
};


Which turns off regen like expected but it’s global and not just in the map I’ve chosen.
You can just turn on an "inDungeon" switch when you enter a dungeon and change this line of code
Code:
if (!$gameParty.inBattle()) return;
to
JavaScript:
if (!$gameParty.inBattle()||!$gameSwitches.value(x)) return;

Where x is the switch number for "InDungeon"
You can just turn on an "inDungeon" switch when you enter a dungeon and change this line of code
Code:
if (!$gameParty.inBattle()) return;
to
JavaScript:
if (!$gameParty.inBattle()||!$gameSwitches.value(x)) return;

Where x is the switch number for "InDungeon"
Aha, thank you. Will this return the regen value back to what it was or will I need to record that value into a variable so it can be restored after leaving?

I was reading some JavaScript syntax on a website I found last night and started writing the following code thinking I may need to allow for the above thought….

function Scene_Dungeon() {
this.initialize.apply(this, arguments);
Scene_Dungeon.prototype = Object.create(Scene_Base.prototype);
Scene_Dungeon.prototype.constructor = Scene_Dungeon;
}

Scene_Dungeon.prototype.initialize = function() {
Scene_Base.prototype.initialize.call(this);
this._isDungeonZone = false;
this._dungeonID = 10;
}

Scene_Dungeon.prototype.noRegen = function() {
Scene_Base.prototype.noRegen.call(this);
this._transfer = $gamePlayer.isTransferring();
var mapId = this._transfer ? $gamePlayer.newMapId() : $gameMap.mapId();
if (mapID == this._dungeonID) {
this._isDungeonZone = True;
}
}

const oldRegenValue = Game_Battler.prototype.regenerateHp;
const disableMapRegen = Game_Battler.prototype.regenerateHp;
Game_Battler.prototype.regenerateHp = function() {
if (this._isDungeonZone){
disableMapRegen == 0;
disableMapRegen.apply(this);
}

else
oldRegenValue.apply(this);
}

Not sure if I’m over complicating the issue but it was something I was trying to put together to restore the original value since the characters may be wearing items that increase the regen?

Thank you for your input thus far, I’ll have a play with setting a switch and using that in part of the code to simplify it when I get home tonight.
Not sure if I’m over complicating the issue
Well... you definitely are. All you need is the line from AquaEcho, and to set a switch when entering a dungeon area and turn said switch off when leaving it.

In general, I'd highly recommend familiarising yourself with eventing, switches and variables before trying to do code-related things.

Also, I'm not sure where you got that code block from, but that is definitely not what scenes do. And in general most of it appears to be gibberish - I'm assuming it's AI generated? If so, that is definitely not something I'd recommend playing with while you're still a beginner - AI plugins require a lot of manual work to turn them into something usable, you won't get much use of them at this stage.
Well... you definitely are. All you need is the line from AquaEcho, and to set a switch when entering a dungeon area and turn said switch off when leaving it.

In general, I'd highly recommend familiarising yourself with eventing, switches and variables before trying to do code-related things.

Also, I'm not sure where you got that code block from, but that is definitely not what scenes do. And in general most of it appears to be gibberish - I'm assuming it's AI generated? If so, that is definitely not something I'd recommend playing with while you're still a beginner - AI plugins require a lot of manual work to turn them into something usable, you won't get much use of them at this stage.
I appreciate your honesty Mac and, to answer your question, I was reading a JavaScript website that explained individual operators, function, etc. and tried to use the examples to build a script that way.

I have since found the tutorial series on the forums and am reading through those while also looking at other people’s code to see how they are writing theirs…

I wasn’t sure if the switch, when turned off, if it would return the original value, a byproduct of still learning. (I’m still at work and haven’t been back at the computer to try Aqua’s code yet)

This was an attempt in trying to understand how lines get written to fulfil a desired result. Just a way I used to play around with C++/C# to learn how things work. Trial and error in the past has taught me how to do thing’s occasionally, thought often how not to, but that in itself can be a useful lesson. I understand that haphazardly writing code to see if it might work isn’t the best or most efficient avenue to take to learn, just me punching above my weight I suppose. I guess what I’m trying to say is I don’t want to give the impression that I want others to do all the work for me, so to speak, and am trying to take some initiative in the problem solving.

I have since taken a step back and just reading through as many tutorials as I can which has helped in understanding some things but the editor help only shows very simple or niche examples. This is why I brought my question here and I’m very thankful for the advice given so far.

Java is probably one of the few languages I have next to no experience with so I may have to lower my expectations. I will take the advice given and report my results.

Again, thank you for the input, so far I’m very impressed with this community and look forward to more discussions!
Java is probably one of the few languages I have next to no experience with so I may have to lower my expectations.
Note that Java is not JavaScript. They have similar names, but are two different programming languages.

JavaScript syntax is based on C++, so you really should be able to understand and work in most of the code that you see in RPG Maker. For example, the line @AquaEcho gave you initially would be written identically in C++ (although most people would put a space around the boolean operators).

When you start getting into function declarations and aliasing/overwriting functions, that syntax is JavaScript-specific, but there's no need for you to get into that in order to accomplish what you're asking for.

Original thread: https://forums.rpgmakerweb.com/threads/hello-and-question.164988/