Вот немного переработал код под скрипты.
AL7.selfSwitches = class {
static getMapEventID(arg, isMapID = true) {
var realARG = AL7.JSONParse(arg);
var typeRealARG = typeof realARG;
if (
typeof arg == "object" &&
(arg.constructor.name === "Game_Interpreter" ||
arg.constructor.name === "Game_Event")
) {
if (isMapID === true) return arg._mapId;
else return arg._eventId;
} else if (typeRealARG === "number") {
return realARG;
} else if (typeRealARG === "string") {
realARG = realARG.toUpperCase();
if (realARG === "PLAYER" || realARG === "P")
if (isMapID === true) return $gameMap.mapId();
else return $gameMap.eventIdXy($gamePlayer.x, $gamePlayer.y);
else if (realARG[0] === "V")
return $gameVariables.value(realARG.match(/\d+/g));
else return realARG.match(/\d+/g);
} else return undefined;
}
static getBool(arg) {
var realARG = AL7.JSONParse(arg);
var typeARG = typeof realARG;
if (typeARG === "boolean") return realARG;
else if (typeARG === "string") {
realARG = realARG.toUpperCase();
if (realARG === "ON") return true;
else if (realARG === "TRUE") return true;
else if (realARG === "OFF") return false;
else if (realARG === "FALSE") return false;
else return undefined;
} else if (typeARG === "number") {
if (realARG > 0) return true;
else return false;
}
return undefined;
}
static SetSelfSwitch(mapID, eventID, ss, enabled, otherDisabled = false) {
var _mapID = this.getMapEventID(mapID);
var _eventID = this.getMapEventID(eventID, false);
var _selfSwitch = AL7.JSONParse(ss).toUpperCase();
var _enabled = this.getBool(enabled);
var _otherDisabled = this.getBool(otherDisabled);
if (
typeof _mapID !== "number" ||
_mapID <= 0 ||
typeof _eventID !== "number" ||
_eventID <= 0 ||
typeof _selfSwitch != "string" ||
typeof _otherDisabled !== "boolean"
)
return;
$gameSelfSwitches.setValue([_mapID, _eventID, _selfSwitch], _enabled);
if (_otherDisabled === true) {
var selfSwitches = ["A", "B", "C", "D"];
selfSwitches.forEach((x) => {
if (x != _selfSwitch)
$gameSelfSwitches.setValue([_mapID, _eventID, x], false);
});
}
}
static SetArraySelfSwitch(
mapID,
eventIDStart,
eventIDStop,
ss,
enabled,
otherDisabled = false
) {
var _eventIDStart = this.getMapEventID(eventIDStart, false);
var _eventIDStop = this.getMapEventID(eventIDStop, false);
if (
_eventIDStart === undefined ||
_eventIDStart <= 0 ||
_eventIDStop === undefined ||
_eventIDStop <= 0
)
return;
if (_eventIDStart <= _eventIDStop)
for (var i = _eventIDStart; i <= _eventIDStop; i++)
this.SetSelfSwitch(mapID, i, ss, enabled, otherDisabled);
else if (_eventIDStart > _eventIDStop)
for (var i = _eventIDStart; i >= _eventIDStop; i--)
this.SetSelfSwitch(mapID, i, ss, enabled, otherDisabled);
}
};
//#region Команды плагинов
if (Utils.RPGMAKER_NAME === "MV") {
AL7.pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
AL7.pluginCommand.call(this, command, args);
if (
command.toUpperCase() === "SETSELFSWITCH" ||
command.toUpperCase() === "SSSWITCH"
) {
if (args.length === 4)
AL7.selfSwitches.SetSelfSwitch(
args[0],
args[1],
args[2],
args[3]
);
else if (args.length > 4)
AL7.selfSwitches.SetSelfSwitch(
args[0],
args[1],
args[2],
args[3],
args[3]
);
} else if (
command.toUpperCase() === "SETARRAYSELFSWITCH" ||
command.toUpperCase() === "SASSWITCH"
) {
if (args.length === 5)
AL7.selfSwitches.SetArraySelfSwitch(
args[0],
args[1],
args[2],
args[3],
args[4]
);
else if (args.length > 5)
AL7.selfSwitches.SetArraySelfSwitch(
args[0],
args[1],
args[2],
args[3],
args[4],
args[5]
);
}
};
} else {
PluginManager.registerCommand("AL7_Core", "setSelfSwitch", (args) => {
var typeGetMap = AL7.JSONParse(args.getMapID).typeIDMap;
var mapID = 0;
if (typeGetMap === "playerMap") mapID = $gameMap.mapId();
else if (typeGetMap === "varValue")
mapID = $gameVariables.value(AL7.JSONParse(args.getMapID).varID);
else if (typeGetMap === "idMap")
mapID = AL7.JSONParse(args.getMapID).mapID;
var typeGetEvent = AL7.JSONParse(args.getEventID).typeIDEvent;
var eventID = 0;
if (typeGetEvent === "playerEvent")
eventID = $gameMap.eventIdXy($gamePlayer.x, $gamePlayer.y);
else if (typeGetEvent === "varValue")
eventID = $gameVariables.value(
AL7.JSONParse(args.getEventID).varID
);
else if (typeGetEvent === "idEvent")
eventID = AL7.JSONParse(args.getEventID).eventID;
AL7.selfSwitches.SetSelfSwitch(
mapID,
eventID,
AL7.JSONParse(args.selfSwitch),
AL7.JSONParse(args.enabled),
AL7.JSONParse(args.disableOtherSelfSwitches)
);
});
PluginManager.registerCommand("AL7_Core", "setArraySelfSwitch", (args) => {
var typeGetMap = AL7.JSONParse(args.getMapID).typeIDMap;
var mapID = 0;
if (typeGetMap === "playerMap") mapID = $gameMap.mapId();
else if (typeGetMap === "varValue")
mapID = $gameVariables.value(AL7.JSONParse(args.getMapID).varID);
else if (typeGetMap === "idMap")
mapID = AL7.JSONParse(args.getMapID).mapID;
var typeGetEvent1 = AL7.JSONParse(args.getEventID1).typeIDEvent;
var eventID1 = 0;
if (typeGetEvent1 === "playerEvent")
eventID1 = $gameMap.eventIdXy($gamePlayer.x, $gamePlayer.y);
else if (typeGetEvent1 === "varValue")
eventID1 = $gameVariables.value(
AL7.JSONParse(args.getEventID1).varID
);
else if (typeGetEvent1 === "idEvent")
eventID1 = AL7.JSONParse(args.getEventID1).eventID;
var typeGetEvent2 = AL7.JSONParse(args.getEventID2).typeIDEvent;
var eventID2 = 0;
if (typeGetEvent2 === "playerEvent")
eventID2 = $gameMap.eventIdXy($gamePlayer.x, $gamePlayer.y);
else if (typeGetEvent2 === "varValue")
eventID2 = $gameVariables.value(
AL7.JSONParse(args.getEventID2).varID
);
else if (typeGetEvent2 === "idEvent")
eventID2 = AL7.JSONParse(args.getEventID2).eventID;
AL7.selfSwitches.SetArraySelfSwitch(
mapID,
eventID1,
eventID2,
AL7.JSONParse(args.selfSwitch),
AL7.JSONParse(args.enabled),
AL7.JSONParse(args.disableOtherSelfSwitches)
);
});
}
По идеи вызов будет так:
AL7.SetSelfSwitch(this, "V1", "A", true)
Конечно не только так. Куча вариантов вызова.
Эти скрипты в я использую в командах плагинах. Так что скрипты сразу учитывают введено скриптами или командами плагинов.
Обновил. Теперь вроде все верно и более надежно.