Can anyone help me edit the rpg_core.js file? I really need the function of the "ok" key removed that lets the player essentially fast forward through events because my game is extremely dependant on dialogue and missing or purposefully skipping any of it will ruin the experience. Before anyone asks, yes I've tried the multiple plugins that exist to solve my exact problem, and no none of them worked for whatever reason. I'm honestly at my wits end and I really just need someone who knows what they're doing to help me get rid of this function, or at the very least disable it. It would be much appreciated! (for anyone who decides to help me edit the file, I've included it below for easier access. If I'm not mistaken, the code that enables the fast forward function is just a little below halfway down the file, where it starts talking about how long keys are pressed down for)
I Really Need Help Editing The rpg_core.js File
Javascript/Plugin SupportWhat if you lock text speed down to the slowest setting? I wouldn't know how to edit it to get the results you want, but to make it easier for others, you should include the line # of the code.
I don't know how I would go about doing that, but I'm almost positive the player could still skip through it if they wanted to. Honestly, I know how this is going to be solved (by editing the file above), I just don't know how to do so. I'm also not entirely sure I know which line of code it is, but sure, I can include the number of the line that I suspect it is.
JavaScript:
function changeKeys(findKey, replaceKey){
let keys = Object.keys(Input.keyMapper);
let vals = Object.values(Input.keyMapper);
for(let i in vals){
if(vals[i] == findKey)
Input.keyMapper[keys[i]] = replaceKey
}
}
//example
changeKeys('ok', 'tempOk')
//reenable
changeKeys('tempOk', 'ok')
You can call this to switch the ok button on and off at will. This will change it for any keys that are mapped to 'ok' not just one of the keys.
You can then check for that input by using
Input.isTriggered('tempOk')
to handle how you want those buttons to behave in the meantime.
It all depends on how deeply you want to implement this, or if you're ok just calling it on the fly
Oh wow! Thank you! Can you possibly tell me where I would insert that? 😅
Does it go somewhere in here?
Code:
//-----------------------------------------------------------------------------
/**
* The static class that handles input data from the keyboard and gamepads.
*
* @class Input
*/
function Input() {
throw new Error('This is a static class');
}
/**
* Initializes the input system.
*
* @static
* @method initialize
*/
Input.initialize = function() {
this.clear();
this._wrapNwjsAlert();
this._setupEventHandlers();
};
/**
* The wait time of the key repeat in frames.
*
* @static
* @property keyRepeatWait
* @type Number
*/
Input.keyRepeatWait = 24;
/**
* The interval of the key repeat in frames.
*
* @static
* @property keyRepeatInterval
* @type Number
*/
Input.keyRepeatInterval = 6;
/**
* A hash table to convert from a virtual key code to a mapped key name.
*
* @static
* @property keyMapper
* @type Object
*/
Input.keyMapper = {
9: 'tab', // tab
13: 'ok', // enter
16: 'shift', // shift
17: 'control', // control
18: 'control', // alt
27: 'escape', // escape
32: 'ok', // space
33: 'pageup', // pageup
34: 'pagedown', // pagedown
37: 'left', // left arrow
38: 'up', // up arrow
39: 'right', // right arrow
40: 'down', // down arrow
45: 'escape', // insert
81: 'pageup', // Q
87: 'pagedown', // W
88: 'escape', // X
90: 'ok', // Z
96: 'escape', // numpad 0
98: 'down', // numpad 2
100: 'left', // numpad 4
102: 'right', // numpad 6
104: 'up', // numpad 8
120: 'debug' // F9
};
/**
* A hash table to convert from a gamepad button to a mapped key name.
*
* @static
* @property gamepadMapper
* @type Object
*/
Input.gamepadMapper = {
0: 'ok', // A
1: 'cancel', // B
2: 'shift', // X
3: 'menu', // Y
4: 'pageup', // LB
5: 'pagedown', // RB
12: 'up', // D-pad up
13: 'down', // D-pad down
14: 'left', // D-pad left
15: 'right', // D-pad right
};
/**
* Clears all the input data.
*
* @static
* @method clear
*/
Input.clear = function() {
this._currentState = {};
this._previousState = {};
this._gamepadStates = [];
this._latestButton = null;
this._pressedTime = 0;
this._dir4 = 0;
this._dir8 = 0;
this._preferredAxis = '';
this._date = 0;
};
/**
* Updates the input data.
*
* @static
* @method update
*/
Input.update = function() {
this._pollGamepads();
if (this._currentState[this._latestButton]) {
this._pressedTime++;
} else {
this._latestButton = null;
}
for (var name in this._currentState) {
if (this._currentState[name] && !this._previousState[name]) {
this._latestButton = name;
this._pressedTime = 0;
this._date = Date.now();
}
this._previousState[name] = this._currentState[name];
}
this._updateDirection();
};
/**
* Checks whether a key is currently pressed down.
*
* @static
* @method isPressed
* @param {String} keyName The mapped name of the key
* @return {Boolean} True if the key is pressed
*/
Input.isPressed = function(keyName) {
if (this._isEscapeCompatible(keyName) && this.isPressed('escape')) {
return true;
} else {
return !!this._currentState[keyName];
}
};
/**
* Checks whether a key is just pressed.
*
* @static
* @method isTriggered
* @param {String} keyName The mapped name of the key
* @return {Boolean} True if the key is triggered
*/
Input.isTriggered = function(keyName) {
if (this._isEscapeCompatible(keyName) && this.isTriggered('escape')) {
return true;
} else {
return this._latestButton === keyName && this._pressedTime === 0;
}
};
/**
* Checks whether a key is just pressed or a key repeat occurred.
*
* @static
* @method isRepeated
* @param {String} keyName The mapped name of the key
* @return {Boolean} True if the key is repeated
*/
Input.isRepeated = function(keyName) {
if (this._isEscapeCompatible(keyName) && this.isRepeated('escape')) {
return true;
} else {
return (this._latestButton === keyName &&
(this._pressedTime === 0 ||
(this._pressedTime >= this.keyRepeatWait &&
this._pressedTime % this.keyRepeatInterval === 0)));
}
};
/**
* Checks whether a key is kept depressed.
*
* @static
* @method isLongPressed
* @param {String} keyName The mapped name of the key
* @return {Boolean} True if the key is long-pressed
*/
Input.isLongPressed = function(keyName) {
if (this._isEscapeCompatible(keyName) && this.isLongPressed('escape')) {
return true;
} else {
return (this._latestButton === keyName &&
this._pressedTime >= this.keyRepeatWait);
}
};
/**
* [read-only] The four direction value as a number of the numpad, or 0 for neutral.
*
* @static
* @property dir4
* @type Number
*/
Object.defineProperty(Input, 'dir4', {
get: function() {
return this._dir4;
},
configurable: true
});
/**
* [read-only] The eight direction value as a number of the numpad, or 0 for neutral.
*
* @static
* @property dir8
* @type Number
*/
Object.defineProperty(Input, 'dir8', {
get: function() {
return this._dir8;
},
configurable: true
});
/**
* [read-only] The time of the last input in milliseconds.
*
* @static
* @property date
* @type Number
*/
Object.defineProperty(Input, 'date', {
get: function() {
return this._date;
},
configurable: true
});
/**
* @static
* @method _wrapNwjsAlert
* @private
*/
Input._wrapNwjsAlert = function() {
if (Utils.isNwjs()) {
var _alert = window.alert;
window.alert = function() {
var gui = require('nw.gui');
var win = gui.Window.get();
_alert.apply(this, arguments);
win.focus();
Input.clear();
};
}
};
/**
* @static
* @method _setupEventHandlers
* @private
*/
Input._setupEventHandlers = function() {
document.addEventListener('keydown', this._onKeyDown.bind(this));
document.addEventListener('keyup', this._onKeyUp.bind(this));
window.addEventListener('blur', this._onLostFocus.bind(this));
};
/**
* @static
* @method _onKeyDown
* @param {KeyboardEvent} event
* @private
*/
Input._onKeyDown = function(event) {
if (this._shouldPreventDefault(event.keyCode)) {
event.preventDefault();
}
if (event.keyCode === 144) { // Numlock
this.clear();
}
var buttonName = this.keyMapper[event.keyCode];
if (ResourceHandler.exists() && buttonName === 'ok') {
ResourceHandler.retry();
} else if (buttonName) {
this._currentState[buttonName] = true;
}
};
/**
* @static
* @method _shouldPreventDefault
* @param {Number} keyCode
* @private
*/
Input._shouldPreventDefault = function(keyCode) {
switch (keyCode) {
case 8: // backspace
case 33: // pageup
case 34: // pagedown
case 37: // left arrow
case 38: // up arrow
case 39: // right arrow
case 40: // down arrow
return true;
}
return false;
};
/**
* @static
* @method _onKeyUp
* @param {KeyboardEvent} event
* @private
*/
Input._onKeyUp = function(event) {
var buttonName = this.keyMapper[event.keyCode];
if (buttonName) {
this._currentState[buttonName] = false;
}
if (event.keyCode === 0) { // For QtWebEngine on OS X
this.clear();
}
};
/**
* @static
* @method _onLostFocus
* @private
*/
Input._onLostFocus = function() {
this.clear();
};
/**
* @static
* @method _pollGamepads
* @private
*/
Input._pollGamepads = function() {
if (navigator.getGamepads) {
var gamepads = navigator.getGamepads();
if (gamepads) {
for (var i = 0; i < gamepads.length; i++) {
var gamepad = gamepads[i];
if (gamepad && gamepad.connected) {
this._updateGamepadState(gamepad);
}
}
}
}
};
/**
* @static
* @method _updateGamepadState
* @param {Gamepad} gamepad
* @param {Number} index
* @private
*/
Input._updateGamepadState = function(gamepad) {
var lastState = this._gamepadStates[gamepad.index] || [];
var newState = [];
var buttons = gamepad.buttons;
var axes = gamepad.axes;
var threshold = 0.5;
newState[12] = false;
newState[13] = false;
newState[14] = false;
newState[15] = false;
for (var i = 0; i < buttons.length; i++) {
newState[i] = buttons[i].pressed;
}
if (axes[1] < -threshold) {
newState[12] = true; // up
} else if (axes[1] > threshold) {
newState[13] = true; // down
}
if (axes[0] < -threshold) {
newState[14] = true; // left
} else if (axes[0] > threshold) {
newState[15] = true; // right
}
for (var j = 0; j < newState.length; j++) {
if (newState[j] !== lastState[j]) {
var buttonName = this.gamepadMapper[j];
if (buttonName) {
this._currentState[buttonName] = newState[j];
}
}
}
this._gamepadStates[gamepad.index] = newState;
};
/**
* @static
* @method _updateDirection
* @private
*/
Input._updateDirection = function() {
var x = this._signX();
var y = this._signY();
this._dir8 = this._makeNumpadDirection(x, y);
if (x !== 0 && y !== 0) {
if (this._preferredAxis === 'x') {
y = 0;
} else {
x = 0;
}
} else if (x !== 0) {
this._preferredAxis = 'y';
} else if (y !== 0) {
this._preferredAxis = 'x';
}
this._dir4 = this._makeNumpadDirection(x, y);
};
/**
* @static
* @method _signX
* @private
*/
Input._signX = function() {
var x = 0;
if (this.isPressed('left')) {
x--;
}
if (this.isPressed('right')) {
x++;
}
return x;
};
/**
* @static
* @method _signY
* @private
*/
Input._signY = function() {
var y = 0;
if (this.isPressed('up')) {
y--;
}
if (this.isPressed('down')) {
y++;
}
return y;
};
/**
* @static
* @method _makeNumpadDirection
* @param {Number} x
* @param {Number} y
* @return {Number}
* @private
*/
Input._makeNumpadDirection = function(x, y) {
if (x !== 0 || y !== 0) {
return 5 - y * 3 + x;
}
return 0;
};
/**
* @static
* @method _isEscapeCompatible
* @param {String} keyName
* @return {Boolean}
* @private
*/
Input._isEscapeCompatible = function(keyName) {
return keyName === 'cancel' || keyName === 'menu';
};
Oh wait, doesn't that mean that the player won't be able to press okay to advance the text? I still need them to be able to use the okay button, I just want to remove the function that happens on a long press.
Line # is shown on the left side like so, you can't miss it. (Just so you know for future reference)
I don't use Windows 😅
Just do the following in a plugin that loads at the bottom of your order.
Save this in a js file
This actually stops the player from being able to speed through your text at all.
I don't think you directly said it, bc you said events, but you were pretty much referring to dialogue, right?
Save this in a js file
JavaScript:
let alias_Window_Message_updateShowFast = Window_Message.prototype.updateShowFast;
Window_Message.prototype.updateShowFast = function(){
alias_Window_Message_updateShowFast.call(this);
this._showFast = false;
}
This actually stops the player from being able to speed through your text at all.
I don't think you directly said it, bc you said events, but you were pretty much referring to dialogue, right?
I mean, honestly at this point I'm so frustrated with plugins not working and my own dumb brain being stupid that I'd be jumping for joy if only dialogue fast forwarding got disabled, but no, I was referring to all fast forwarding (including movement route fast forwarding). By the way, the code you gave me didn't work :/ I'm sure it's probably something I'm doing wrong, though. I just don't know what it could possibly be.
fix the typo where it calls alias_Window_Message_updateShowFas
add the t there
add the t there
The alias_Window function I sent you, I actually missed a 't' in the last reference. My bad, I went back and edited it.
About fast forwarding through events though...what do you mean? What other than dialogue are you fast forwarding through?
About fast forwarding through events though...what do you mean? What other than dialogue are you fast forwarding through?
maybe this for event fast forwarding?
JavaScript:
Scene_Map.prototype.isFastForward = function() {
return false;
};
@Ritter we just parented a mini plugin. What do you want to name it? No D names, and nothing that has an apostrophe.
I want to completely erase the fast forward function. If I ever see it again, it'll be too soon. Also, it seems like this code just turns the okay key completely off, but I still need the okay key to function as a means for the player forward the text (or am I just misinterpreting what you wrote?)
Also, I'm not entirely sure how I would go about using what you gave me as a script command. Where do I insert the 'ok' and where do I insert the 'tempok'
Thank you for putting up with me, by the way. I'm very bad with code and you're being extremely helpful.
Oh! Wait, is that the whole plugin, or does it need to be added to standardplayer's code?
Lol it's ok, and please don't feel like you're gonna give up. There's almost always a way, and something like this isn't the thing that's gonna beat you.
the changeKey function replaces the command 'ok' with whatever you put as the second argument.
So if you change 'ok' to 'tOk', you can check for that as input in a conditional branch's script box.
Input.isTriggered('tOk')
However, if you take the corrected alias I gave you (as my second answer) and @Ritter's answer (I haven't tested it, but I'm sure they did), and put both of those in a file, save it as a .js file to your plugins folder, and then add it to your plugin manager, all the way at the bottom, that might be your answer. Try it and let us know.
Although, I would actually write @Ritter 's answer as an alias, just to be safe and give it a better chance of playing nice with other people's code that might change this stuff.
the changeKey function replaces the command 'ok' with whatever you put as the second argument.
So if you change 'ok' to 'tOk', you can check for that as input in a conditional branch's script box.
Input.isTriggered('tOk')
However, if you take the corrected alias I gave you (as my second answer) and @Ritter's answer (I haven't tested it, but I'm sure they did), and put both of those in a file, save it as a .js file to your plugins folder, and then add it to your plugin manager, all the way at the bottom, that might be your answer. Try it and let us know.
Although, I would actually write @Ritter 's answer as an alias, just to be safe and give it a better chance of playing nice with other people's code that might change this stuff.
JavaScript:
let aliasSceneMap_isFastForward = Scene_Map.prototype.isFastForward;
Scene_Map.prototype.isFastForward = function() {
aliasSceneMap_isFastForward.call(this);
return false;
};
Do I have this in here the right way? I tried it in the editor and it didn't work, then I tried deploying it and it didn't work, then I turned off all of my other plugins and it didn't work :/ The only thing that I can think of is that I'm just not putting it into the js file correctly.
You would use both, i'll attach a plugin you can add that contains both functions. This contains both functions with mine properly aliased, i tested and it seems to work on both text and events. don't forget to add it to your plugin manager :mrsatan:
Edit: Sorry it has a D word lmao
Edit: Sorry it has a D word lmao
Have you saved it as a .js file? And you definitely put it in the plugins file, AND enabled it in the plugin manager, all the way at the bottom?
Holy ... I'm gonna cry...
IT WORKED
(I put it at the top on a whim)
THANK YOU SO MUCH! I'm a nitpicker when it comes to tiny details, so this means so much to me!
I can die now. thank you for releasing me from this mortal coil.
IT WORKED
(I put it at the top on a whim)
THANK YOU SO MUCH! I'm a nitpicker when it comes to tiny details, so this means so much to me!
I can die now. thank you for releasing me from this mortal coil.
Original thread: https://forums.rpgmakerweb.com/threads/i-really-need-help-editing-the-rpg_core-js-file.122984/