From 2859fc5803081a87c3d97cf33bab13d27d471c4c Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Tue, 24 Aug 2021 19:52:47 -0500 Subject: [PATCH] Load biz game scripts from db, index biz loc/script --- scripts/server/business.js | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/scripts/server/business.js b/scripts/server/business.js index 1c80c621..9ace3e0a 100644 --- a/scripts/server/business.js +++ b/scripts/server/business.js @@ -62,6 +62,7 @@ function loadBusinessesFromDatabase() { while(dbAssoc = fetchQueryAssoc(dbQuery)) { let tempBusinessData = new serverClasses.businessData(dbAssoc); tempBusinessData.locations = loadBusinessLocationsFromDatabase(tempBusinessData.databaseId); + tempBusinessData.gameScripts = loadBusinessGameScriptsFromDatabase(tempBusinessData.databaseId); tempBusinesses.push(tempBusinessData); logToConsole(LOG_INFO, `[VRR.Business]: Business '${tempBusinessData.name}' (ID ${tempBusinessData.databaseId}) loaded from database successfully!`); } @@ -108,6 +109,37 @@ function loadBusinessLocationsFromDatabase(businessId) { // =========================================================================== +function loadBusinessGameScriptsFromDatabase(businessId) { + logToConsole(LOG_VERBOSE, `[VRR.Business]: Loading business game scripts for business ${businessId} from database ...`); + + let tempBusinessGameScripts = []; + let dbConnection = connectToDatabase(); + let dbQuery = null; + let dbAssoc; + let dbQueryString = ""; + + if(dbConnection) { + dbQueryString = `SELECT * FROM biz_script WHERE biz_script_biz = ${businessId}`; + dbQuery = queryDatabase(dbConnection, dbQueryString); + if(dbQuery) { + if(dbQuery.numRows > 0) { + while(dbAssoc = fetchQueryAssoc(dbQuery)) { + let tempBusinessGameScriptData = new serverClasses.businessGameScriptData(dbAssoc); + tempBusinessGameScripts.push(tempBusinessGameScriptData); + logToConsole(LOG_VERBOSE, `[VRR.Business]: Game script '${tempBusinessGameScriptData.name}' loaded from database successfully!`); + } + } + freeDatabaseQuery(dbQuery); + } + disconnectFromDatabase(dbConnection); + } + + logToConsole(LOG_VERBOSE, `[VRR.Business]: ${tempBusinessGameScripts.length} game scripts for business ${businessId} loaded from database successfully!`); + return tempBusinessGameScripts; +} + +// =========================================================================== + function createBusinessCommand(command, params, client) { let tempBusinessData = createBusiness(params, getPlayerPosition(client), toVector3(0.0, 0.0, 0.0), getGameConfig().pickupModels[getServerGame()].business, getGameConfig().blipSprites[getServerGame()].business, getPlayerInterior(client), getPlayerDimension(client)); getServerData().businesses.push(tempBusinessData); @@ -1230,6 +1262,16 @@ function reloadAllBusinessesCommand(command, params, client) { function setAllBusinessIndexes() { for(let i in getServerData().businesses) { getServerData().businesses[i].index = i; + + for(let j in getServerData().businesses[i].locations) { + getServerData().businesses[i].locations[j].index = j; + getServerData().businesses[i].locations[j].businessIndex = i; + } + + for(let j in getServerData().businesses[i].gameScripts) { + getServerData().businesses[i].gameScripts[j].index = j; + getServerData().businesses[i].gameScripts[j].businessIndex = i; + } } } @@ -1579,4 +1621,20 @@ function doesBusinessHaveAnyItemsToBuy(businessId) { return (getBusinessData(businessId).floorItemCache.length > 0); } +// =========================================================================== + +function sendPlayerBusinessGameScripts(client, businessId) { + for(let i in getBusinessData(businessId).gameScripts) { + sendPlayerGameScriptState(client, getBusinessData(businessId).gameScripts[i].state); + } +} + +// =========================================================================== + +function clearPlayerBusinessGameScripts(client, businessId) { + for(let i in getBusinessData(businessId).gameScripts) { + sendPlayerGameScriptState(client, VRR_GAMESCRIPT_DENY); + } +} + // =========================================================================== \ No newline at end of file