Lordjovian

Warper
Member
Joined
Nov 21, 2019
Messages
2
Reaction score
0
First Language
English
Primarily Uses
RMMV
Hello! Disclaimer first - I am the worst human at scripting. I've thrown together a script from several different resources, and I'm assuming it's beyond broken and need some help.

Goal: I want an equipped armor (e.g. a shield) to "break" when the attacked party member's HP hits a certain percentage. By "break" I mean swapping the good version of the item to a broken version of the item. Example: Bob has the Iron Shield equipped. During combat, a monster hits Bob with a physical attack and his health drops to 25% or lower, causing the Iron Shield to be swapped out to the Broken Shield. The attack must be a physical attack - if a spell causes Bob to drop below 25%, the shield stays intact UNTIL Bob is struck with a physical attack, therefore breaking the shield.

What I've done:
I have given all enemies a "monster attack" skill. This skill replaces the default "Physical Attack." It's a clone of the default physical attack, except I've added a Common Event to the Effects.
This common event (script will be below) will check to see if the attacked players HP is below 25%.
If it is, it retrieves the ArmorID of the item in the Shield slot, unequips the attacked player's item in the Shield slot, removes the ArmorID of the shield they had equipped from the party, adds the Broken Shield to the party's inventory, then equips the newly added Broken Shield on the attacked player. At the end, it displays a message that your shield is an ex-shield.

Common Event Script:
if (b.hp <= b.hp*0.25)
{

{$gameVariables.setValue(5, $game_actorsBRACKETb].equips[4].id unless $game_actorsBRACKETb].equips[4] == nil)

$gameActors.actor(b).clearEquipments(4);

$gameParty.gainItem($dataArmors[\v[5]], -1, false);

$gameParty.gainItem($dataArmors[11], 1, false);

$gameActors.actor(b).changeEquip(4, $dataArmors[11]);

$gameMessage.setFaceImage(0)

$gameMessage.setBackground(1)

$gameMessage.setPositionType(1)

$gameMessage.add("The shield has been destroyed!")

} else {}

EDIT: BRACKET = [
I had to fix that as it was causing bolding.

PROBLEM: I get a syntax error that a "(" was not closed. They all look pretty closed to me?
I'm sure I'm going about this an odd way and there's a strong possibility I might even be totally using the scripting feature wrong.

Could someone point to my mistake in the script, or if I'm doing something that totally doesn't work? It seems a rather "simple" scripty job to run the check, and if it fails grab the item, unequip, delete, add, equip.

As to why this mechanic - even though the shield is broken, it's still partially a shield. The Broken Shield is an armor item that still has some protection, but not much. I want the player to have a more permanent penalty when nearly losing a battle. Instead of just drinking potions and casting healing spells to continue skipping around the dungeon merrily, they have to deal with the loss of some gear. This either prompts them to get out of dodge, or make the decision to press on with the penalty.

Thanks in advance!
 

trapless

Veteran
Veteran
Joined
Mar 3, 2014
Messages
43
Reaction score
17
First Language
English
Primarily Uses
RPG Maker MV does not use the Ruby programming language but your code does.
 

Lordjovian

Warper
Member
Joined
Nov 21, 2019
Messages
2
Reaction score
0
First Language
English
Primarily Uses
RMMV
Yikes!?

I'm not sure how that happened - I've been piecing together scripts and variables from RMMV resources online.

Such as this, this, and this.

Are these the wrong resources? I might be completely off the right path then.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
659
Reaction score
372
First Language
German
Primarily Uses
Hey there,

Most of your code is valid in Javascript, you probably tripped up in line 3 where you use
$game_actors[X] (used in RMXP through RMVXAce) and
X unless Y (Ruby syntax, not allowed in Javascript).

As for the error, you have 2 opening curly brackets in line 2 and 3, but only one matching closing one towards the end.
Also, it looks like you made a typo in the condition in line 1.

Apart from that, a, b and v are only available in damage formulas by default (these variables are set by the game for damage calculation).
For events you'd need to find another way to identify your last targets (if there were any):
- You could just check all party members (this would also break the shields of members who dropped to 25% by other means)
- You could make the skill inflict an invisible state and make the common event check for it
- You could save the target in a variable using the damage formula
- You could drop the common event

To apply your code to all party members you could use a loop:
Code:
// Cycle through all party members (using b as an identifier for each one)
for (var b of $gameParty.members()) {
    ... // <Original Code>
}
To check the actor for a state you can use
b.isStateAffected(state-Id)
in your if-statement if necessary.

Alternatively you could drop the common event in favor of a plugin like Yanflys Skill Core, which would allow you to run your code whenever the skill is used on a target (by putting it in your skills notebox):
Code:
<after eval>
if (b.result().isHit()) {
    ... // Your original code
}
</after eval>

A few notes about the rest (sorry if uncalled for :)):

$gameActors.actor(15)
is useful when you know an actors database ID but need the corresponding actor. In your case, "b" already is your actor.

b.equips()[4]
In MV, you need an extra pair of brackets to get an actors equipment, since equips is a function.

actor.clearEquipments()
clears all equipment the actor is wearing, not just one piece. To clear a specific slot, you can equip "null" (without quotes) in it.

\v[5]
is a code used in some messages and is not valid Javascript code.
In damage formulas you can use v[5] instead, but in general the Javascript equivalent for reading a game variable should be
$gameVariables.value(5)

Instead of
actor.changeEquip(...)
you could also use
actor.forceChangeEquip(...)
It has the same effect for the actor, but it does not check/change your partys inventory.

Apart from that it looks good. :)
 
Last edited:

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
14,338
Reaction score
15,504
First Language
English
Primarily Uses
RMVXA

I've moved this thread to JavaScript Support. Thank you.

 

Latest Threads

Latest Profile Posts

This is a really good video
Testing Parry/Counter system straight from Action Sequence instead of utilizing the default counter.
Quite happy with the result so far.
Bex
This just blew my mind.
RMMZ can choose Tilesize.
No complicated Plugin needed, it is a simple inbuild Option.
This means you could literally use all your rm2k3 or vx-ace Tilesets and Characktersets in RMMZ.
This also makes me curious about experimenting with smaler Tiles and higher Screen Resolutions for non RPG Games.
mztilesize1414564.png
Did you know about this?
Just gonna leave this here lol. 7th cycle endless mode :D 700% enemy dmg or something.

Forum statistics

Threads
126,983
Messages
1,182,867
Members
166,837
Latest member
kasuga24
Top