Sethorion

Veteran
Veteran
Joined
May 8, 2015
Messages
52
Reaction score
19
First Language
English
Primarily Uses
Outside of SV battle, a character can take damage and die. What is a GOOD way to do that for NPCs and monster events while in a map scene?
NOTE: I've made my character swing his sword in the right direction when you hit the appropriate key, and I can get the event data of the monster that would be hit, so those parts are working. The 'damage' that would be dealt is calculated properly, as is the max HP of the target (based on monster type and level). I just need some way to track the current hp of an event with reasonable and forward-facing code.
 

Iron_Brew

Veteran
Veteran
Joined
Nov 19, 2021
Messages
333
Reaction score
962
First Language
English
Primarily Uses
RMMV
Define a variable to have it increment, have it trigger a self-switch when variable is hits a certain number, then reset the variable if you wanna reuse it.
 

Sethorion

Veteran
Veteran
Joined
May 8, 2015
Messages
52
Reaction score
19
First Language
English
Primarily Uses
Makes sense. So, I would probably need an invisible event that finds the monster events and sets their HP dynamically. I was kinda hoping there was a more dynamic way to do it, but this should be sufficient for now. ty!
 

Sethorion

Veteran
Veteran
Joined
May 8, 2015
Messages
52
Reaction score
19
First Language
English
Primarily Uses
Ideally, I'd love to listen for a `player_transferred` event and run a method checking for monsters on the map he/she just moved to, and making those monster events a new property. Right now I just have an invisible event that runs once after the player arrives in the map.
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
194
Reaction score
173
First Language
English
Primarily Uses
RMMZ
Is there a reason why you don't want to just give the event a "hp" property? Or are you trying to do this without script calls or something?
 

Sethorion

Veteran
Veteran
Joined
May 8, 2015
Messages
52
Reaction score
19
First Language
English
Primarily Uses
I want to have the plugin give it that 'hp' or 'hp_current' property automatically when the player enters the map. I would rather not have lots of events with script calls, as that would confuse future users of the plugin.
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
194
Reaction score
173
First Language
English
Primarily Uses
RMMZ
Oh, you're making a plugin? Sorry, your initial post didn't really make it clear exactly what you're doing. It's a really simple matter in that case, so I thought maybe you were trying to do this all through eventing or something. If you're making a plugin, then just hook into one of the methods that deals with the creation of the events, and then assign the property there. For example:

JavaScript:
(function(alias) {
    Game_Map.prototype.setupEvents = function() {
        alias.call(this);

        for (const event of this._events.filter(event => !!event)) {
            event.hp = 500;
        }
    };
})(Game_Map.prototype.setupEvents);

That will make it so that when you enter a map, it will iterate through all events on the map and give them a hp property with an initial value of 500. Of course, you're probably going to want to pull the hp value from a note tag, or from some calculation or something, rather than assigning a flat value like I did in the example.

*edit* I should mention that I wrote that based on MZ's code base, because I already had it open in VS Code and didn't feel like switching. Pretty sure it won't matter in this case, but in the event that it doesn't work, that's probably why.
 
Last edited:

Sethorion

Veteran
Veteran
Joined
May 8, 2015
Messages
52
Reaction score
19
First Language
English
Primarily Uses
Ah, this answers so many questions. Ty!
 

Sethorion

Veteran
Veteran
Joined
May 8, 2015
Messages
52
Reaction score
19
First Language
English
Primarily Uses
Sorry for the double-post, but this actually spat out an error the moment I clicked "New Game". I must have an outdated plugin or something:
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
194
Reaction score
173
First Language
English
Primarily Uses
RMMZ
That shouldn't have anything to do with my code. When the error occurs, can you press F8 to open up the console, and post a picture of it? The stack trace might help us figure out what's going on.
 

Sethorion

Veteran
Veteran
Joined
May 8, 2015
Messages
52
Reaction score
19
First Language
English
Primarily Uses
Here's the stack trace
EDIT: I found the issue. It was this:
JavaScript:
// Game_Player.prototype.performTransfer = function() {
// };
I thought I had commented it out, but I just found that I hadn't...
 
Last edited:

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
194
Reaction score
173
First Language
English
Primarily Uses
RMMZ
Glad you got it figured out.
 

Latest Threads

Latest Posts

Latest Profile Posts

HexMozart88 wrote on RHachicho's profile.
Hey wait a minute, I remember you!
Granny.gif
Nap! Knit! Read! Repeat!
Granny's got a busy life now :3
Бас Лого.png
Reflections on the topic of choosing the path of the main character )

Forum statistics

Threads
121,908
Messages
1,145,081
Members
160,168
Latest member
estanislao21
Top