MV makedropitems

So i'm using this enemy level script here by ぶちょー
Now my problem is when there is no additional item drop on enemy level up i get error.. reduce of undefined.. however when i do define an additional item when level up, the plugin works correct and smoothly!
1637908984948.png

original code from Game_Troop.makeDropItems
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), []);

KZR_EnemyLevel.js code
JavaScript:
var _kzr_enemy_level_Game_Enemy_makeDropItems = Game_Enemy.prototype.makeDropItems;
Game_Enemy.prototype.makeDropItems = function() {
    var result = _kzr_enemy_level_Game_Enemy_makeDropItems.call(this);
    //if (this._dropItems.length !== 0) {
    return result.concat(this._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), []));//}
};

also i have another problem, the plugin help states that i can use v[x] for eval on the "level" parameter, but when i put level:v[10], for gameVariable ID 10.. it becomes undifined or NaN in game.

JavaScript:
Game_Enemy.prototype.ELgetValue = function(formula) {
    formula = formula.replace(/level/g, 'this._level');
    formula = formula.replace(/v\[(\d+)\]/gi, function() {
        return $gameVariables.value(parseInt(arguments[1]));
    }.bind(this));
    formula = formula.replace(/random\((-)?(\d+),(-)?(\d+)\)/gi, function() {
        var min = parseInt(arguments[2]);
        if (arguments[1]) min *= -1;
        var max = parseInt(arguments[4]);
        if (arguments[3]) max *= -1;
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }.bind(this));
    return eval(formula);
};
"of undefined" always means that the engine tries to access data that doesn't exist, and given your description it is most likely that one array is one element too short.

does this error happen when you start a new game, when you load a saved game or in both cases?

as for the second question - can you give a screenshot of how exactly and where you place the code?
this is the enemy notetag in the database as per example in the plugin
1637928320627.png


if i put the v[10], then the level is not reflected in game.
the the drop:I5,1,level>=3 is from the example in the help section
Item type === item ID 5, drop rate 1/1, when level is 3 or more.
when i dont set a drop, i get the error.. it's like im forced to enter a drop entry..
but on the level tag.. when i just put "level:10" in game is correct.. but when i use "level:v[10]" to assign the level value to be that of gamevar ID 10, the value becomes 0 in game.
you didn't answer my first question, which was the more important one.

and where and when do you set the variable 10? can you give a screenshot of that as well (full event please, nothing cropped)?
@Andar i start new game every time i playtest.
this is the help text
JavaScript:
@help
 * 敵キャラにレベルを実装します。
 * 能力は設定した職業に依存します。
 *
 * 【エネミーの設定】
 * 以下、メモ欄に記述します。
 * <EnemyLevel>
 * 各パラメータの設定
 * </EnemyLevel>
 * パラメータの設定には、変数とランダム数を用いることができます。
 * 変数 : v[id]
 * ランダム数 : random(min, max) : min から max までの数値
 * ・レベル
 *    level:レベル   (例)v[1] + random(1,2) : 変数[1] + 1~2
 * ・職業
 *    class:職業ID    :能力値、スキル等、職業依存になります。
 * ・経験値
 *    exp:経験値     (例)10 + level * 5
 * ・所持金
 *    gold:所持金    (例)5 + level * 3
 * ・武器
 *    weapon:ID,ID,.. :いくつでも設定できます。数値のみ対応。 NG:v[10]
 * ・防具
 *    armor:ID,ID,..  :いくつでも設定できます。数値のみ対応。
 * ・ドロップアイテム(複数設定可)
 *    drop:識別子+ID,確率,条件     識別子:アイテム I , 武器 W , 防具 A
 *    (例)I5,3,level>=3
 *                  レベルが3以上のとき、アイテムID5を3分の1の確率でドロップ。
 *    (例)W5,50,v[10]>=5
 *                  変数[10]が5以上のとき、武器ID5を50分の1の確率でドロップ。
 * ※ データベースで設定したもの+メモ欄で設定したものをドロップします。
 *
 * 【例】
 * <EnemyLevel>
 * level:v[1] + random(-1,1)
 * class:13
 * exp:10 + level * 5
 * gold:5 + level * 3
 * weapon:1,1
 * armor:1,2,3,4
 * drop:I5,3,level>=3
 * drop:W5,50,v[10]>=5
 * </EnemyLevel>
 *
 * 【行動パターン】
 *  レベルにより習得しているスキルが変わります。
 *  行動パターンに設定したスキルを習得していない場合、そのスキルは使用しません。

i just inserted those codes in the enemy note tags, level:v[x] dont work, while the drop:XX,X,X is required, else error if you dont state anything.

EDIT:
i found that adding the tag drop:I0,0,0, avoids the error.. but still, the script won't work if the "drop:XX,X,X" is left blank..
I didn't ask for the help text, I asked to see the event where you assign a value to the variable 10 by using the control variable command.
because all variables start with value 0, and getting a 0 from level: v[10] is the correct behaviour if somehow the event where you set the variable to a different value fails to run.
I didn't ask for the help text, I asked to see the event where you assign a value to the variable 10 by using the control variable command.
because all variables start with value 0, and getting a 0 from level: v[10] is the correct behaviour if somehow the event where you set the variable to a different value fails to run.

Here's the event. I use it before the SRPG starts.

1637967080828.png


1637967190477.png



@Andar thank you very much! you are correct, i had other places where i called the common event, so this caused the event that assign the value to 0.

Original thread: https://forums.rpgmakerweb.com/threads/makedropitems.142471/