Use simpler chunked list for characters

This commit is contained in:
Vortrex
2022-06-07 10:25:15 -05:00
parent 9e9be6ef0c
commit a8f5eb6a9a

View File

@@ -16,12 +16,12 @@ function initSubAccountScript() {
function loadSubAccountFromName(firstName, lastName) { function loadSubAccountFromName(firstName, lastName) {
let dbConnection = connectToDatabase(); let dbConnection = connectToDatabase();
if(dbConnection) { if (dbConnection) {
firstName = escapeDatabaseString(dbConnection, firstName); firstName = escapeDatabaseString(dbConnection, firstName);
lastName = escapeDatabaseString(dbConnection, lastName); lastName = escapeDatabaseString(dbConnection, lastName);
let dbQueryString = `SELECT * FROM sacct_main INNER JOIN sacct_svr ON sacct_svr.sacct_svr_sacct=sacct_main.sacct_id AND sacct_svr.sacct_svr_server=${getServerId()} WHERE sacct_name_first = '${firstName}' AND sacct_name_last = '${lastName}' LIMIT 1;`; let dbQueryString = `SELECT * FROM sacct_main INNER JOIN sacct_svr ON sacct_svr.sacct_svr_sacct=sacct_main.sacct_id AND sacct_svr.sacct_svr_server=${getServerId()} WHERE sacct_name_first = '${firstName}' AND sacct_name_last = '${lastName}' LIMIT 1;`;
let dbQuery = queryDatabase(dbConnection, dbQueryString); let dbQuery = queryDatabase(dbConnection, dbQueryString);
if(dbQuery) { if (dbQuery) {
let dbAssoc = fetchQueryAssoc(dbQuery); let dbAssoc = fetchQueryAssoc(dbQuery);
freeDatabaseQuery(dbQuery); freeDatabaseQuery(dbQuery);
return new SubAccountData(dbAssoc); return new SubAccountData(dbAssoc);
@@ -36,10 +36,10 @@ function loadSubAccountFromName(firstName, lastName) {
function loadSubAccountFromId(subAccountId) { function loadSubAccountFromId(subAccountId) {
let dbConnection = connectToDatabase(); let dbConnection = connectToDatabase();
if(dbConnection) { if (dbConnection) {
let dbQueryString = `SELECT * FROM sacct_main INNER JOIN sacct_svr ON sacct_svr.sacct_svr_sacct=sacct_main.sacct_id AND sacct_svr.sacct_svr_server=${getServerId()} WHERE sacct_id = ${subAccountId} LIMIT 1;`; let dbQueryString = `SELECT * FROM sacct_main INNER JOIN sacct_svr ON sacct_svr.sacct_svr_sacct=sacct_main.sacct_id AND sacct_svr.sacct_svr_server=${getServerId()} WHERE sacct_id = ${subAccountId} LIMIT 1;`;
let dbQuery = queryDatabase(dbConnection, dbQueryString); let dbQuery = queryDatabase(dbConnection, dbQueryString);
if(dbQuery) { if (dbQuery) {
let dbAssoc = fetchQueryAssoc(dbQuery); let dbAssoc = fetchQueryAssoc(dbQuery);
freeDatabaseQuery(dbQuery); freeDatabaseQuery(dbQuery);
return new SubAccountData(dbAssoc); return new SubAccountData(dbAssoc);
@@ -55,31 +55,31 @@ function loadSubAccountFromId(subAccountId) {
function loadSubAccountsFromAccount(accountId) { function loadSubAccountsFromAccount(accountId) {
let tempSubAccounts = []; let tempSubAccounts = [];
let dbAssoc = false; let dbAssoc = false;
if(accountId > 0) { if (accountId > 0) {
let dbConnection = connectToDatabase(); let dbConnection = connectToDatabase();
if(dbConnection) { if (dbConnection) {
let dbQueryString = `SELECT * FROM sacct_main INNER JOIN sacct_svr ON sacct_svr.sacct_svr_sacct=sacct_main.sacct_id AND sacct_svr.sacct_svr_server=${getServerId()} WHERE sacct_acct = ${accountId} AND sacct_server = ${getServerId()}`; let dbQueryString = `SELECT * FROM sacct_main INNER JOIN sacct_svr ON sacct_svr.sacct_svr_sacct=sacct_main.sacct_id AND sacct_svr.sacct_svr_server=${getServerId()} WHERE sacct_acct = ${accountId} AND sacct_server = ${getServerId()}`;
let dbQuery = queryDatabase(dbConnection, dbQueryString); let dbQuery = queryDatabase(dbConnection, dbQueryString);
if(dbQuery) { if (dbQuery) {
while(dbAssoc = fetchQueryAssoc(dbQuery)) { while (dbAssoc = fetchQueryAssoc(dbQuery)) {
let tempSubAccount = new SubAccountData(dbAssoc); let tempSubAccount = new SubAccountData(dbAssoc);
// Make sure skin is valid // Make sure skin is valid
if(tempSubAccount.skin == -1) { if (tempSubAccount.skin == -1) {
tempSubAccount.skin = getServerConfig().newCharacter.skin; tempSubAccount.skin = getServerConfig().newCharacter.skin;
} }
// Check if clan and rank are still valid // Check if clan and rank are still valid
if(tempSubAccount.clan != 0) { if (tempSubAccount.clan != 0) {
let clanId = getClanIdFromDatabaseId(tempSubAccount.clan); let clanId = getClanIdFromDatabaseId(tempSubAccount.clan);
if(!getClanData(clanId)) { if (!getClanData(clanId)) {
tempSubAccount.clan = 0; tempSubAccount.clan = 0;
tempSubAccount.clanRank = 0; tempSubAccount.clanRank = 0;
tempSubAccount.clanTitle = ""; tempSubAccount.clanTitle = "";
tempSubAccount.clanFlags = 0; tempSubAccount.clanFlags = 0;
} else { } else {
let rankId = getClanRankIdFromDatabaseId(clanId, tempSubAccount.clanRank); let rankId = getClanRankIdFromDatabaseId(clanId, tempSubAccount.clanRank);
if(!getClanRankData(clanId, rankId)) { if (!getClanRankData(clanId, rankId)) {
tempSubAccount.clanRank = 0; tempSubAccount.clanRank = 0;
} }
} }
@@ -101,7 +101,7 @@ function loadSubAccountsFromAccount(accountId) {
function saveSubAccountToDatabase(subAccountData) { function saveSubAccountToDatabase(subAccountData) {
let dbConnection = connectToDatabase(); let dbConnection = connectToDatabase();
if(dbConnection) { if (dbConnection) {
let safeClanTag = escapeDatabaseString(dbConnection, subAccountData.ClanTag); let safeClanTag = escapeDatabaseString(dbConnection, subAccountData.ClanTag);
let safeClanTitle = escapeDatabaseString(dbConnection, subAccountData.clanTitle); let safeClanTitle = escapeDatabaseString(dbConnection, subAccountData.clanTitle);
let safeFirstName = escapeDatabaseString(dbConnection, subAccountData.firstName); let safeFirstName = escapeDatabaseString(dbConnection, subAccountData.firstName);
@@ -171,7 +171,7 @@ function saveSubAccountToDatabase(subAccountData) {
["sacct_svr_hd_prop_rightwrist_model", subAccountData.bodyProps.rightWrist[0]], ["sacct_svr_hd_prop_rightwrist_model", subAccountData.bodyProps.rightWrist[0]],
["sacct_svr_hd_prop_rightwrist_texture", subAccountData.bodyProps.rightWrist[1]], ["sacct_svr_hd_prop_rightwrist_texture", subAccountData.bodyProps.rightWrist[1]],
["sacct_svr_hd_prop_hip_model", subAccountData.bodyProps.hip[0]], ["sacct_svr_hd_prop_hip_model", subAccountData.bodyProps.hip[0]],
["sacct_svr_hd_prop_hip_texture",subAccountData.bodyProps.hip[1]], ["sacct_svr_hd_prop_hip_texture", subAccountData.bodyProps.hip[1]],
["sacct_svr_hd_prop_leftfoot_model", subAccountData.bodyProps.leftFoot[0]], ["sacct_svr_hd_prop_leftfoot_model", subAccountData.bodyProps.leftFoot[0]],
["sacct_svr_hd_prop_leftfoot_texture", subAccountData.bodyProps.leftFoot[1]], ["sacct_svr_hd_prop_leftfoot_texture", subAccountData.bodyProps.leftFoot[1]],
["sacct_svr_hd_prop_rightfoot_model", subAccountData.bodyProps.rightFoot[0]], ["sacct_svr_hd_prop_rightfoot_model", subAccountData.bodyProps.rightFoot[0]],
@@ -196,7 +196,7 @@ function createSubAccount(accountId, firstName, lastName) {
let dbConnection = connectToDatabase(); let dbConnection = connectToDatabase();
let dbQuery = false; let dbQuery = false;
if(dbConnection) { if (dbConnection) {
firstName = fixCharacterName(firstName); firstName = fixCharacterName(firstName);
lastName = fixCharacterName(lastName); lastName = fixCharacterName(lastName);
let safeFirstName = escapeDatabaseString(dbConnection, firstName); let safeFirstName = escapeDatabaseString(dbConnection, firstName);
@@ -204,13 +204,13 @@ function createSubAccount(accountId, firstName, lastName) {
dbQuery = queryDatabase(dbConnection, `INSERT INTO sacct_main (sacct_acct, sacct_name_first, sacct_name_last, sacct_pos_x, sacct_pos_y, sacct_pos_z, sacct_rot_z, sacct_cash, sacct_server, sacct_health, sacct_when_made, sacct_when_lastlogin) VALUES (${accountId}, '${safeFirstName}', '${safeLastName}', ${getServerConfig().newCharacter.spawnPosition.x}, ${getServerConfig().newCharacter.spawnPosition.y}, ${getServerConfig().newCharacter.spawnPosition.z}, ${getServerConfig().newCharacter.spawnHeading}, ${getServerConfig().newCharacter.money}, ${getServerId()}, 100, CURRENT_TIMESTAMP(), 0)`); dbQuery = queryDatabase(dbConnection, `INSERT INTO sacct_main (sacct_acct, sacct_name_first, sacct_name_last, sacct_pos_x, sacct_pos_y, sacct_pos_z, sacct_rot_z, sacct_cash, sacct_server, sacct_health, sacct_when_made, sacct_when_lastlogin) VALUES (${accountId}, '${safeFirstName}', '${safeLastName}', ${getServerConfig().newCharacter.spawnPosition.x}, ${getServerConfig().newCharacter.spawnPosition.y}, ${getServerConfig().newCharacter.spawnPosition.z}, ${getServerConfig().newCharacter.spawnHeading}, ${getServerConfig().newCharacter.money}, ${getServerId()}, 100, CURRENT_TIMESTAMP(), 0)`);
//if(dbQuery) { //if(dbQuery) {
if(getDatabaseInsertId(dbConnection) > 0) { if (getDatabaseInsertId(dbConnection) > 0) {
let dbInsertId = getDatabaseInsertId(dbConnection); let dbInsertId = getDatabaseInsertId(dbConnection);
createDefaultSubAccountServerData(dbInsertId, getServerConfig().newCharacter.skin); createDefaultSubAccountServerData(dbInsertId, getServerConfig().newCharacter.skin);
let tempSubAccount = loadSubAccountFromId(dbInsertId); let tempSubAccount = loadSubAccountFromId(dbInsertId);
return tempSubAccount; return tempSubAccount;
} }
//freeDatabaseQuery(dbQuery); //freeDatabaseQuery(dbQuery);
//} //}
disconnectFromDatabase(dbConnection); disconnectFromDatabase(dbConnection);
} }
@@ -223,20 +223,20 @@ function createSubAccount(accountId, firstName, lastName) {
function showCharacterSelectToClient(client) { function showCharacterSelectToClient(client) {
getPlayerData(client).switchingCharacter = true; getPlayerData(client).switchingCharacter = true;
if(doesPlayerHaveAutoSelectLastCharacterEnabled(client)) { if (doesPlayerHaveAutoSelectLastCharacterEnabled(client)) {
if(getPlayerData(client).subAccounts.length > 0) { if (getPlayerData(client).subAccounts.length > 0) {
logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is being auto-spawned as character ID ${getPlayerLastUsedSubAccount(client)}`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is being auto-spawned as character ID ${getPlayerLastUsedSubAccount(client)}`);
selectCharacter(client, getPlayerLastUsedSubAccount(client)); selectCharacter(client, getPlayerLastUsedSubAccount(client));
return true; return true;
} }
} }
if(doesServerHaveGUIEnabled() && doesPlayerHaveGUIEnabled(client)) { if (doesServerHaveGUIEnabled() && doesPlayerHaveGUIEnabled(client)) {
getPlayerData(client).currentSubAccount = 0; getPlayerData(client).currentSubAccount = 0;
logToConsole(LOG_DEBUG, `[VRR.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`);
let tempSubAccount = getPlayerData(client).subAccounts[0]; let tempSubAccount = getPlayerData(client).subAccounts[0];
let clanName = (tempSubAccount.clan != 0) ? getClanData(getClanIdFromDatabaseId(tempSubAccount.clan)).name : "None"; let clanName = (tempSubAccount.clan != 0) ? getClanData(getClanIdFromDatabaseId(tempSubAccount.clan)).name : "None";
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${msToTime(getCurrentUnixTimestamp()-tempSubAccount.lastLogin)} ago` : "Never"; let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${msToTime(getCurrentUnixTimestamp() - tempSubAccount.lastLogin)} ago` : "Never";
showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, getGameConfig().skins[getGame()][tempSubAccount.skin][0]); showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, getGameConfig().skins[getGame()][tempSubAccount.skin][0]);
//spawnPlayer(client, getServerConfig().characterSelectPedPosition, getServerConfig().characterSelectPedHeading, getPlayerCurrentSubAccount(client).skin, getServerConfig().characterSelectInterior, getServerConfig().characterSelectDimension); //spawnPlayer(client, getServerConfig().characterSelectPedPosition, getServerConfig().characterSelectPedHeading, getPlayerCurrentSubAccount(client).skin, getServerConfig().characterSelectInterior, getServerConfig().characterSelectDimension);
@@ -245,16 +245,12 @@ function showCharacterSelectToClient(client) {
//}, 500); //}, 500);
logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is being shown the character select GUI`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is being shown the character select GUI`);
} else { } else {
//let emojiNumbers = ["➊", "➋", "➌", "➍", "➎", "➏", "➐", "➑", "➒"]; let charactersList = getPlayerData(client).subAccounts.map(sacct, index => `{teal}${index}: {ALTCOLOUR}${sacct.name}`);
//let emojiNumbers = ["①", "②", "③", "④", "⑤", "⑥", "⑦", "⑧", "⑨"]; let chunkedList = splitArrayIntoChunks(charactersList, 5);
//let emojiNumbers = ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣"]; messagePlayerNormal(client, makeChatBoxSectionHeader(getLocaleString(client, "HeaderCharacterListSelf")));
messagePlayerNormal(client, `You have the following characters. Use /usechar <id> to select one:`, getColourByName("teal")); for (let i in chunkedList) {
getPlayerData(client).subAccounts.forEach(function(subAccount, index) { messagePlayerNormal(client, chunkedList[i].join("{MAINCOLOUR}, "));
let tempSubAccount = getPlayerData(client).subAccounts[0]; }
//let clanName = (tempSubAccount.clan != 0) ? getClanData(getClanIdFromDatabaseId(tempSubAccount.clan)).name : "None";
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${msToTime(getCurrentUnixTimestamp()-tempSubAccount.lastLogin)} ago` : "Never";
messagePlayerNormal(client, `${index+1} • [#BBBBBB]${subAccount.firstName} ${subAccount.lastName} ($${tempSubAccount.cash}, ${lastPlayedText})`);
});
logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is being shown the character select/list message (GUI disabled)`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is being shown the character select/list message (GUI disabled)`);
} }
} }
@@ -262,25 +258,25 @@ function showCharacterSelectToClient(client) {
// =========================================================================== // ===========================================================================
function checkNewCharacter(client, firstName, lastName) { function checkNewCharacter(client, firstName, lastName) {
if(areParamsEmpty(firstName)) { if (areParamsEmpty(firstName)) {
showPlayerNewCharacterFailedGUI(client, "First name cannot be blank!"); showPlayerNewCharacterFailedGUI(client, "First name cannot be blank!");
return false; return false;
} }
firstName = firstName.trim(); firstName = firstName.trim();
if(areParamsEmpty(lastName)) { if (areParamsEmpty(lastName)) {
showPlayerNewCharacterFailedGUI(client, "Last name cannot be blank!"); showPlayerNewCharacterFailedGUI(client, "Last name cannot be blank!");
return false; return false;
} }
lastName = lastName.trim(); lastName = lastName.trim();
if(doesNameContainInvalidCharacters(firstName) || doesNameContainInvalidCharacters(lastName)) { if (doesNameContainInvalidCharacters(firstName) || doesNameContainInvalidCharacters(lastName)) {
logToConsole(LOG_INFO|LOG_WARN, `[VRR.Account] Subaccount ${firstName} ${lastName} could not be created (invalid characters in name)`); logToConsole(LOG_INFO | LOG_WARN, `[VRR.Account] Subaccount ${firstName} ${lastName} could not be created (invalid characters in name)`);
showPlayerNewCharacterFailedGUI(client, "Invalid characters in name!"); showPlayerNewCharacterFailedGUI(client, "Invalid characters in name!");
return false; return false;
} }
if(getPlayerData(client).changingCharacterName) { if (getPlayerData(client).changingCharacterName) {
getPlayerCurrentSubAccount(client).firstName = fixCharacterName(firstName); getPlayerCurrentSubAccount(client).firstName = fixCharacterName(firstName);
getPlayerCurrentSubAccount(client).lastName = fixCharacterName(lastName); getPlayerCurrentSubAccount(client).lastName = fixCharacterName(lastName);
updateAllPlayerNameTags(client); updateAllPlayerNameTags(client);
@@ -289,8 +285,8 @@ function checkNewCharacter(client, firstName, lastName) {
} }
let subAccountData = createSubAccount(getPlayerData(client).accountData.databaseId, firstName, lastName); let subAccountData = createSubAccount(getPlayerData(client).accountData.databaseId, firstName, lastName);
if(!subAccountData) { if (!subAccountData) {
if(doesServerHaveGUIEnabled() && doesPlayerHaveGUIEnabled(client)) { if (doesServerHaveGUIEnabled() && doesPlayerHaveGUIEnabled(client)) {
showPlayerNewCharacterFailedGUI(client, "Your character could not be created!"); showPlayerNewCharacterFailedGUI(client, "Your character could not be created!");
} else { } else {
messagePlayerError(client, "Your character could not be created!"); messagePlayerError(client, "Your character could not be created!");
@@ -302,16 +298,15 @@ function checkNewCharacter(client, firstName, lastName) {
getPlayerData(client).subAccounts = loadSubAccountsFromAccount(getPlayerData(client).accountData.databaseId); getPlayerData(client).subAccounts = loadSubAccountsFromAccount(getPlayerData(client).accountData.databaseId);
getPlayerData(client).currentSubAccount = 0; getPlayerData(client).currentSubAccount = 0;
getPlayerData(client).creatingCharacter = false; getPlayerData(client).creatingCharacter = false;
let tempSubAccount = getPlayerData(client).subAccounts[0];
showCharacterSelectToClient(client); showCharacterSelectToClient(client);
} }
// =========================================================================== // ===========================================================================
function checkPreviousCharacter(client) { function checkPreviousCharacter(client) {
if(getPlayerData(client).subAccounts.length > 1) { if (getPlayerData(client).subAccounts.length > 1) {
if(getPlayerData(client).currentSubAccount <= 0) { if (getPlayerData(client).currentSubAccount <= 0) {
getPlayerData(client).currentSubAccount = getPlayerData(client).subAccounts.length-1; getPlayerData(client).currentSubAccount = getPlayerData(client).subAccounts.length - 1;
} else { } else {
getPlayerData(client).currentSubAccount--; getPlayerData(client).currentSubAccount--;
} }
@@ -320,7 +315,7 @@ function checkPreviousCharacter(client) {
let tempSubAccount = getPlayerData(client).subAccounts[subAccountId]; let tempSubAccount = getPlayerData(client).subAccounts[subAccountId];
let clanName = (tempSubAccount.clan != 0) ? getClanData(getClanIdFromDatabaseId(tempSubAccount.clan)).name : "None"; let clanName = (tempSubAccount.clan != 0) ? getClanData(getClanIdFromDatabaseId(tempSubAccount.clan)).name : "None";
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${msToTime(getCurrentUnixTimestamp()-tempSubAccount.lastLogin)} ago` : "Never"; let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${msToTime(getCurrentUnixTimestamp() - tempSubAccount.lastLogin)} ago` : "Never";
showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, getGameConfig().skins[getGame()][tempSubAccount.skin][0]); showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, getGameConfig().skins[getGame()][tempSubAccount.skin][0]);
logToConsole(LOG_DEBUG, `[VRR.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`);
@@ -330,8 +325,8 @@ function checkPreviousCharacter(client) {
// =========================================================================== // ===========================================================================
function checkNextCharacter(client) { function checkNextCharacter(client) {
if(getPlayerData(client).subAccounts.length > 1) { if (getPlayerData(client).subAccounts.length > 1) {
if(getPlayerData(client).currentSubAccount >= getPlayerData(client).subAccounts.length-1) { if (getPlayerData(client).currentSubAccount >= getPlayerData(client).subAccounts.length - 1) {
getPlayerData(client).currentSubAccount = 0; getPlayerData(client).currentSubAccount = 0;
} else { } else {
getPlayerData(client).currentSubAccount++; getPlayerData(client).currentSubAccount++;
@@ -341,7 +336,7 @@ function checkNextCharacter(client) {
let tempSubAccount = getPlayerData(client).subAccounts[subAccountId]; let tempSubAccount = getPlayerData(client).subAccounts[subAccountId];
let clanName = (tempSubAccount.clan != 0) ? getClanData(getClanIdFromDatabaseId(tempSubAccount.clan)).name : "None"; let clanName = (tempSubAccount.clan != 0) ? getClanData(getClanIdFromDatabaseId(tempSubAccount.clan)).name : "None";
let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${msToTime(getCurrentUnixTimestamp()-tempSubAccount.lastLogin)} ago` : "Never"; let lastPlayedText = (tempSubAccount.lastLogin != 0) ? `${msToTime(getCurrentUnixTimestamp() - tempSubAccount.lastLogin)} ago` : "Never";
showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, getGameConfig().skins[getGame()][tempSubAccount.skin][0]); showPlayerCharacterSelectGUI(client, tempSubAccount.firstName, tempSubAccount.lastName, tempSubAccount.cash, clanName, lastPlayedText, getGameConfig().skins[getGame()][tempSubAccount.skin][0]);
logToConsole(LOG_DEBUG, `[VRR.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] Setting ${getPlayerDisplayForConsole(client)}'s character to ID ${getPlayerData(client).currentSubAccount}`);
@@ -352,7 +347,7 @@ function checkNextCharacter(client) {
function selectCharacter(client, characterId = -1) { function selectCharacter(client, characterId = -1) {
logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} character select called (Character ID ${characterId})`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} character select called (Character ID ${characterId})`);
if(characterId != -1) { if (characterId != -1) {
logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} provided character ID (${characterId}) to spawn with`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} provided character ID (${characterId}) to spawn with`);
getPlayerData(client).currentSubAccount = characterId; getPlayerData(client).currentSubAccount = characterId;
} }
@@ -371,9 +366,9 @@ function selectCharacter(client, characterId = -1) {
//setPlayerCameraLookAt(client, getPosBehindPos(spawnPosition, spawnHeading, 5), spawnPosition); //setPlayerCameraLookAt(client, getPosBehindPos(spawnPosition, spawnHeading, 5), spawnPosition);
getPlayerData(client).pedState = VRR_PEDSTATE_SPAWNING; getPlayerData(client).pedState = VRR_PEDSTATE_SPAWNING;
if(getGame() <= VRR_GAME_GTA_SA) { if (getGame() <= VRR_GAME_GTA_SA) {
spawnPlayer(client, spawnPosition, spawnHeading, getGameConfig().skins[getGame()][skin][0], spawnInterior, spawnDimension); spawnPlayer(client, spawnPosition, spawnHeading, getGameConfig().skins[getGame()][skin][0], spawnInterior, spawnDimension);
} else if(getGame() == VRR_GAME_GTA_IV) { } else if (getGame() == VRR_GAME_GTA_IV) {
spawnPlayer(client, spawnPosition, spawnHeading, getGameConfig().skins[getGame()][skin][0], spawnInterior, spawnDimension); spawnPlayer(client, spawnPosition, spawnHeading, getGameConfig().skins[getGame()][skin][0], spawnInterior, spawnDimension);
//clearPlayerWeapons(client); //clearPlayerWeapons(client);
//setPlayerSkin(client, skin); //setPlayerSkin(client, skin);
@@ -382,7 +377,7 @@ function selectCharacter(client, characterId = -1) {
//setPlayerInterior(client, spawnInterior); //setPlayerInterior(client, spawnInterior);
//setPlayerDimension(client, spawnDimension); //setPlayerDimension(client, spawnDimension);
//restorePlayerCamera(client); //restorePlayerCamera(client);
} else if(getGame() == VRR_GAME_MAFIA_ONE) { } else if (getGame() == VRR_GAME_MAFIA_ONE) {
//spawnPlayer(client, spawnPosition, spawnHeading, getGameConfig().skins[getGame()][skin][0]); //spawnPlayer(client, spawnPosition, spawnHeading, getGameConfig().skins[getGame()][skin][0]);
logToConsole(LOG_DEBUG, `[VRR.SubAccount] Spawning ${getPlayerDisplayForConsole(client)} as ${getGameConfig().skins[getGame()][skin][1]} (${getGameConfig().skins[getGame()][skin][0]})`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] Spawning ${getPlayerDisplayForConsole(client)} as ${getGameConfig().skins[getGame()][skin][1]} (${getGameConfig().skins[getGame()][skin][0]})`);
spawnPlayer(client, getGameConfig().skins[getGame()][skin][0], spawnPosition, spawnHeading); spawnPlayer(client, getGameConfig().skins[getGame()][skin][0], spawnPosition, spawnHeading);
@@ -392,7 +387,7 @@ function selectCharacter(client, characterId = -1) {
logToConsole(LOG_DEBUG, `[VRR.SubAccount] Spawned ${getPlayerDisplayForConsole(client)} as character ID ${getPlayerData(client).currentSubAccount} with skin ${skin} (${spawnPosition.x}, ${spawnPosition.y}, ${spawnPosition.z})`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] Spawned ${getPlayerDisplayForConsole(client)} as character ID ${getPlayerData(client).currentSubAccount} with skin ${skin} (${spawnPosition.x}, ${spawnPosition.y}, ${spawnPosition.z})`);
setTimeout(function() { setTimeout(function () {
onPlayerSpawn(client); onPlayerSpawn(client);
}, 500); }, 500);
@@ -405,12 +400,12 @@ function selectCharacter(client, characterId = -1) {
function switchCharacterCommand(command, params, client) { function switchCharacterCommand(command, params, client) {
logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is requesting to switch characters (current character: ${getCharacterFullName(client)} [${getPlayerData(client).currentSubAccount}/${getPlayerCurrentSubAccount(client).databaseId}])`); logToConsole(LOG_DEBUG, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is requesting to switch characters (current character: ${getCharacterFullName(client)} [${getPlayerData(client).currentSubAccount}/${getPlayerCurrentSubAccount(client).databaseId}])`);
if(!isPlayerSpawned(client)) { if (!isPlayerSpawned(client)) {
logToConsole(LOG_WARN, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is not allowed to switch characters (not spawned)`); logToConsole(LOG_WARN, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is not allowed to switch characters (not spawned)`);
return false; return false;
} }
if(isPlayerSwitchingCharacter(client)) { if (isPlayerSwitchingCharacter(client)) {
logToConsole(LOG_WARN, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is not allowed to switch characters (already in switch char mode)`); logToConsole(LOG_WARN, `[VRR.SubAccount] ${getPlayerDisplayForConsole(client)} is not allowed to switch characters (already in switch char mode)`);
messagePlayerError(client, "You are already selecting/switching characters!"); messagePlayerError(client, "You are already selecting/switching characters!");
return false; return false;
@@ -422,12 +417,12 @@ function switchCharacterCommand(command, params, client) {
// =========================================================================== // ===========================================================================
function newCharacterCommand(command, params, client) { function newCharacterCommand(command, params, client) {
if(areParamsEmpty(params)) { if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command)); messagePlayerSyntax(client, getCommandSyntaxText(command));
return false; return false;
} }
let firstName = getParam(params, " ", 1); let firstName = getParam(params, " ", 1);
let lastName = getParam(params, " ", 2); let lastName = getParam(params, " ", 2);
checkNewCharacter(client, firstName, lastName); checkNewCharacter(client, firstName, lastName);
@@ -436,19 +431,19 @@ let firstName = getParam(params, " ", 1);
// =========================================================================== // ===========================================================================
function useCharacterCommand(command, params, client) { function useCharacterCommand(command, params, client) {
if(!getPlayerData(client).switchingCharacter) { if (!getPlayerData(client).switchingCharacter) {
messagePlayerError(client, "Use /switchchar to save this character and return to the characters screen first!"); messagePlayerError(client, "Use /switchchar to save this character and return to the characters screen first!");
return false; return false;
} }
if(areParamsEmpty(params)) { if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command)); messagePlayerSyntax(client, getCommandSyntaxText(command));
return false; return false;
} }
let characterId = toInteger(params) || 1; let characterId = toInteger(params) || 1;
selectCharacter(client, characterId-1); selectCharacter(client, characterId - 1);
} }
// =========================================================================== // ===========================================================================
@@ -456,8 +451,8 @@ function useCharacterCommand(command, params, client) {
function getPlayerLastUsedSubAccount(client) { function getPlayerLastUsedSubAccount(client) {
let subAccounts = getPlayerData(client).subAccounts; let subAccounts = getPlayerData(client).subAccounts;
let lastUsed = 0; let lastUsed = 0;
for(let i in subAccounts) { for (let i in subAccounts) {
if(subAccounts[i].lastLogin > subAccounts[lastUsed].lastLogin) { if (subAccounts[i].lastLogin > subAccounts[lastUsed].lastLogin) {
lastUsed = i; lastUsed = i;
} }
} }
@@ -496,16 +491,16 @@ function isPlayerCreatingCharacter(client) {
* *
*/ */
function getPlayerCurrentSubAccount(client) { function getPlayerCurrentSubAccount(client) {
if(!getPlayerData(client)) { if (!getPlayerData(client)) {
return false; return false;
} }
let subAccountId = getPlayerData(client).currentSubAccount; let subAccountId = getPlayerData(client).currentSubAccount;
if(subAccountId == -1) { if (subAccountId == -1) {
return false; return false;
} }
if(typeof getPlayerData(client).subAccounts[subAccountId] == "undefined") { if (typeof getPlayerData(client).subAccounts[subAccountId] == "undefined") {
return false; return false;
} }
@@ -522,21 +517,21 @@ function getClientSubAccountName(client) {
// =========================================================================== // ===========================================================================
function setFightStyleCommand(command, params, client) { function setFightStyleCommand(command, params, client) {
if(areParamsEmpty(params)) { if (areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command)); messagePlayerSyntax(client, getCommandSyntaxText(command));
return false; return false;
} }
let fightStyleId = getFightStyleFromParams(params); let fightStyleId = getFightStyleFromParams(params);
if(!fightStyle) { if (!fightStyle) {
messagePlayerError(client, `That fight style doesn't exist!`); messagePlayerError(client, `That fight style doesn't exist!`);
messagePlayerError(client, `Fight styles: ${getGameConfig().fightStyles[getGame()].map(fs => fs[0]).join(", ")}`); messagePlayerError(client, `Fight styles: ${getGameConfig().fightStyles[getGame()].map(fs => fs[0]).join(", ")}`);
return false; return false;
} }
if(!isPlayerAtGym(client)) { if (!isPlayerAtGym(client)) {
if(!doesPlayerHaveStaffPermission(client, getStaffFlagValue("BasicModeration"))) { if (!doesPlayerHaveStaffPermission(client, getStaffFlagValue("BasicModeration"))) {
messagePlayerError(client, `You need to be at a gym!`); messagePlayerError(client, `You need to be at a gym!`);
return false return false
} }
@@ -551,8 +546,8 @@ function setFightStyleCommand(command, params, client) {
// =========================================================================== // ===========================================================================
function createDefaultSubAccountServerData(databaseId, thisServerSkin) { function createDefaultSubAccountServerData(databaseId, thisServerSkin) {
for(let i = 1 ; i <= 5 ; i++) { for (let i = 1; i <= 5; i++) {
if(i == getServerId()) { if (i == getServerId()) {
let dbQueryString = `INSERT INTO sacct_svr (sacct_svr_sacct, sacct_svr_server, sacct_svr_skin) VALUES (${databaseId}, ${i}, ${thisServerSkin})`; let dbQueryString = `INSERT INTO sacct_svr (sacct_svr_sacct, sacct_svr_server, sacct_svr_skin) VALUES (${databaseId}, ${i}, ${thisServerSkin})`;
quickDatabaseQuery(dbQueryString); quickDatabaseQuery(dbQueryString);
} else { } else {
@@ -582,5 +577,6 @@ function forcePlayerIntoSwitchCharacterScreen(client) {
getPlayerData(client).switchingCharacter = true; getPlayerData(client).switchingCharacter = true;
showConnectCameraToPlayer(client); showConnectCameraToPlayer(client);
showCharacterSelectToClient(client); showCharacterSelectToClient(client);
} }