Creating a dynamic basic attack with Yanfly's weapon unleash and a custom function
BMM Archive · July 16, 2026
Original Source
- Original title: Creating a dynamic basic attack with Yanfly's weapon unleash and a custom function
- Original author: ThreeSixNine
- Original date: February 10, 2020
- Source thread: https://forums.rpgmakerweb.com/threads/creating-a-dynamic-basic-attack-with-yanflys-weapon-unleash-and-a-custom-function.118095/
- Source forum path: Game Development Engines > RPG Maker Tutorials > RMMV Tutorials
Summary
Greetings makers! ThreeSixNine here, bringing you my very first tutorial! This tutorial highlights how I use Yanfly's Weapon Unleash Plugin (which is a paid plugin), as well as a custom function added through a small plugin, to replace the standard attack skill with a modified attack skill based on which type of weapon the user has equipped. This tutorial will go over a few different aspects and how they combine to create this system;
Archived First Post
ThreeSixNine here,
bringing you my very first tutorial! This tutorial highlights how I use Yanfly's Weapon Unleash Plugin (which is a paid plugin), as well as a custom function added through a small plugin, to replace the standard attack skill with a modified attack skill based on which type of weapon the user has equipped.
This tutorial will go over a few different aspects and how they combine to create this system;
2. I'll go over the plugins used and link a video on how to install them, as this method will not work without them. This section will also cover how to add a custom function through a self-made plugin.
3. I'll introduce and break down the formulas and how they differ by weapon type.
4. I'll get into how and why I think this system suits my current project.
A few things to note before we get started:
-This tutorial only covers the basic attack skill.
-Prior Javascript knowledge is not necessary, but it will definitely help.
-Most importantly, this tutorial is designed to show how to:
- Import a new function into your project in the form a plugin.
- Use the function in a damage formula that does not directly reference defense to reduce incoming damage.
- Use a second plugin to replace the basic attack skill with a custom attack skill, based on the users equipped weapon.
- Use the damage formula to assign a set damage range, consistent across all weapons of a given type.
- Treat the target's base defense like an armor class, checking it against the user's base strength, to see if the user is even physically capable of damaging the enemy with their "basic attack".
Part 1: The Basics
View attachment 134775
Type: sets the damage type of the skill.
Note - HP Damage is the only type used in any formula provided in this tutorial.
Note - Normal Attack will reference any elemental properties of the user's equipped weapon and is the only type used by any formula provided in this tutorial.
Formula: The input field for the damage formula. The code input here will decide the damage or healing output of the skill.
Note - There is no character limit to the input field.
"b.def" references the total defense of the target, where "b." is used to reference the target of the skill and def references the total defense parameter.
This simple equation first multiplies the total attack value of the user by 4, then multiplies the target's defense by 2 and then subtracts the defense from the attack to decide the final damage.
Variance: Variance allows the skill to do a range of damage within a given percentage over or under the calculated value of the formula.
Note: formulas provided in this tutorial have a 0% variance by default method. Any variance is handled in the formula itself.
Critical Hits: Determines if the skill can critical, dealing 300% of normal value. Set to 'Yes' or 'No'.
Note - all formulas in this tutorial are set to 'No'
If you're having any questions at this point, check out Damage Formulas 101 before moving on. The information I found there has been immeasurable in helping me get to where I am now.
Part 2: The Plugins
If you're unfamiliar with installing plugins, check out this Video first. You can also navigate to Yanfly's plugin listing from this page, if you intend to purchase and use the plugin.
Once you're familiar with installing a plugin file, you can start the process of creating your own mini plugin that will add the new Javascript function to your project. I will outline the process before going into detail about each step. The process will have five steps:
- Create a new file in any text editor
- Copy the funtcion into the new file
- Save the file
- Move the file.
- Import the file into your project.
But first, let's take a look at our function's code:
Math.range = function (min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
};
Example; Math.range(1, 10); generates a random number between 1 and 10. This function creates the core of our damage formula and is precisely what gives the weapons a specified damage range, but more on that later.
For the first step, navigate to your desktop, right click an and select 'new' then 'text document'. Locate your new text file on your desktop and open it. It should be a completely blank text file.
Now, copy the code form the 'Math.range' spoiler above, then copy it into you blank text file.
It should look something like this:
Next, click file and choose save as. Save the file as 'MathRange.js'. Don't forget '.js' at the end of the file name. Close the file.
If you watched the linked video for installing plugins, the next two steps should be familiar.
Open your project and navigate to the project folder, under the 'Game' tab:
Open the js folder, then open the plugins folder. Copy the newly saved 'MathRange.js' from the desktop to the plugins folder.
Return to your project and open the plugins manager. Click an empty slot and find MathRange.
-Yanfly's Weapon Unleash Plugin-
-Introduction-
commands or give them the option of having a skill randomly occur when using
them in reference to Golden Sun's Weapon Unleash system!
When replacing the Attack and Guard commands, the text can be changed out
for the command names as well. These replacements aren't limited to just
equipment in origin, but also from actors, classes, enemies, equipment, and
states, too!"
-Understanding Notetags-

