Here is some sample code for an RPG Maker MV plugin that allows text input interaction with events:
// Plugin code
const InputReplyPlugin = {};
InputReplyPlugin.loadReplies = function() {
// Load replies.txt into array
let replies = [];
// Read file and split into lines
const file = /* file loading code */;
const lines = file.split('\n');
// Loop lines and push to replies array
lines.forEach(line => {
if(line) replies.push(line);
});
return replies;
}
InputReplyPlugin.checkForReply = function(input) {
// Get loaded replies
const replies = this.loadReplies();
// Loop replies and return match if found
for(let reply of replies) {
if(reply.includes(input)) {
return reply;
}
}
// No match found
return "Sorry, I don't have a reply for that.";
}
// Add plugin command
PluginManager.registerCommand(
InputReplyPlugin,
"InputReply",
args => {
// Show input box
const input = Window_Message.prototype.inputBox();
// Get reply from input
const reply = InputReplyPlugin.checkForReply(input);
// Show reply
Window_Message.prototype.clear();
Window_Message.prototype.push(reply);
}
);
// Next half
// Event page settings
Database.eventPageSetup = function(page) {
// Add input reply command to self switch
page.list.push({
code: $gameVariables.value(1) === 1 ? 'InputReply' : '',
indent: 0
});
}
// Trigger input on interaction
Scene_Map.prototype.checkEventTriggerThere = function(x, y) {
// Normal trigger
this.checkEventTriggerHere(x, y);
// Input trigger
if ($gameVariables.value(1) === 1) {
this.runEventCommand('InputReply');
}
};
So in summary, it loads replies from a text file, checks input against replies, displays the matching reply if found. The event page and interaction is set up to trigger the input command. Let me know if any part needs more explanation!