Project1
标题: 请教写事件时,如何实现指定队列人物随机学习到技能? [打印本页]
作者: 负零 时间: 2016-3-10 19:44
标题: 请教写事件时,如何实现指定队列人物随机学习到技能?
实话,标题还是被吃了好,不知道怎么表达。下边才是详细的:
请教写事件时,如何实现指定队列人物随机学习到指定范围内的技能?
举个栗子:
事件设置中设置选择分支:
#1重置1号位 #排在队列中一号位(不一定是数据库ID为1)的队员,
更改队伍成员:移除 二狗
更改队伍成员:添加 二狗(初始化) #实现了二狗的初始化
增减技能 二狗,+狂吼 #这个是重点要解决的问题,如何学习到指定范围内的技能,例如某个范围(1到15这些技能中任学两个、三个、或四个,如此。)
#2重置2号位
#3重置3号位
#4重置4号位
#5...
#6...
作者: 小叮鈴 时间: 2016-3-10 20:37
假如要學十個隨機技能
變量1~10
變量等於1時學A
=2 學B
如此類推
作者: andrewx 时间: 2016-3-10 21:14
本帖最后由 andrewx 于 2016-3-10 21:56 编辑
事件里执行脚本:
var actorId = 1, lowerBound = 1, upperBound = 15, learnNum = 4;
//修改以上参数,分别是角色ID,最小技能ID,最大技能ID,学习个数
var actor = $gameActors.actor(actorId);
var unlearned = 0; for (var i = lowerBound; i <= upperBound; i++) {if (!actor.isLearnedSkill(i)) {unlearned++;}}
if (unlearned <= learnNum) {for (var i = lowerBound; i <= upperBound; i++) {actor.learnSkill(i);}} else {for (var i = 0; i < learnNum; i++) {while (true) {var skillId = Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);if (!actor.isLearnedSkill(skillId)) {actor.learnSkill(skillId);break;}}}}
var actorId = 1, lowerBound = 1, upperBound = 15, learnNum = 4;
//修改以上参数,分别是角色ID,最小技能ID,最大技能ID,学习个数
var actor = $gameActors.actor(actorId);
var unlearned = 0; for (var i = lowerBound; i <= upperBound; i++) {if (!actor.isLearnedSkill(i)) {unlearned++;}}
if (unlearned <= learnNum) {for (var i = lowerBound; i <= upperBound; i++) {actor.learnSkill(i);}} else {for (var i = 0; i < learnNum; i++) {while (true) {var skillId = Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);if (!actor.isLearnedSkill(skillId)) {actor.learnSkill(skillId);break;}}}}
或者:
var memberIndex = 0, lowerBound = 1, upperBound = 15, learnNum = 4;
//修改以上参数,分别是队列index,最小技能ID,最大技能ID,学习个数
var actor = $gameParty.members()[memberIndex];
var unlearned = 0; for (var i = lowerBound; i <= upperBound; i++) {if (!actor.isLearnedSkill(i)) {unlearned++;}}
if (unlearned <= learnNum) {for (var i = lowerBound; i <= upperBound; i++) {actor.learnSkill(i);}} else {for (var i = 0; i < learnNum; i++) {while (true) {var skillId = Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);if (!actor.isLearnedSkill(skillId)) {actor.learnSkill(skillId);break;}}}}
var memberIndex = 0, lowerBound = 1, upperBound = 15, learnNum = 4;
//修改以上参数,分别是队列index,最小技能ID,最大技能ID,学习个数
var actor = $gameParty.members()[memberIndex];
var unlearned = 0; for (var i = lowerBound; i <= upperBound; i++) {if (!actor.isLearnedSkill(i)) {unlearned++;}}
if (unlearned <= learnNum) {for (var i = lowerBound; i <= upperBound; i++) {actor.learnSkill(i);}} else {for (var i = 0; i < learnNum; i++) {while (true) {var skillId = Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);if (!actor.isLearnedSkill(skillId)) {actor.learnSkill(skillId);break;}}}}
第二种是按队列位置,注意index从0开始,即第一个队员index=0
未详细测试,如果指定范围内未学技能数量小于等于学习个数,则强制学习未学的全部技能。其他情况随机在未习得技能里学习指定个数技能,不过这随机的效率很差。
扔完就跑,你问我为啥不换行?谁让编辑器只能写12行呢wwwww
作者: seedj13 时间: 2016-3-10 22:11
大概写了一下,细节上还不完善,你试试看,我是建立一个事件,然后选择肢选择队员,把队员编号放进20号变量,然后再调用公共事件,事件代码在下面,为了方便查看,每句都写的很短
- var actorid=parseInt($gameVariables.value(20))//把20号变量放入自定义变量actorid,这是为了方便楼主阅读
- var skillnum=Math.floor(Math.random()*3)+2;//随机人物可获得2-4个技能
- var skillid;//自定义变量,下面要用
- for(var x=1;x<=skillnum;x++){
- skillid=Math.floor(Math.random()*10)+11;
- $gameActors.actor(actorid).learnSkill(skillid);//循环一次增加一个技能,因为有可能重复,所以实际人物可能得到的技能数量是1-4个,这个你自己完善一下
- };
复制代码
作者: 汪汪 时间: 2016-3-10 22:29
andrewx 发表于 2016-3-10 21:14
事件里执行脚本:
var actorId = 1, lowerBound = 1, upperBound = 15, learnNum = 4;
- //事件里执行脚本的增强,应该可以用吧 ,保存成插件用就好.....
- Game_Interpreter.prototype.command355 = function() {
- var script = this.currentCommand().parameters[0] + '\n';
- while (this.nextEventCode() === 655 || this.nextEventCode() === 355) {
- this._index++;
- script += this.currentCommand().parameters[0] + '\n';
- }
- eval(script);
- return true;
- };
复制代码
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |