【質問】イベントを追いかけるイベント【解決】
Posted: 2019年11月05日(火) 03:09
特定のイベントが特定の範囲内に入ると追いかける、というよりスイッチが入るイベントを作る方法を探しています
プラグイン、コモンイベント、何でもいいので教えてくださるとありがたいです
プラグイン、コモンイベント、何でもいいので教えてくださるとありがたいです
▼SC Get Distance(さくらくらうど様作)かになべ さんが書きました:特定のイベントが特定の範囲内に入ると追いかける、というよりスイッチが入るイベントを作る方法を探しています
プラグイン、コモンイベント、何でもいいので教えてくださるとありがたいです
イベント範囲が拡大するタイプのプラグインは結構ありますが、その中でマンカインド様のプラグインを利用してみては?かになべ さんが書きました:丁寧な返信ありがとうございます!
早速導入しようと思ったのですが、この仕様では壁の向こうに居ても感知されてしまいます
どうにか壁から先は範囲に入れないように出来ないでしょうか...?
あれこれと考えてはみたのですがどうにも再現は出来ず、八方塞がりです
いい案があれば教えてくださるとありがたいです
実現したい要件が曖昧で、提案しかねます。かになべ さんが書きました:虚構の城跡様 返信ありがとうございます
自分もツクマテで質問する前にそのプラグインは見つけていて、最初はコイツが使えるか、と思ってました
しかし、これの場合視界内に入ったプレイヤーには反応しますが、イベントには反応せずあえなく断念した次第です
お手間を取らせてしまい申し訳ありません・・・!
コード: 全て選択
(function(_global) {
// マップID、侵入時にオンするスイッチ番号、主体イベントID、対象イベントID
var mapId = 2, switchNumber = 7, subjectEventId = 16, targetEventId = 20;//★
// 主体イベントの視界
var checkRange = 5;
// 追跡可能歩数(これ以上離れている場合は、壁で隔たれていると判断してスイッチを入れない)
var traceRange = 10;
// その他
var astar = _global.astar,
Graph = _global.Graph,
graph,
checkWaitCount = 60;
// 対象イベントを赤くする処理
var BlendRed = {
reslis: [],
addRed: function(res) {
this.reslis[this.reslis.length] = SceneManager._scene._spriteset._characterSprites[res - 1];
if (this.reslis[this.reslis.length - 1]) {
this.reslis[this.reslis.length - 1].setBlendColor([255, 0, 0, 200]);
}
},
eraseRed: function() {
this.reslis.forEach(function(res) { res._blendColor = []; });
this.reslis = [];
},
alert: function(ev) {
ev.requestBalloon(1);
AudioManager.playSe({"name":"Shot2","volume":90,"pitch":100,"pan":0});
}
};
//============================================================
// AStar関係の処理
//============================================================
Object.defineProperty(Scene_Map.prototype, "createGraph", {
value: function() {
var g = [];
for (var x=0, len2=$gameMap.width(); x<len2; x++) {
g[g.length] = [];
for (var y=0, len=$gameMap.height(); y<len; y++) {
g[x][y] = $gameMap.isPassable(x, y) ? 1 : 0;
}
}
graph = new Graph(g);
}
});
var _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
_Scene_Map_start.call(this);
if (!graph) {
this.createGraph();
}
};
Object.defineProperty(Game_Event.prototype, "traceTarget", {
value: function(res) {
var start = graph.grid[this.x][this.y];
var end = graph.grid[$gameMap.event(res).x][$gameMap.event(res).y];
var options = {};
return astar.search(graph, start, end, options);
}
});
//============================================================
// 主体イベント
//============================================================
var _Game_Event_initialize = Game_Event.prototype.initialize;
Game_Event.prototype.initialize = function(mapId, eventId) {
this._checkCountX = 0;
this._checkCountY = 0;
this._checkWaitCount = checkWaitCount;
_Game_Event_initialize.apply(this, arguments);
};
Game_Event.prototype.checkOtherEvent = function() {
var id = 0, direction = this._direction, dx = 1, dy = 1;
if (direction === 4) { dx *= -1; }
if (direction === 8) { dy *= -1; }
for (var i = 0, l = checkRange ** 2; i < l; i++) {
var n = this._checkCountY % checkRange;
if (n === checkRange - 1) { this._checkCountX++; }
if (direction === 2 || direction === 8) {
var x = this.x + this._checkCountX % checkRange - Math.floor(checkRange / 2);
var y = this.y + n * dy + 1 * dy;
} else {
var x = this.x + this._checkCountX % checkRange * dx + 1 * dx;
var y = this.y + this._checkCountY % checkRange - Math.floor(checkRange / 2);
}
id = $gameMap.eventIdXy(x, y);
if (targetEventId) {
if (id === targetEventId) { break; }
} else {
if (id) { break; }
}
this._checkCountY++;
}
return id;
};
var _Game_Event_update = Game_Event.prototype.update;
Game_Event.prototype.update = function() {
if (this._eventId === subjectEventId && this._mapId === mapId) {
if (this._checkWaitCount <= 0) {
this._checkWaitCount = 0;
BlendRed.eraseRed();
} else {
this._checkWaitCount--;
}
var res = this.checkOtherEvent();
if (res) {
if (targetEventId && res !== targetEventId) { return; }
var route = this.traceTarget(res);
if (route.length !== 0 && route.length <= traceRange) {
//console.log(route);
if (this._checkWaitCount === 0) {
$gameSwitches.setValue(switchNumber, true);
//console.log("in " + res);
console.log($gameSwitches.value(switchNumber));
BlendRed.alert(this);
BlendRed.addRed(res);
BlendRed.eraseRed();
if (this._checkWaitCount === 0) { this._checkWaitCount = checkWaitCount; }
}
}
} else {
if ($gameSwitches.value(switchNumber)) {
$gameSwitches.setValue(switchNumber, false);
//console.log("out");
console.log($gameSwitches.value(switchNumber));
}
}
}
_Game_Event_update.call(this);
};
})(this);
コード: 全て選択
var mapId = 2, switchNumber = 7, subjectEventId = 16, targetEventId;//★