I decided to make a new post because I generated a new code that works.... Kind of....
The issue with this code is that the sprint doesn't stop and go back to walking when the character stops moving and the character keeps getting faster and faster until they're sonic. Is there anything I'm missing; I'm not that code savvy like all of y'all. Tell me what snippets I need to add because I don't know what to add to resolve this issue hahah.
JavaScript:
/*:
* @plugindesc -
* @author -
*
* @param KeyPressTime
* @desc The time in ms to register a double press. Default: 250
* @default 250
*
* @param SprintSpeed
* @desc The speed increase when sprinting. Default: 1
* @default 1
*
* @help
*/
var Imported = Imported || {};
Imported.DoublePressSprint = true;
var DoublePressSprint = DoublePressSprint || {};
DoublePressSprint.keyPressTime = Number(PluginManager.parameters('DoublePressSprint')['KeyPressTime'] || 250);
DoublePressSprint.sprintSpeed = Number(PluginManager.parameters('DoublePressSprint')['SprintSpeed'] || 1);
// Override the default moveByInput function
DoublePressSprint.moveByInput = Game_Player.prototype.moveByInput;
Game_Player.prototype.moveByInput = function() {
if (Input.isTriggered('up') && DoublePressSprint.checkDoublePress('up')) {
this.setMoveSpeed(this._moveSpeed + DoublePressSprint.sprintSpeed);
} else if (Input.isTriggered('left') && DoublePressSprint.checkDoublePress('left')) {
this.setMoveSpeed(this._moveSpeed + DoublePressSprint.sprintSpeed);
} else if (Input.isTriggered('down') && DoublePressSprint.checkDoublePress('down')) {
this.setMoveSpeed(this._moveSpeed + DoublePressSprint.sprintSpeed);
} else if (Input.isTriggered('right') && DoublePressSprint.checkDoublePress('right')) {
this.setMoveSpeed(this._moveSpeed + DoublePressSprint.sprintSpeed);
} else {
// call the original moveByInput function
DoublePressSprint.moveByInput.call(this);
}
};
// check if the specified key has been pressed twice within the specified time
DoublePressSprint.checkDoublePress = function(key) {
var currentTime = new Date().getTime();
if (DoublePressSprint.lastKeyPressTime[key] === undefined) {
DoublePressSprint.lastKeyPressTime[key] = currentTime;
return false;
} else if (currentTime - DoublePressSprint.lastKeyPressTime[key] < DoublePressSprint.keyPressTime) {
DoublePressSprint.lastKeyPressTime[key] = undefined;
return true;
} else {
DoublePressSprint.lastKeyPressTime[key] = currentTime;
return false;
}
};
DoublePressSprint.lastKeyPressTime = {};
The issue with this code is that the sprint doesn't stop and go back to walking when the character stops moving and the character keeps getting faster and faster until they're sonic. Is there anything I'm missing; I'm not that code savvy like all of y'all. Tell me what snippets I need to add because I don't know what to add to resolve this issue hahah.