//The list above is supposed to be like [11,11,11,12]
//So for the god's sake the value of w cannot be too large
}
}
var randomValue = randomList[Math.floor(Math.random() * randomList.length)];
return randomValue;
};
function weightRandom(randomConfig){
//var randomConfig = [{id:11,w:3},{id:12,w:1}];
//SpawnEventID, Weight
var randomList = [];
for(var i in randomConfig){
for(var j = 0; j < randomConfig[i].w; j++){
randomList.push(randomConfig[i].id);
//The list above is supposed to be like [11,11,11,12]
//So for the god's sake the value of w cannot be too large
}
}
var randomValue = randomList[Math.floor(Math.random() * randomList.length)];
return randomValue;
};
脚本代码函数引用:
var Gid=weightRandom([{id:34,w:2},{id:38,w:1}]);//基础药水
var x=$gameMap._events[this._eventId]._x;
var y=$gameMap._events[this._eventId]._y;
Galv.SPAWN.event(Gid,x,y);