Luck Affecting Drop Rate

AdeptusUK

Veteran
Veteran
Joined
May 27, 2020
Messages
63
Reaction score
15
First Language
English
Primarily Uses
RMMV
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), []);
 

Rugman

Veteran
Veteran
Joined
Jun 11, 2020
Messages
146
Reaction score
37
First Language
English
Primarily Uses
RMMV
It’s surprising that something like this doesn’t already exist. Hopefully a plugin writer will see this and make it into a plugin. I fear that most people have shifted their focus to mz now though.
 

AdeptusUK

Veteran
Veteran
Joined
May 27, 2020
Messages
63
Reaction score
15
First Language
English
Primarily Uses
RMMV
I was surprised too, I spent longer searching for a superior, pre-made version than writing code!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Frostorm wrote on Featherbrain's profile.
Hey, so what species are your raptors? Any of these?
... so here's my main characters running around inside "Headspace", a place people use as a safe place away from anxious/panic related thinking.
Stream will be live shortly! I will be doing some music tonight! Feel free to drop by!
Made transition effects for going inside or outside using zoom, pixi filter, and a shutter effect
I have gathered enough feedback from a few selected people. But it is still available if you want to sign up https://forums.rpgmakerweb.com/index.php?threads/looking-for-testers-a-closed-tech-demo.130774/

Forum statistics

Threads
105,992
Messages
1,018,197
Members
137,773
Latest member
Kirakirna
Top