From 9f6c8b1026ff2ebda2afbc5754fb1f7ad17270cd Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Thu, 17 Mar 2022 08:05:32 -0500 Subject: [PATCH] Start working on combo keybind support --- scripts/server/keybind.js | 46 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/scripts/server/keybind.js b/scripts/server/keybind.js index d392bd68..e7d33dd6 100644 --- a/scripts/server/keybind.js +++ b/scripts/server/keybind.js @@ -19,19 +19,16 @@ function initKeyBindScript() { function addKeyBindCommand(command, params, client) { let splitParams = params.split(" "); - let keyId = getKeyIdFromParams(getParam(params, " ", 1)); + let keys = getKeysInComboName(getParam(params, " ", 1)); let tempCommand = getParam(params, " ", 2); let tempParams = (splitParams.length > 2) ? splitParams.slice(2).join(" ") : ""; - if(!keyId) { - messagePlayerError(client, "The key ID or name you input is invalid!"); - messagePlayerTip(client, "Use simple key names, letters, or numbers. Don't add spaces."); + if(keys.indexOf(false) != -1) { + messagePlayerError(client, "One of the key names you input is invalid!"); + messagePlayerTip(client, "Use simple key names, letters, or numbers. Don't add spaces. Must be lowercase."); + messagePlayerTip(client, "No actual symbols, use a name for those if needed like ampersand, hashtag, tilde, etc"); messagePlayerInfo(client, `Examples: {ALTCOLOUR}1, 2, a, b, numplus, num1, f1, f2, pageup, delete, insert, rightshift, leftctrl`); - return false; - } - - if(!keyId) { - messagePlayerError(client, "That key name/id is invalid!"); + messagePlayerInfo(client, `For combos, use a plus sign between the keys. No spaces! Example: {ALTCOLOUR}rightctrl+num3{MAINCOLOUR}`); return false; } @@ -41,14 +38,12 @@ function addKeyBindCommand(command, params, client) { } addPlayerKeyBind(client, keyId, tempCommand, tempParams); - messagePlayerSuccess(client, `You binded the {ALTCOLOUR}${toUpperCase(getKeyNameFromId(keyId))} {MAINCOLOUR}key to command: {ALTCOLOUR}/${tempCommand} ${tempParams}`); + messagePlayerSuccess(client, `You binded the {ALTCOLOUR}${toUpperCase(keys.join(" + "))} {MAINCOLOUR}keys to command: {ALTCOLOUR}/${tempCommand} ${tempParams}`); } // =========================================================================== function removeKeyBindCommand(command, params, client) { - let splitParams = params.split(" "); - let keyId = getKeyIdFromParams(getParam(params, " ", 1)); if(!keyId) { @@ -75,6 +70,8 @@ function addPlayerKeyBind(client, keys, command, params, tempKey = false) { keyBindData.databaseId = -1; } + keyBindData.needsSaved = true; + getPlayerData(client).keyBinds.push(keyBindData); sendAddAccountKeyBindToClient(client, keys, (keys.length > 1) ? VRR_KEYSTATE_COMBO : VRR_KEYSTATE_UP); @@ -217,4 +214,29 @@ function showKeyBindListCommand(command, params, client) { } } +// =========================================================================== + +function getKeyNamesInComboName(comboName) { + if(comboName.indexOf("+") != -1) { + return comboName.split("+"); + } else { + return [comboName]; + } +} + +// =========================================================================== + +function getKeysInComboName(comboName) { + let keyNames = getKeyNamesInComboName(comboName); + let keys = []; + for(let i in keyNames) { + if(getKeyIdFromParams(keyNames[i])) { + keys.push(getKeyIdFromParams(keyNames[i])); + } else { + keys.push(false); + } + } + return keys +} + // =========================================================================== \ No newline at end of file