diff --git a/scripts/client/house.js b/scripts/client/house.js new file mode 100644 index 00000000..ecdc5d9a --- /dev/null +++ b/scripts/client/house.js @@ -0,0 +1,109 @@ +// =========================================================================== +// Vortrex's Roleplay Resource +// https://github.com/VortrexFTW/gtac_roleplay +// =========================================================================== +// FILE: house.js +// DESC: Provides house functions and usage +// TYPE: Client (JavaScript) +// =========================================================================== + +class HouseData { + constructor(houseId, entrancePosition, blipModel, pickupModel, hasInterior) { + this.index = -1; + this.houseId = houseId; + this.entrancePosition = entrancePosition; + this.blipModel = blipModel; + this.pickupModel = pickupModel; + this.hasInterior = hasInterior; + this.blipId = -1; + } +} + +// =========================================================================== + +function receiveHouseFromServer(houseId, entrancePosition, blipModel, pickupModel, hasInterior) { + logToConsole(LOG_DEBUG, `[VRR.House] Received house ${houseId} (${name}) from server`); + + if(getGame() == VRR_GAME_GTA_IV) { + if(getHouseData(houseId) != false) { + let houseData = getHouseData(houseId); + houseData.entrancePosition = entrancePosition; + houseData.blipModel = blipModel; + houseData.pickupModel = pickupModel; + houseData.hasInterior = hasInterior; + + logToConsole(LOG_DEBUG, `[VRR.House] House ${houseId} already exists. Checking blip ...`); + if(blipModel == -1) { + if(houseData.blipId != -1) { + logToConsole(LOG_DEBUG, `[VRR.House] House ${houseId}'s blip has been removed by the server`); + if(getGame() == VRR_GAME_GTA_IV) { + natives.removeBlipAndClearIndex(getHouseData(houseId).blipId); + } else { + destroyElement(getElementFromId(blipId)); + } + houseData.blipId = -1; + } else { + logToConsole(LOG_DEBUG, `[VRR.House] House ${houseId}'s blip is unchanged`); + } + } else { + if(houseData.blipId != -1) { + logToConsole(LOG_DEBUG, `[VRR.House] House ${houseId}'s blip has been changed by the server`); + if(getGame() == VRR_GAME_GTA_IV) { + natives.setBlipCoordinates(houseData.blipId, houseData.entrancePosition); + natives.changeBlipSprite(houseData.blipId, houseData.blipModel); + natives.setBlipMarkerLongDistance(houseData.blipId, false); + natives.setBlipAsShortRange(houseData.blipId, true); + natives.changeBlipNameFromAscii(houseData.blipId, `${houseData.name.substr(0, 24)}${(houseData.name.length > 24) ? " ...": ""}`); + } + } else { + let blipId = createGameBlip(houseData.blipModel, houseData.entrancePosition, houseData.name); + if(blipId != -1) { + houseData.blipId = blipId; + } + logToConsole(LOG_DEBUG, `[VRR.House] House ${houseId}'s blip has been added by the server (Model ${blipModel}, ID ${blipId})`); + } + } + } else { + logToConsole(LOG_DEBUG, `[VRR.House] House ${houseId} doesn't exist. Adding ...`); + let tempHouseData = new HouseData(houseId, entrancePosition, blipModel, pickupModel, hasInterior); + if(blipModel != -1) { + let blipId = createGameBlip(tempHouseData.blipModel, tempHouseData.entrancePosition, "House"); + if(blipId != -1) { + tempHouseData.blipId = blipId; + } + logToConsole(LOG_DEBUG, `[VRR.House] House ${houseId}'s blip has been added by the server (Model ${blipModel}, ID ${blipId})`); + } else { + logToConsole(LOG_DEBUG, `[VRR.House] House ${houseId} has no blip.`); + } + getServerData().houses.push(tempHouseData); + setAllHouseDataIndexes(); + } + } +} + +// =========================================================================== + +/** + * @param {number} houseId - The ID of the house (initially provided by server) + * @return {HouseData} The house's data (class instance) + */ + function getHouseData(houseId) { + let houses = getServerData().houses; + for(let i in houses) { + if(houses[i].houseId == houseId) { + return houses[i]; + } + } + + return false; +} + +// =========================================================================== + +function setAllHouseDataIndexes() { + for(let i in getServerData().houses) { + getServerData().houses[i].index = i; + } +} + +// =========================================================================== \ No newline at end of file diff --git a/scripts/client/locale.js b/scripts/client/locale.js new file mode 100644 index 00000000..53eb182a --- /dev/null +++ b/scripts/client/locale.js @@ -0,0 +1,31 @@ +// =========================================================================== +// Vortrex's Roleplay Resource +// https://github.com/VortrexFTW/gtac_roleplay +// =========================================================================== +// FILE: locale.js +// DESC: Provides locale functions and usage +// TYPE: Client (JavaScript) +// =========================================================================== + +function getLocaleString(stringName, ...args) { + if(typeof getServerData().localeStrings[stringName] == undefined) { + return ""; + } + + let tempString = getServerData().localeStrings[stringName]; + + for(let i = 1; i <= args.length; i++) { + tempString = tempString.replace(`{${i}}`, args[i-1]); + } + + return tempString; +} + +// =========================================================================== + +function receiveLocaleStringFromServer(stringName, stringValue) { + logToConsole(LOG_INFO, `[VRR.Locale]: Received locale string "${stringName}" from server (${stringValue})`); + getServerData().localeStrings[stringName] = stringValue; +} + +// =========================================================================== \ No newline at end of file diff --git a/scripts/client/vehicle.js b/scripts/client/vehicle.js new file mode 100644 index 00000000..2b28e5a2 --- /dev/null +++ b/scripts/client/vehicle.js @@ -0,0 +1,18 @@ +// =========================================================================== +// Vortrex's Roleplay Resource +// https://github.com/VortrexFTW/gtac_roleplay +// =========================================================================== +// FILE: vehicle.js +// DESC: Provides vehicle functions and arrays with data +// TYPE: Client (JavaScript) +// =========================================================================== + +function receiveVehicleFromServer(vehicleId, position, model, colour1, colour2, colour3 = 0, colour4 = 0) { + logToConsole(LOG_DEBUG, `[VRR.Job] Received vehicle ${vehicleId} (${getVehicleNameFromModel(model, getGame())}) from server`); + + if(getGame() == VRR_GAME_GTA_IV) { + + } +} + +// =========================================================================== \ No newline at end of file