RPG Maker Forums

But Adept, they said, surely with your limited knowledge of javascript you could write some code that would allow luck to affect the drop chance of items!

In actuality of course no-one said this, but I needed to make it happen and so I have and thought I would share as I couldn't find anything that already does this for MV. That being said, I would caution anyone against its use. I am not clever enough to write it as a plugin so I have had to go into the actual code for MV and adjust it.

In order make it clear what I've done, we should perhaps first talk about how MV works out item drops. When you create an enemy, you set a drop probability as a fraction. MV cycles through the drops for each enemy and essentially says "if there is an item in this slot I'm checking and this random number I have generated between 0 and 1 multiplied by the denominator of the item drop fraction is less than 1 then add that item to the item drop list":

JavaScript:
        if (di.kind > 0 && Math.random() * di.denominator < this.dropItemRate()) {
            return r.concat(this.itemObject(di.kind, di.dataId));
        } else {
            return r;
        }
A couple of caveats to that explanation; the random number won't ever actually be 1 but can be any decimal less than 1 and that if your party has the double chance of item drop activated then the test is for less than 2.

Aaaanyway, in order to intercept this process I have created a variable (26), which stores a single actor's luck stat. You could do whatever you want with this variable - average party luck, make it your favourite number, etc etc. I could potentially have just grabbed the luck stat directly in the code, but I want to be able to affect it with items and just generally be able to fiddle with it in the game. So my code in the rpg_objects.js is now as below:

JavaScript:
    Game_Enemy.prototype.makeDropItems = function() {

        return this.enemy().dropItems.reduce(function(r, di) {
        var _dropMod = $gameVariables.value(26)/1000;
        var original_dropChance = Math.random() * di.denominator;
        var modified_dropChance = original_dropChance - _dropMod;
        if (di.kind > 0 && modified_dropChance < this.dropItemRate()) {
            return r.concat(this.itemObject(di.kind, di.dataId));
        } else {
            return r;
        }
    }.bind(this), []);
    };
You can see that for now I have just divided the luck stat by 1000. This will work for me as I am breaking the level/stat limits in my game, but the "/1000" could be replaced with any required mathematical operator.

If you are going to use this then in order to assuage my conscience I provide the original script below as a backup. Anyone who is better with js than me please feel free to comment or improve!

JavaScript:
Game_Enemy.prototype.makeDropItems = function() {
    return this.enemy().dropItems.reduce(function(r, di) {
        if (di.kind > 0 && Math.random() * di.denominator < this.dropItemRate()) {
            return r.concat(this.itemObject(di.kind, di.dataId));
        } else {
            return r;
        }
    }.bind(this), []);

Latest Threads

Latest Posts

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,450
Members
137,820
Latest member
georg09byron
Top