0% found this document useful (0 votes)
99 views

JS Codes

The document provides code snippets for various battle mechanics in RPG Maker MZ including: 1) Setting a home position after a skill and dealing damage when removing a state. 2) Enabling skills based on HP percentage and inventory items. 3) Applying damage and healing over time as states expire or turns pass. 4) Targeting skills based on the last attacking enemy and increasing critical hit chance after multiple attacks. 5) Restricting items and manually increasing actor AP. 6) Displaying state counts and stacking damage. 7) Sharing a macro for displaying stats and examples of counters and regeneration.

Uploaded by

ShayneHurdle
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

JS Codes

The document provides code snippets for various battle mechanics in RPG Maker MZ including: 1) Setting a home position after a skill and dealing damage when removing a state. 2) Enabling skills based on HP percentage and inventory items. 3) Applying damage and healing over time as states expire or turns pass. 4) Targeting skills based on the last attacking enemy and increasing critical hit chance after multiple attacks. 5) Restricting items and manually increasing actor AP. 6) Displaying state counts and stacking damage. 7) Sharing a macro for displaying stats and examples of counters and regeneration.

Uploaded by

ShayneHurdle
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

--Set home position in battle after a skill

<JS Post-Apply>
user.setHome(user._homeX - 64, user._homeY);
</JS Post-Apply>

--For a state that deals 5% damage to a random enemy when removed:

Code:
<JS On Erase State>
const targetId = Math.randomInt($gameTroop.aliveMembers().length);
const target = $gameTroop.aliveMembers()[targetId];
const damage = Math.floor(target.mhp * 0.05);
target.gainHp(-damage);
</JS On Erase State>
For your expire:

Code:
<JS On Expire State>
target.addState(ID of new state);
</JS On Expire State>

--Let's say you want a state to deal 10% + 10 damage to the sufferer per turn:

Code:
<JS HP Slip Damage>
damage = Math.floor(target.mhp * 0.1) + 10;
</JS HP Slip Damage>

--
1) A skill that is only enabled when HP is 70% of that actor's Max HP and disabled
otherwise. Without any HP Costs involved if that makes sense?

2) 5 Potions in the Inventory needed for a skill to be enabled, and it's disabled
if that number drops. Without any x5 Potion costs attached to the skill.

Code:
<JS Skill Enable>
enabled = user.hpRate() <= 0.7;
</JS Skill Enable>
and

Code:
<JS Skill Enable>
enabled = $gameParty.numItems($dataItems[id of potion]) >= 5;
</JS Skill Enable>

--
<JS Passive Condition>
code
code
condition = target.hpRate() >= 0.75;
</JS Passive Condition>
If i need this passive to only be active if the user is above 75% HP

--

<JS Pre-Damage as User>


if (!user.isStateAffected(14)) {
user._attackStack = user._attackStack || 0;
user._attackStack++;
user.setStateDisplay(11, user._attackStack);
if (user._attackStack == 3) {
user.addState(14);
}
}
</JS Pre-Damage as User>
Replace 11 with the ID of your passive state and 14 with the ID of a new state;
call it "attack crit up" or whatever name you want to give it.
The state should add 50% critical rate, and have the following notetag:

