From 7a21edc8f628bbe366b73c17c1d74f58776739a5 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Tue, 8 Mar 2022 01:08:14 -0600 Subject: [PATCH] New business stuff --- scripts/client/business.js | 52 ++++++++++++++++++++++++ scripts/client/label.js | 81 +++++++++++++++++++++----------------- scripts/client/main.js | 6 +-- scripts/client/sync.js | 37 ----------------- 4 files changed, 100 insertions(+), 76 deletions(-) create mode 100644 scripts/client/business.js diff --git a/scripts/client/business.js b/scripts/client/business.js new file mode 100644 index 00000000..599fec5c --- /dev/null +++ b/scripts/client/business.js @@ -0,0 +1,52 @@ +// =========================================================================== +// Vortrex's Roleplay Resource +// https://github.com/VortrexFTW/gtac_roleplay +// =========================================================================== +// FILE: business.js +// DESC: Provides business functions and usage +// TYPE: Client (JavaScript) +// =========================================================================== + +class BusinessData() { + constructor(index, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems) { + this.index = index; + this.name = name; + this.entrancePosition = entrancePosition; + this.blipModel = blipModel; + this.pickupModel = pickupModel; + this.hasInterior = hasInterior; + this.hasItems = hasItems; + this.blipId = -1; + } +} + +// =========================================================================== + +function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems) { + if(getGame() == VRR_GAME_GTA_IV) { + if(getBusinessData(businessId) != false) { + if(blipModel == -1) { + natives.removeBlipAndClearIndex(getBusinessData(businessId).blipId); + businesses.splice(getBusinessData(businessId).index, 1); + } else { + natives.setBlipCoordinates(getBusinessData(businessId).blipId, getBusinessData(businessId).entrancePosition); + natives.changeBlipSprite(getBusinessData(businessId).blipId, getBusinessData(businessId).blipModel); + natives.changeBlipNameFromAscii(getBusinessData(businessId).blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`); + } + } else { + if(blipModel != -1) { + let blipId = natives.addBlipForCoord(entrancePosition); + if(blipId) { + let tempBusinessData = new BusinessData(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems); + tempBusinessData.blipId = blipId; + natives.changeBlipSprite(blipId, blipModel); + natives.setBlipMarkerLongDistance(blipId, true); + natives.changeBlipNameFromAscii(blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`); + businesses.push(tempBusinessData); + } + } + } + } +} + +// =========================================================================== \ No newline at end of file diff --git a/scripts/client/label.js b/scripts/client/label.js index 70e2df8e..1dd15426 100644 --- a/scripts/client/label.js +++ b/scripts/client/label.js @@ -249,42 +249,51 @@ function renderJobLabel(name, position, jobType) { function processLabelRendering() { if(renderLabels && areWorldLabelsSupported()) { if(localPlayer != null) { - let pickups = getElementsByType(ELEMENT_PICKUP); - for(let i in pickups) { - if(pickups[i].getData("vrr.label.type") != null) { - if(getDistance(localPlayer.position, pickups[i].position) <= renderLabelDistance) { - if(!pickups[i].isOnScreen) { - let price = "0"; - let rentPrice = "0"; - let labelInfoType = VRR_PROPLABEL_INFO_NONE; - if(pickups[i].getData("vrr.label.price") != null) { - price = makeLargeNumberReadable(pickups[i].getData("vrr.label.price")); - } - - if(pickups[i].getData("vrr.label.rentprice") != null) { - rentPrice = makeLargeNumberReadable(pickups[i].getData("vrr.label.rentprice")); - } - - if(pickups[i].getData("vrr.label.help") != null) { - labelInfoType = pickups[i].getData("vrr.label.help"); - } - - switch(pickups[i].getData("vrr.label.type")) { - case VRR_LABEL_BUSINESS: - renderPropertyEntranceLabel(pickups[i].getData("vrr.label.name"), pickups[i].position, pickups[i].getData("vrr.label.locked"), true, price, rentPrice, labelInfoType); - break; - - case VRR_LABEL_HOUSE: - renderPropertyEntranceLabel("House", pickups[i].position, pickups[i].getData("vrr.label.locked"), false, price, rentPrice, labelInfoType); - break; - - case VRR_LABEL_JOB: - renderJobLabel(pickups[i].getData("vrr.label.name"), pickups[i].position, pickups[i].getData("vrr.label.jobType")); - break; - - case VRR_LABEL_EXIT: - renderPropertyExitLabel(pickups[i].position); - break; + if(!areServerElementsSupported()) { + //for(let i in businessBlips) { + // if(pickups[i].getData("vrr.label.type") != null) { + // if(getDistance(localPlayer.position, pickups[i].position) <= renderLabelDistance) { + + // natives.getScreenViewportId + // natives.getViewportPositionOfCoord + } else { + let pickups = getElementsByType(ELEMENT_PICKUP); + for(let i in pickups) { + if(pickups[i].getData("vrr.label.type") != null) { + if(getDistance(localPlayer.position, pickups[i].position) <= renderLabelDistance) { + if(!pickups[i].isOnScreen) { + let price = "0"; + let rentPrice = "0"; + let labelInfoType = VRR_PROPLABEL_INFO_NONE; + if(pickups[i].getData("vrr.label.price") != null) { + price = makeLargeNumberReadable(pickups[i].getData("vrr.label.price")); + } + + if(pickups[i].getData("vrr.label.rentprice") != null) { + rentPrice = makeLargeNumberReadable(pickups[i].getData("vrr.label.rentprice")); + } + + if(pickups[i].getData("vrr.label.help") != null) { + labelInfoType = pickups[i].getData("vrr.label.help"); + } + + switch(pickups[i].getData("vrr.label.type")) { + case VRR_LABEL_BUSINESS: + renderPropertyEntranceLabel(pickups[i].getData("vrr.label.name"), pickups[i].position, pickups[i].getData("vrr.label.locked"), true, price, rentPrice, labelInfoType); + break; + + case VRR_LABEL_HOUSE: + renderPropertyEntranceLabel("House", pickups[i].position, pickups[i].getData("vrr.label.locked"), false, price, rentPrice, labelInfoType); + break; + + case VRR_LABEL_JOB: + renderJobLabel(pickups[i].getData("vrr.label.name"), pickups[i].position, pickups[i].getData("vrr.label.jobType")); + break; + + case VRR_LABEL_EXIT: + renderPropertyExitLabel(pickups[i].position); + break; + } } } } diff --git a/scripts/client/main.js b/scripts/client/main.js index fb292248..7e56d8ce 100644 --- a/scripts/client/main.js +++ b/scripts/client/main.js @@ -69,8 +69,8 @@ let forceWantedLevel = 0; // Pre-cache all allowed skins let allowedSkins = getAllowedSkins(getGame()); -let businessBlips = {}; -let houseBlips = {}; -let jobBlips = {}; +let businesses = {}; +let houses = {}; +let jobs = {}; // =========================================================================== \ No newline at end of file diff --git a/scripts/client/sync.js b/scripts/client/sync.js index 56802738..2ffe01e3 100644 --- a/scripts/client/sync.js +++ b/scripts/client/sync.js @@ -14,18 +14,6 @@ function processSync(event, deltaTime) { sendNetworkEventToServer("vrr.player.heading", localPlayer.heading); } - //if(game.game == VRR_GAME_GTA_SA) { - // let lookAtPos = getLocalPlayerLookAtPosition(); - // sendNetworkEventToServer("vrr.player.lookat", lookAtPos); - // setEntityData(localPlayer, "vrr.headLook", lookAtPos); - // let peds = getPeds(); - // for(let i in peds) { - // if(doesEntityDataExist(peds[i], "vrr.headLook")) { - // peds[i].lookAt(getEntityData(peds[i], "vrr.headLook"), 99999); - // } - // } - //} - if(localPlayer.health <= 0) { if(!calledDeathEvent) { logToConsole(LOG_DEBUG, `Local player died`); @@ -391,32 +379,7 @@ function syncElementProperties(element) { } } -// =========================================================================== -function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems) { - if(getGame() == VRR_GAME_GTA_IV) { - if(typeof businessBlips[businessId] != "undefined") { - if(blipModel == -1) { - natives.removeBlipAndClearIndex(businessBlips[businessId]); - businessBlips.splice(businessId, 1); - } else { - natives.setBlipCoordinates(businessBlips[businessId], entrancePosition); - natives.changeBlipSprite(businessBlips[businessId], blipModel); - natives.changeBlipNameFromAscii(businessBlips[businessId], `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`); - } - } else { - if(blipModel != -1) { - let blipId = natives.addBlipForCoord(entrancePosition); - if(blipId) { - businessBlips[businessId] = blipId; - natives.changeBlipSprite(blipId, blipModel); - natives.setBlipMarkerLongDistance(blipId, true); - natives.changeBlipNameFromAscii(blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`); - } - } - } - } -} // ===========================================================================