Fix updating business blips for IV
This commit is contained in:
@@ -25,44 +25,60 @@ class BusinessData {
|
|||||||
|
|
||||||
function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems) {
|
function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems) {
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Business] Received business ${businessId} (${name}) from server`);
|
logToConsole(LOG_DEBUG, `[VRR.Business] Received business ${businessId} (${name}) from server`);
|
||||||
|
|
||||||
if(getGame() == VRR_GAME_GTA_IV) {
|
if(getGame() == VRR_GAME_GTA_IV) {
|
||||||
if(getBusinessData(businessId) != false) {
|
if(getBusinessData(businessId) != false) {
|
||||||
|
let businessData = getBusinessData(businessId);
|
||||||
|
businessData.name = name;
|
||||||
|
businessData.entrancePosition = entrancePosition;
|
||||||
|
businessData.blipModel = blipModel;
|
||||||
|
businessData.pickupModel = pickupModel;
|
||||||
|
businessData.hasInterior = hasInterior;
|
||||||
|
businessData.hasItems = hasItems;
|
||||||
|
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId} already exists. Checking blip ...`);
|
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId} already exists. Checking blip ...`);
|
||||||
if(blipModel == -1) {
|
if(blipModel == -1) {
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been removed by the server`);
|
if(businessData.blipId != -1) {
|
||||||
natives.removeBlipAndClearIndex(getBusinessData(businessId).blipId);
|
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been removed by the server`);
|
||||||
getBusinessData(businessId).blipId = -1;
|
natives.removeBlipAndClearIndex(getBusinessData(businessId).blipId);
|
||||||
//businesses.splice(getBusinessData(businessId).index, 1);
|
businessData.blipId = -1;
|
||||||
//setAllBusinessDataIndexes();
|
//businesses.splice(businessData.index, 1);
|
||||||
} else {
|
//setAllBusinessDataIndexes();
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been changed by the server`);
|
} else {
|
||||||
if(getBusinessData(businessId).blipId != -1) {
|
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip is unchanged`);
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been modified by the server`);
|
}
|
||||||
natives.setBlipCoordinates(getBusinessData(businessId).blipId, getBusinessData(businessId).entrancePosition);
|
} else {
|
||||||
natives.changeBlipSprite(getBusinessData(businessId).blipId, getBusinessData(businessId).blipModel);
|
if(businessData.blipId != -1) {
|
||||||
natives.changeBlipNameFromAscii(getBusinessData(businessId).blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`);
|
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been changed by the server`);
|
||||||
|
natives.setBlipCoordinates(businessData.blipId, businessData.entrancePosition);
|
||||||
|
natives.changeBlipSprite(businessData.blipId, businessData.blipModel);
|
||||||
|
natives.setBlipMarkerLongDistance(businessData.blipId, true);
|
||||||
|
natives.changeBlipNameFromAscii(businessData.blipId, `${businessData.name.substr(0, 24)}${(businessData.name.length > 24) ? " ...": ""}`);
|
||||||
} else {
|
} else {
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been added by the server`);
|
|
||||||
let blipId = natives.addBlipForCoord(entrancePosition);
|
let blipId = natives.addBlipForCoord(entrancePosition);
|
||||||
if(blipId) {
|
if(blipId) {
|
||||||
getBusinessData(businessId).blipId = blipId;
|
businessData.blipId = blipId;
|
||||||
natives.changeBlipSprite(blipId, blipModel);
|
natives.changeBlipSprite(businessData.blipId, businessData.blipModel);
|
||||||
natives.setBlipMarkerLongDistance(blipId, false);
|
natives.setBlipMarkerLongDistance(businessData.blipId, true);
|
||||||
|
natives.changeBlipNameFromAscii(businessData.blipId, `${businessData.name.substr(0, 24)}${(businessData.name.length > 24) ? " ...": ""}`);
|
||||||
}
|
}
|
||||||
|
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been added by the server (Model ${blipModel}, ID ${blipId})`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId} doesn't exist. Adding ...`);
|
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId} doesn't exist. Adding ...`);
|
||||||
let tempBusinessData = new BusinessData(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems);
|
let tempBusinessData = new BusinessData(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems);
|
||||||
if(blipModel != -1) {
|
if(blipModel != -1) {
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been added by the server`);
|
|
||||||
let blipId = natives.addBlipForCoord(entrancePosition);
|
let blipId = natives.addBlipForCoord(entrancePosition);
|
||||||
if(blipId) {
|
if(blipId) {
|
||||||
tempBusinessData.blipId = blipId;
|
tempBusinessData.blipId = blipId;
|
||||||
natives.changeBlipSprite(blipId, blipModel);
|
natives.changeBlipSprite(tempBusinessData.blipId, blipModel);
|
||||||
natives.setBlipMarkerLongDistance(blipId, false);
|
natives.setBlipMarkerLongDistance(tempBusinessData.blipId, true);
|
||||||
natives.changeBlipNameFromAscii(blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`);
|
natives.changeBlipNameFromAscii(tempBusinessData.blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`);
|
||||||
}
|
}
|
||||||
|
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been added by the server (Model ${blipModel}, ID ${blipId})`);
|
||||||
|
} else {
|
||||||
|
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId} has no blip.`);
|
||||||
}
|
}
|
||||||
businesses.push(tempBusinessData);
|
businesses.push(tempBusinessData);
|
||||||
setAllBusinessDataIndexes();
|
setAllBusinessDataIndexes();
|
||||||
@@ -77,8 +93,15 @@ function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel
|
|||||||
* @return {BusinessData} The business's data (class instance)
|
* @return {BusinessData} The business's data (class instance)
|
||||||
*/
|
*/
|
||||||
function getBusinessData(businessId) {
|
function getBusinessData(businessId) {
|
||||||
let tempBusinessData = businesses.find((b) => b.businessId == businessId);
|
//let tempBusinessData = businesses.find((b) => b.businessId == businessId);
|
||||||
return (typeof tempBusinessData != "undefined") ? tempBusinessData : false;
|
//return (typeof tempBusinessData != "undefined") ? tempBusinessData[0] : false;
|
||||||
|
for(let i in businesses) {
|
||||||
|
if(businesses[i].businessId == businessId) {
|
||||||
|
return businesses[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user