Code:
<JS Post-Damage as User>
delete user._attackStack;
user.setStateDisplay(11, "");
user.removeState(14);
</JS Post-Damage as User>
Replace 11 with the ID of your passive state and 14 with the ID of the state you
just created.
This will cause every 3rd hit that actor makes to have 50% increased crit chance
which will reset after their next hit (misses shouldn't affect it).
The state will show just the icon, then a "1", then a "2", with the next hit after
that being the boosted one.

--

<JS Item Enable>


enabled = BattleManager.actor().actorId() === ID OF ACTOR;
</JS Item Enable>
And that item will only appear to the character who can use it.
The colouring issue is a bit more complex since it's being caused by the dark item
rects and those are built in to some of the functions being called by the shop menu
code.
You could replace these with your own versions but that'd be quite involved; Yanfly
said he'll add a parameter for changing the dark rect colour in a later update,
which should resolve this for you.

--

You need to edit the JS: Draw Gauge section: change the "const label" line to say
"Fury" rather than the TP name from TextManager
(you can also change the colour values here as I imagine you'd probably prefer it
to be red rather than green)

--
5 flat heal, and each extra point of MAT above 15 add 2 additional healing
<JS HP Slip Heal>
heal = 5 + Math.max(user.mat - 15, 0) * 2
</JS HP Slip Heal>

-------
Something like

Code:
<JS On State Apply>
target._stateStacks = target._stateStacks || 0;
target._stateStacks++;
target.setStateDisplay(id of state, target._stateStacks);
</JS On State Apply>
This would only handle the visual part; actually having it do different things
depending on number of stacks would be separate, like

Code:
<JS HP Slip Damage>
target.gainHp(-(target._stateStacks * 10));
</JS HP Slip Damage>

-------------
Is there a way to manually increase an actor's AP?
It's something like:
$gameActors.actor(x).gainAP(n);

(how to set display.)


battler.getStateDisplay(stateId)
battler.setStateDisplay(stateId, value)
battler.clearStateDisplay(stateId)

-----For Action Sequence use to check if target is affected by state and if passive
state

BattleManager._target && BattleManager._target.isStateAffected(82)


You want to make sure the target exists first
So you can avoid crashes
if its passive
hasState(x) instead of isStateAffected

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

Sharing a useful macro for Message Core real quick. It basically allows you to
display stats in an esthetic way.

const statname = $dataSystem.terms.basic[3];


const count = arguments[1];
return '\x1bc[18]' + count + ' \x1bi[247]' + statname + '\x1bc';

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

small example for a stacking state if anyone needs


<JS MaxHP Rate: (1 - ((this.woundcount ? this.woundcount : 1)*0.04))>

<JS On Add State>


if (target.woundcount) {
target.woundcount += 1;
} else {
target.woundcount = 1;
}
target.setStateDisplay(state.id, target.woundcount);
</JS On Add State>

<JS On Erase State>


target.woundcount = 0;
</JS On Erase State>
///////////////////////////////

idea for improvement: factor in enemies countering you, as well as you countering
enemies
<JS Targets>
//const counter = $gameTroop.members()[$gameTemp.lastActionData(3) - 1];
targets = [];
const counter = this.opponentsUnit().members()[$gameTemp.lastActionData(3) - 1];
targets.push(counter);
</JS Targets>
<Auto Trigger: Physical Enemy>

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

Requires AutoSkillTriggers
To make a counter-attack:

1. Make a state that adds your counter-attack skill


2. Add this piece of code in the skill notetag:
<JS Targets>
const counter = $gameTroop.members()[$gameTemp.lastActionData(3) - 1];
targets.push(counter);
</JS Targets>
<Auto Trigger: Physical Target>

You can change auto-trigger as you want for other means, but this makes it so the
skill always targets the last enemy that attacked the player

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

<JS HP Slip Damage>


// Get the element ID.
var elementId = 2;
// Set the damage for the effect.
var baseDamage = a.mat * 1.5;
// Calculate the damage after applying the target's element rate.
damage = Math.ceil(target.elementRate(elementId) * baseDamage);
</JS HP Slip Damage>

I was messing around with an old state from my MV project and managed to get a slip
damage state to calculate a target's element rate in MZ. Original code was based on
an old Tips and Tricks

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

let party = $gameParty.allMembers();


for (let member of party) {
if (member._cache.param1Total != 0) {
if (member._mp != member._cache.param1Total) {
let manaMax = member._cache.param1Total;
let manaNow = member._mp;
let regenRate = member.mrg
let regenValue = Math.round(manaMax * regenRate)
if (regenValue <= 1) {
regenValue = 1
}
member._mp = Math.min(manaMax, manaNow + regenValue);
}
}
}

simple dynamic mana regen code if anyone wants it, just put it on a loop with
desired wait time and it'll plink away regenerating mana for your characters in
real time (does not work during battle)

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

made a skill that deals damage and then heals all allies for a portion of the
damage dealt. I don't know if anyone else would want this, but I thought I'd share
this because I spent a little bit of time troubleshooting how to make this work for
MZ. It's based off an old Yanfly Tips and Tricks from MV.

<JS Post-Damage>
if (target.result().hpDamage > 0) {
// establish the rate of healing proportional to damage dealt
var healRate = 0.5;
// establish the actual amount of healing to be done
var healValue = Math.floor(target.result().hpDamage * healRate);

// creates "allies" as an array of all living allies


var group = user.friendsUnit();
var allies = group.aliveMembers();

// for loop to run through every member of "allies" and heal them
for (var i = 0; i < allies.length; i++) {
var ally = allies[i];
ally.gainHp(healValue);
ally.startDamagePopup();
}

user.clearResult();
}
</JS Post-Damage>

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

You might also like