Add keybind.js for keybind handling and funcs

This commit is contained in:
Vortrex
2020-12-16 07:57:31 -06:00
parent 5a7a7b6954
commit 8ce2c43de9

75
scripts/server/keybind.js Normal file
View File

@@ -0,0 +1,75 @@
// ===========================================================================
// Asshat-Gaming Roleplay
// https://github.com/VortrexFTW/gtac_asshat_rp
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
// ---------------------------------------------------------------------------
// FILE: keybind.js
// DESC: Provides keybind handlers and functions
// TYPE: Server (JavaScript)
// ===========================================================================
function initKeyBindScript() {
console.log("[Asshat.KeyBind]: Initializing key bind script ...");
console.log("[Asshat.KeyBind]: Key bind script initialized!");
}
// ---------------------------------------------------------------------------
function doesPlayerHaveKeyBindForCommand(client, command) {
let accountKeyBinds = getClientData(client).accountData.keyBinds;
for(let i in accountKeyBinds) {
if(accountKeyBinds[i].command == command) {
return true;
}
}
return false;
}
// ---------------------------------------------------------------------------
function getPlayerKeyBindForCommand(client, command) {
let accountKeyBinds = getClientData(client).accountData.keyBinds;
for(let i in accountKeyBinds) {
if(accountKeyBinds[i].command == command) {
return accountKeyBinds[i];
}
}
return false;
}
// ---------------------------------------------------------------------------
function doesPlayerHaveKeyBindForKey(client, key) {
let accountKeyBinds = getClientData(client).accountData.keyBinds;
for(let i in accountKeyBinds) {
if(accountKeyBinds[i].key == key) {
return true;
}
}
return false;
}
// ---------------------------------------------------------------------------
function getPlayerKeyBindForKey(client, key) {
let accountKeyBinds = getClientData(client).accountData.keyBinds;
for(let i in accountKeyBinds) {
if(accountKeyBinds[i].key == key) {
return accountKeyBinds[i];
}
}
return false;
}
// ---------------------------------------------------------------------------
function playerUsedKeyBind(client, key) {
if(doesPlayerHaveKeyBindForKey(client, key)) {
let keyBindData = getPlayerKeyBindForKey(client, key);
if(keyBindData.enabled) {
getCommand(keyBindData.command).handlerFunction(keyBindData.command, keyBindData.params, client);
}
}
}
// ---------------------------------------------------------------------------