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), []);