Lark_Larkington

Villager
Member
Joined
Mar 2, 2021
Messages
7
Reaction score
2
First Language
Dutch
Primarily Uses
RMMV
Dear all,

I'm just getting started with MV and have little coding experience. I would like to create save points that do the following:
IF [actor] was below 50% of their maximum health, THEN their health is set to 50% of their maximum health.

In other words, this would not trigger if the actor has 50% or more of their maximum health. I don't think I can get this done without coding, so I'd greatly appreciate it if someone who knows JS could type out the required lines for me.

Many thanks <3
 

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
482
Reaction score
693
First Language
German
Primarily Uses
RMMV
Should this affect the entire group or just specific actors?
Should this affect dead characters aswell?

Until then, you can try this Script-Call (It is found on Page 3 At the bottom right of the event tabs):

JavaScript:
let targets = $gameParty.members();
targets.forEach(function(target) {
  if (target.hpRate() < 0.5) {
    target.setHp(target.mhp * 0.5);
  }
});

Alternatively, you can probably do this with just events instead of actual codes, but I don't have enough time to write that out right now.
 
Last edited:

Lark_Larkington

Villager
Member
Joined
Mar 2, 2021
Messages
7
Reaction score
2
First Language
Dutch
Primarily Uses
RMMV
Should this affect the entire group or just specific actors?
Should this affect dead characters aswell?

Thanks! I want certain characters to be unaffected, though, so I want the script to target a specific actor. I figured I'd repeat the script a few times for all actors that I want to be affected.
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
933
Reaction score
492
First Language
English
Primarily Uses
RMMV
There's a more efficient way to do this with Javascript and a plugin, but you don't need to - you can do it with just event commands.

Control Variable variableOne Set to Game Data Actor 1 HP
Control Variable variableTwo Set to Game Data Actor 1 Max HP
Control Variable variableTwo Div 2
Conditional Branch variableOne < variableTwo
- do your healing stuff

Then repeat for each party member. This presumes you know which actors are in your party, if you have a system where you'll be swapping out different actors, you'll need to make the plugin (or a really over-convoluted event where you first check whether every possible actor is in your party).
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,516
Reaction score
8,147
First Language
German
Primarily Uses
RMMV
I don't think I can get this done without coding,
you are wrong, it can be done with pure eventing.
However the fact that you don't know this is not unique, because the needed event options are a bit hidden.

go to control variable, set the lower section to game data (the one that defaults to Map ID) and then click on the dots to the right of "map id" to open the game data window.
In that window you can select hundreds of different game data options including the actor HP and actor MaxHP, then use conditional branch and mathematics to compare the numbers and decide whether to heal or not.

ninja'd
 

Lark_Larkington

Villager
Member
Joined
Mar 2, 2021
Messages
7
Reaction score
2
First Language
Dutch
Primarily Uses
RMMV
I got it done with variables and conditionals! Thanks guys. Looks like I can do a lot more than I thought without coding.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,040
Reaction score
2,297
First Language
English
Primarily Uses
RMMV
If you do want to use a script though (which will be useful for expanding which characters are affected, or removing some you realise shouldn't be any more) you can do

var actors = [1, 3, 5, 7];

$gameParty.aliveMembers().forEach(actor => (actors.contains(actor.actorId()) && actor.hpRate() < 0.5) ? actor.setHp(Math.ceil(actor.mhp * 0.5)) : actor);
 

Latest Threads

Latest Posts

Latest Profile Posts

I managed to fix my car at last... :biggrin:

I'm proud of what I have achieved with my project. Don't mind with the Spanish, Ill add more languages.
Our garage has been so full since moving we haven't been able to get our car in. Storm night before last (no hail), storms forecast for last night & today. I convinced hubby we should clean out the garage and we managed to get it done and get the car in. Hail last night! Just in time!
Taller RTP Characters, Rewrite Dialogues w/ AI, & Simple Event AI & Shooting | RPG Maker News #37

Forum statistics

Threads
111,278
Messages
1,059,847
Members
144,578
Latest member
rodeorodent
Top