Hello,
I am working on a custom combat system for my game, it is supposed to work similar to the game Pokemon Conquest. The issue is characters spawn on top of character to the right when beginning, after a few turns the game suddenly crashes. This is a really complex plugin and a bit messy in terms of code. if someone could point me in the right direction that would be great.
Useful Info:
Variable 27: counter for the index of the current fighters turn
Variable 28: The fighters after being sorted by agility/
Variable 29: The Number of Party Members
Variable 30: Reserved event id used to keep track of fighter locations.
I am using visustella as well as galvs event mover to spawn in an empty event from another map as well as keep track of event spawning in some cases.
The Error:
I am working on a custom combat system for my game, it is supposed to work similar to the game Pokemon Conquest. The issue is characters spawn on top of character to the right when beginning, after a few turns the game suddenly crashes. This is a really complex plugin and a bit messy in terms of code. if someone could point me in the right direction that would be great.
Useful Info:
Variable 27: counter for the index of the current fighters turn
Variable 28: The fighters after being sorted by agility/
Variable 29: The Number of Party Members
Variable 30: Reserved event id used to keep track of fighter locations.
I am using visustella as well as galvs event mover to spawn in an empty event from another map as well as keep track of event spawning in some cases.
The Error:
JavaScript:
//=============================================================================
// RPG Maker MZ - Button Picture
//=============================================================================
/*:
* @target MZ
* @plugindesc Combat Stuff.
* @author Lef
* @command StartBattle
* @text Battle
* @desc Battle.
* @command DoTurn
* @text Process Turn
* @desc Process Turn.
* @command Move
* @text Move
* @desc Move
*
*/
(() => {
'use strict';
const pluginName = "BackdoorCombat";
function get_all_events() {
var events = []
for (let x = 0; x < $dataMap.width; x++) {
for (let y = 0; y < $dataMap.width; y++) {
var new_event = $gameMap.eventIdXy(x, y)
if (new_event != 0) {
events.push(new_event)
}
}
}
return events
};
function Get_All_Party_Members() {
var all_party_members = [];
var events = get_all_events()
for (let i = 0; i < $gameParty.members().length; i++) {
var current_member = $gameParty.members()[i];
all_party_members.push([current_member.param(6),current_member,0,events.length+i]);
};
console.log(all_party_members)
return all_party_members
};
function Get_All_Enemies() {
var events = get_all_events()
var enemies = [];
for (let i = 0; i < events.length; i++) {
var new_event = events[i]
if (new_event.meta != null) {
var enemy = new_event.meta.npc;
if (enemy != null) {
enemies.push([enemy, 1, events.length+i]);
}
};
};
return enemies
};
function Get_All_Battlers () {
var all_enemies = Get_All_Enemies();
var all_battlers = [];
var all_battlers = all_battlers.concat(Get_All_Party_Members(), all_enemies);
return all_battlers
};
function Sort_By_Speed () {
var battlers = Get_All_Battlers();
var speed_data = battlers.sort((first, second) => second[0] - first[0]);
console.log(speed_data);
$gameVariables.setValue(28, speed_data)
};
function GetIds() {
var ids = [];
for (let i = 0; i < $gameParty.members().length; i++) {
ids.push($gameVariables.value(30)[i][3])
};
$gameVariables.setValue(31, ids)
console.log(ids)
console.log($gameVariables.value(31))
};
function Seperate_Party_Members () {
GetIds()
var ids = $gameVariables.value(31);
for (let i = 0; i < ids.length; i++) {
$gameParty.removeActor(i);
var id = ids[i]
var cords = [$gamePlayer.x+(id+1), $gamePlayer.y];
Galv.SPAWN.event(1,'xy',cords,'all',false);
console.log($gameMap._lastSpawnEventId)
$gameMap.event($gameMap._lastSpawnEventId).setImage(Get_Party_member_Image(i), 0);
$gameMap.event($gameMap._lastSpawnEventId).setDirection(8)
};
};
function BeginBattle() {
var original_party = $gameParty.members().map(function(actor) {
return actor.actorId();
})
$gameVariables.setValue(29, $gameParty.members().length);
$gameVariables.setValue(30, Get_All_Party_Members());
console.log('battle');
Sort_By_Speed()
Seperate_Party_Members();
};
function move() {
if ($gameVariables.value(22) > $gameVariables.value(24)) {
if ($gameVariables.value(26)== 1) {
$gameParty._steps = 0;
$gameVariables.setValue(22, $gameParty._steps);
$gameMessage.setBackground(0);
$gameMessage.add('Movement Up');
$gameMap._interpreter.setWaitMode('message');
$gameVariables.setValue(26, 0);
};
};
};
function DoTurn () {
$gameMap._interpreter.wait(60);
console.log($gameVariables.value(29))
var priority_actor = $gameVariables.value(28)[$gameVariables.value(27)];
var id = $gameVariables.value(31)[$gameVariables.value(27)];
if ($gameVariables.value(27) > $gameVariables.value(29)) {
$gameVariables.setValue(27, 2);
};
console.log(id);
// 30 - all party members at start of battle
console.log(priority_actor);
if (priority_actor[2] == 0) {
$gameParty._actors = []
console.log($gameVariables.value(27))
$gameParty.addActor($gameVariables.value(27))
console.log($gamePlayer)
$gameMessage.setChoices(['pass', 'move', 'attack', 'wait'], 0, 0);
$gameMessage.setChoiceBackground(0);
$gameMessage.setChoicePositionType(2);
$gameMessage.setChoiceCallback(n => {
$gameVariables.setValue(26, n)
console.log(id);
$gamePlayer.swap($gameMap.event(id));
});
$gameMap._interpreter.setWaitMode('message');
$gameVariables.setValue(26, 1);
$gameVariables.setValue(27, $gameVariables.value(27)+1)
};
};
function Get_Party_member_Image(id) {
var image = $gameVariables.value(30)[id][1].characterName();
return image
};
PluginManager.registerCommand(pluginName, "Move", function(args) {
console.log('Moving');
move();
});
PluginManager.registerCommand(pluginName, "StartBattle", function(args) {
console.log('battle');
BeginBattle();
});
PluginManager.registerCommand(pluginName, "DoTurn", function(args) {
console.log('Turn');
DoTurn();
});
PluginManager.registerCommand(pluginName, "InitializeMenu", function(args) {
$gameSystem.disableMenu();
});
})();