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
461
Reaction score
676
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
791
Reaction score
431
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,380
Reaction score
8,098
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
2,961
Reaction score
2,239
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

Unironically, no joke, after consideration and self-reflection, I have decided that the best thing for my creative/workflow/commitment problems is to spend EVEN MOAR hours a day playing videogames than I normally do. (Micro-thread)
FINALLY got my weather system implemented. Who needs a black mage when you have a weathermancer! :p
Oh boy! COVID19 lockdown again! Good thing I already never go outside! :D
This one is less showing off and more 'I really don't know how I feel about this one.' The 'child' sprite template I made either works great or doesn't at times. (She is a fairy, so I made her small).
Morgan.png

Forum statistics

Threads
110,640
Messages
1,054,877
Members
143,766
Latest member
systemdisco
Top