RPG Maker MV's editor is unable to allow for custom traits/properties that a game dev may wish to associate with a database object, event, map, etc. Notetags are used to work around such limitations by allowing the game dev to tag certain traits/properties using specific Notetags declared by the related plugin.
any weapon unleash effects. Note: If you're using notetags that write out
the skill's name and you have multiple skills in your database with the same
name, priority will be given to the skill with the highest ID.
Actor, Class, Enemy, Weapon, Armor, State notetags:
--- Replace Attack ---
<Replace Attack: x>
<Replace Attack: name>
This will replace the attack skill used by the battler. If a battler would
have multiple attack replacements, priority will be given in the following
order in a first-come-first-serve aspect:
States - Highest to Lowest Priority
Equipment - In order of equip list
Enemy Aspect
Class Aspect
Actor Aspect
Skill Notetags:
<Command Text: x>
<Attack Text: x>
<Guard Text: x>
If you are using Replace Attack or Replace Guard, you can change the way
the command name appears in the actor command window to x. If you are
using the <Command Text: x> notetag, this will apply to both Attack and
Guard names.
For this tutorial we will be only be focused on only two notetags,
<Replace Attack: x>
and
<Attack Text: x>
<Replace Attack: name>
This will replace the attack skill used by the battler. If a battler would
have multiple attack replacements, priority will be given in the following
order in a first-come-first-serve aspect:
States - Highest to Lowest Priority
Equipment - In order of equip list
Enemy Aspect
Class Aspect
Actor Aspect
If you are using Replace Attack you can change the way
the command name appears in the actor command window to x.
Part 3: The Formulas
a.paramBase(2) >= b.paramBase(3) ? Math.range(a.paramPlus(2), (a.paramPlus(2) + 10)) : Math.range(1, a.paramBase(2));
First, I'll break down down each element of the formula:
'b.paramBase(3)' references the base defense of the target.
'Math.range' generates our random number
'a.paramPlus(2)' references the user's bonus attack value, which is the total attack added from any equipment, NOT including the base value.
Note - By adding attack to an actor through weapons only, we can always reference the attack value of the equipped weapon this way. If your actor has any other gear that adds attack, that will be added to the plus value.
' + 10' adds 10 points to the attack plus value when it's used as the max value for the Math.range function.
1 - Max MP
2 - Attack
3 - Defence
4 - Magic Attack
5 - Magic Defence
6 - Agility
7 - Luck
Next, I explain how those parts come together to create the complete the process:
The ternary operator has 3 parts, or operands:
- A condition followed by a question mark - in this case "a.paramBase(2) >= b.paramBase(3) ?"
- An expression that executes if the condition is true, followed by a colon - "Math.range(a.paramPlus(2), (a.paramPlus(2) + 10)) : "
- An expression that executes if the condition is false - "Math.range(1, a.paramBase(2));
Check if the user's base attack is higher than the target's base defense; if yes, run the first expression, if not, run the second expression.
Note - "Math.range(a.paramPlus(2), (a.paramPlus(2) + 10)) : " is where we get our damage range.
Let's look at an example:
10 >= 10 ? Math.range(20, (20 + 10)) : Math.range(1, 10);
Since 10 is greater than or equal to 10, we know the first condition will run to determine damage. Math.range will generate a random number between 20 and 20 + 10 and deal that damage to the bat.
Now for the slime:
10 >= 30 ? Math.range(20, (20 + 10) : Math.range(1, 10);
Since 10 is not greater than or equal to 30, we know the second expression will determine the damage.
Harold will only do between 1 and 10 damage to the slime.
This formula allows the base defense parameter to function more like an armor class and the base attack parameter to function like a strength stat. Simply, if the target's armor class is higher than the user's strength, the attack will do minimal damage.
Part 4: The Reason
While this only covers the basic attacks of the actors for now, I feel like it's a decent starting point for class-based skills as it sets the ground work for things like using the base values of certain stats as modifiers as well as giving me a better idea of the amount of damage any skill will do to any given enemy at any point in the game.
I've had a few ideas about how to apply this to the more magic-based classes;
Maybe swapping their attack out for a skill that would make sense for a mage, maybe a generic, non elemental spell that is free to cast and could also generate a small amount of mp.
Finally, I want to highlight that this is just one of countless possibiliies when considering damage formulas and plugins. Damage formulas can add a great deal of depth to even the standard battle system. Even without any plugins whatsoever, damage formulas should not be overlooked as one of the more dynamic features.
I do understand that this specific setup is not going to work for everyone, and that's absolutely okay, but I am hoping that maybe this can shed some light on just what kind of things can be achieved by leveraging damage formulas.
Until next time
Downloads / Referenced Files
Log in, then follow the RPG Maker Developers Group to see these download links.
Log in to downloadReferenced Images / Attachments
Creator Claims / Removal
If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.
Replies (0)
No replies yet.
Topic Summary
Loading summary...