Merge branch 'gtaiv' into nightly

This commit is contained in:
Vortrex
2022-03-09 05:18:24 -06:00
28 changed files with 531 additions and 327 deletions

View File

@@ -8,8 +8,9 @@
// ===========================================================================
class BusinessData {
constructor(index, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems) {
this.index = index;
constructor(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems) {
this.index = -1;
this.businessId = businessId;
this.name = name;
this.entrancePosition = entrancePosition;
this.blipModel = blipModel;
@@ -23,30 +24,92 @@ class BusinessData {
// ===========================================================================
function receiveBusinessFromServer(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems) {
logToConsole(LOG_DEBUG, `[VRR.Business] Received business ${businessId} (${name}) from server`);
if(getGame() == VRR_GAME_GTA_IV) {
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 ...`);
if(blipModel == -1) {
natives.removeBlipAndClearIndex(getBusinessData(businessId).blipId);
businesses.splice(getBusinessData(businessId).index, 1);
if(businessData.blipId != -1) {
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip has been removed by the server`);
natives.removeBlipAndClearIndex(getBusinessData(businessId).blipId);
businessData.blipId = -1;
//businesses.splice(businessData.index, 1);
//setAllBusinessDataIndexes();
} else {
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId}'s blip is unchanged`);
}
} 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) ? " ...": ""}`);
if(businessData.blipId != -1) {
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 {
let blipId = natives.addBlipForCoord(entrancePosition);
if(blipId) {
businessData.blipId = blipId;
natives.changeBlipSprite(businessData.blipId, businessData.blipModel);
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 {
logToConsole(LOG_DEBUG, `[VRR.Business] Business ${businessId} doesn't exist. Adding ...`);
let tempBusinessData = new BusinessData(businessId, name, entrancePosition, blipModel, pickupModel, hasInterior, hasItems);
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);
natives.changeBlipSprite(tempBusinessData.blipId, blipModel);
natives.setBlipMarkerLongDistance(tempBusinessData.blipId, true);
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);
setAllBusinessDataIndexes();
}
}
}
// ===========================================================================
/**
* @param {number} businessId - The ID of the business (initially provided by server)
* @return {BusinessData} The business's data (class instance)
*/
function getBusinessData(businessId) {
//let tempBusinessData = businesses.find((b) => b.businessId == businessId);
//return (typeof tempBusinessData != "undefined") ? tempBusinessData[0] : false;
for(let i in businesses) {
if(businesses[i].businessId == businessId) {
return businesses[i];
}
}
return false;
}
// ===========================================================================
function setAllBusinessDataIndexes() {
for(let i in businesses) {
businesses[i].index = i;
}
}
// ===========================================================================

View File

@@ -145,9 +145,7 @@ function onElementStreamIn(event, element) {
function onLocalPlayerExitedVehicle(event, vehicle, seat) {
logToConsole(LOG_DEBUG, `[VRR.Event] Local player exited vehicle`);
if(areServerElementsSupported()) {
sendNetworkEventToServer("vrr.onPlayerExitVehicle", getVehicleForNetworkEvent(vehicle), seat);
}
sendNetworkEventToServer("vrr.onPlayerExitVehicle", getVehicleForNetworkEvent(vehicle), seat);
if(inVehicleSeat) {
parkedVehiclePosition = false;
@@ -160,17 +158,13 @@ function onLocalPlayerExitedVehicle(event, vehicle, seat) {
function onLocalPlayerEnteredVehicle(event, vehicle, seat) {
logToConsole(LOG_DEBUG, `[VRR.Event] Local player entered vehicle`);
if(areServerElementsSupported()) {
sendNetworkEventToServer("vrr.onPlayerEnterVehicle", getVehicleForNetworkEvent(vehicle), seat);
sendNetworkEventToServer("vrr.onPlayerEnterVehicle", getVehicleForNetworkEvent(vehicle), seat);
if(inVehicleSeat == 0) {
if(inVehicle.owner != -1) {
inVehicle.engine = false;
if(!inVehicle.engine) {
parkedVehiclePosition = inVehicle.position;
parkedVehicleHeading = inVehicle.heading;
}
}
if(inVehicleSeat == 0) {
inVehicle.engine = false;
if(!inVehicle.engine) {
parkedVehiclePosition = inVehicle.position;
parkedVehicleHeading = inVehicle.heading;
}
}
}

82
scripts/client/house.js Normal file
View File

@@ -0,0 +1,82 @@
// ===========================================================================
// 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) {
if(getGame() == VRR_GAME_GTA_IV) {
if(getHouseData(houseId) != false) {
if(blipModel == -1) {
natives.removeBlipAndClearIndex(getHouseData(houseId).blipId);
getHouseData(houseId).blipId = -1;
//houses.splice(getHouseData(houseId).index, 1);
//setAllHouseDataIndexes();
} else {
if(getHouseData(houseId).blipId != -1) {
natives.setBlipCoordinates(getHouseData(houseId).blipId, getHouseData(houseId).entrancePosition);
natives.changeBlipSprite(getHouseData(houseId).blipId, getHouseData(houseId).blipModel);
//natives.changeBlipNameFromAscii(getHouseData(houseId).blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`);
} else {
let blipId = natives.addBlipForCoord(entrancePosition);
if(blipId) {
getHouseData(houseId).blipId = blipId;
natives.changeBlipSprite(blipId, blipModel);
natives.setBlipMarkerLongDistance(blipId, false);
}
}
}
} else {
let tempHouseData = new HouseData(houseId, entrancePosition, blipModel, pickupModel, hasInterior, hasItems);
if(blipModel != -1) {
let blipId = natives.addBlipForCoord(entrancePosition);
if(blipId) {
tempHouseData.blipId = blipId;
natives.changeBlipSprite(blipId, blipModel);
natives.setBlipMarkerLongDistance(blipId, false);
//natives.changeBlipNameFromAscii(blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`);
}
}
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 tempHouseData = houses.find((h) => h.houseId == houseId);
return (typeof tempHouseData != "undefined") ? tempHouseData : false;
}
// ===========================================================================
function setAllHouseDataIndexes() {
for(let i in houses) {
houses[i].index = i;
}
}
// ===========================================================================

View File

@@ -247,17 +247,19 @@ function renderJobLabel(name, position, jobType) {
// -------------------------------------------------------------------------
function processLabelRendering() {
if(renderLabels && areWorldLabelsSupported()) {
if(localPlayer != null) {
if(!areServerElementsSupported()) {
//for(let i in businesses) {
// if(pickups[i].getData("vrr.label.type") != null) {
// if(getDistance(localPlayer.position, pickups[i].position) <= renderLabelDistance) {
// natives.getScreenViewportId
// natives.getGameViewportId
// natives.getViewportPositionOfCoord
} else {
if(renderLabels) {
if(!areServerElementsSupported()) {
if(localPlayer != null) {
for(let i in businesses) {
if(getDistance(localPlayer.position, businesses[i].entrancePosition) <= 75.0) {
natives.drawColouredCylinder(getPosBelowPos(businesses[i].entrancePosition, 1.0), 0.0, 0.0, 0, 153, 255, 255);
}
}
}
}
if(areWorldLabelsSupported()) {
if(localPlayer != null) {
let pickups = getElementsByType(ELEMENT_PICKUP);
for(let i in pickups) {
if(pickups[i].getData("vrr.label.type") != null) {

View File

@@ -69,8 +69,9 @@ let forceWantedLevel = 0;
// Pre-cache all allowed skins
let allowedSkins = getAllowedSkins(getGame());
let businesses = {};
let houses = {};
let jobs = {};
let businesses = [];
let houses = [];
let jobs = [];
let vehicles = [];
// ===========================================================================

View File

@@ -107,6 +107,8 @@ function addAllNetworkHandlers() {
addNetworkEventHandler("vrr.holdObject", makePedHoldObject);
addNetworkEventHandler("vrr.playerPedId", sendLocalPlayerNetworkIdToServer);
addNetworkEventHandler("vrr.ped", setLocalPlayerPedPartsAndProps);
}
// ===========================================================================
@@ -139,6 +141,8 @@ function setPlayer2DRendering(hudState, labelState, smallGameMessageState, score
natives.displayCash(hudState);
natives.displayAmmo(hudState);
natives.displayHud(hudState);
natives.displayRadar(hudState);
natives.displayAreaName(hudState);
} else {
if(typeof setHUDEnabled != "undefined") {
setHUDEnabled(hudState);
@@ -257,18 +261,6 @@ function setElementCollisionsEnabled(elementId, state) {
// ===========================================================================
function setLocalPlayerPedPartsAndProps(parts, props) {
for(let i in parts) {
localPlayer.changeBodyPart(parts[0], parts[1], parts[2]);
}
for(let i in props) {
localPlayer.changeBodyProp(props[0], props[1]);
}
}
// ===========================================================================
function setLocalPlayerArmour(armour) {
if(typeof localPlayer.armour != "undefined") {
localPlayer.armour = armour;
@@ -301,8 +293,9 @@ function setLocalPlayerInfiniteRun(state) {
function setLocalPlayerSkin(skinId) {
if(getGame() == VRR_GAME_GTA_IV) {
//natives.changePlayerModel(natives.getPlayerId(), skinId);
localPlayer.skin = allowedSkins[skinSelectorIndex][0];
natives.changePlayerModel(natives.getPlayerId(), skinId);
//localPlayer.skin = allowedSkins[skinSelectorIndex][0];
//localPlayer.modelIndex = allowedSkins[skinSelectorIndex][0];
} else {
localPlayer.skin = skinId;
}

View File

@@ -55,7 +55,8 @@ function processSkinSelectKeyPress(keyCode) {
skinSelectMessageTextTop = allowedSkins[skinSelectorIndex][1];
if(getGame() == VRR_GAME_GTA_IV) {
//natives.changePlayerModel(natives.getPlayerId(), allowedSkins[skinSelectorIndex][0]);
localPlayer.skin = allowedSkins[skinSelectorIndex][0];
//localPlayer.skin = allowedSkins[skinSelectorIndex][0];
//localPlayer.modelIndex = allowedSkins[skinSelectorIndex][0];
} else {
localPlayer.skin = allowedSkins[skinSelectorIndex][0];
}
@@ -69,7 +70,8 @@ function processSkinSelectKeyPress(keyCode) {
skinSelectMessageTextTop = allowedSkins[skinSelectorIndex][1];
if(getGame() == VRR_GAME_GTA_IV) {
//natives.changePlayerModel(natives.getPlayerId(), allowedSkins[skinSelectorIndex][0]);
localPlayer.skin = allowedSkins[skinSelectorIndex][0];
//localPlayer.skin = allowedSkins[skinSelectorIndex][0];
//localPlayer.modelIndex = allowedSkins[skinSelectorIndex][0];
} else {
localPlayer.skin = allowedSkins[skinSelectorIndex][0];
}

View File

@@ -121,12 +121,12 @@ function setUpInitialGame() {
natives.setPickupsFixCars(false);
// HUD and Display
natives.displayCash(false);
natives.displayAmmo(false);
natives.displayHud(false);
natives.displayRadar(false);
natives.displayAreaName(false);
natives.displayPlayerNames(false);
//natives.displayCash(false);
//natives.displayAmmo(false);
//natives.displayHud(false);
//natives.displayRadar(false);
//natives.displayAreaName(false);
//natives.displayPlayerNames(false);
natives.setPoliceRadarBlips(false);
natives.removeTemporaryRadarBlipsForPickups();
natives.displayNonMinigameHelpMessages(false);
@@ -138,14 +138,14 @@ function setUpInitialGame() {
natives.setPlayersDropMoneyInNetworkGame(false);
// Population
natives.dontSuppressAnyCarModels(5.0);
natives.dontSuppressAnyPedModels(5.0);
natives.forceGenerateParkedCarsTooCloseToOthers(5.0);
natives.setParkedCarDensityMultiplier(5.0);
natives.setRandomCarDensityMultiplier(5.0);
natives.setPedDensityMultiplier(5.0);
natives.setCarDensityMultiplier(5.0);
natives.setScenarioPedDensityMultiplier(5.0, 5.0);
//natives.dontSuppressAnyCarModels(5.0);
//natives.dontSuppressAnyPedModels(5.0);
//natives.forceGenerateParkedCarsTooCloseToOthers(true);
//natives.setParkedCarDensityMultiplier(5.0);
//natives.setRandomCarDensityMultiplier(5.0);
//natives.setPedDensityMultiplier(5.0);
//natives.setCarDensityMultiplier(5.0);
//natives.setScenarioPedDensityMultiplier(5.0, 5.0);
natives.switchRandomTrains(true);
natives.switchRandomBoats(true);
natives.switchAmbientPlanes(true);

View File

@@ -10,8 +10,13 @@
function processSync(event, deltaTime) {
if(localPlayer != null) {
if(!areServerElementsSupported()) {
sendNetworkEventToServer("vrr.player.position", localPlayer.position);
sendNetworkEventToServer("vrr.player.heading", localPlayer.heading);
sendNetworkEventToServer("vrr.plr.pos", localPlayer.position);
sendNetworkEventToServer("vrr.plr.rot", localPlayer.heading);
if(localPlayer.vehicle != null) {
sendNetworkEventToServer("vrr.veh.pos", getVehicleForNetworkEvent(localPlayer.vehicle), localPlayer.vehicle.position);
sendNetworkEventToServer("vrr.veh.rot", getVehicleForNetworkEvent(localPlayer.vehicle), localPlayer.vehicle.heading);
}
}
if(localPlayer.health <= 0) {
@@ -39,12 +44,20 @@ function setVehicleEngine(vehicleId, state) {
// ===========================================================================
function setVehicleLights(vehicleId, state) {
if(getGame() != VRR_GAME_MAFIA_ONE) {
if(!state) {
getElementFromId(vehicleId).lightStatus = 2;
} else {
getElementFromId(vehicleId).lightStatus = 1;
}
} else if(getGame() == VRR_GAME_GTA_IV) {
if(!state) {
natives.forceCarLights(natives.getVehicleFromNetworkId(vehicleId, 0));
} else {
natives.forceCarLights(natives.getVehicleFromNetworkId(vehicleId, 1));
}
} else {
if(!state) {
getElementFromId(vehicleId).lights = false;
@@ -63,6 +76,10 @@ function repairVehicle(syncId) {
// ===========================================================================
function syncVehicleProperties(vehicle) {
if(!areServerElementsSupported()) {
return false;
}
if(doesEntityDataExist(vehicle, "vrr.lights")) {
let lightStatus = getEntityData(vehicle, "vrr.lights");
if(!lightStatus) {
@@ -134,6 +151,10 @@ function syncVehicleProperties(vehicle) {
// ===========================================================================
function syncCivilianProperties(civilian) {
if(!areServerElementsSupported()) {
return false;
}
if(getGame() == VRR_GAME_GTA_III) {
if(doesEntityDataExist(civilian, "vrr.scale")) {
let scaleFactor = getEntityData(civilian, "vrr.scale");
@@ -226,6 +247,10 @@ function syncCivilianProperties(civilian) {
// ===========================================================================
function syncPlayerProperties(player) {
if(!areServerElementsSupported()) {
return false;
}
if(getGame() == VRR_GAME_GTA_III) {
if(doesEntityDataExist(player, "vrr.scale")) {
let scaleFactor = getEntityData(player, "vrr.scale");
@@ -335,6 +360,10 @@ function syncPlayerProperties(player) {
// ===========================================================================
function syncObjectProperties(object) {
if(!areServerElementsSupported()) {
return false;
}
if(getGame() == VRR_GAME_GTA_III || getGame() == VRR_GAME_GTA_VC) {
if(doesEntityDataExist(object, "vrr.scale")) {
let scaleFactor = getEntityData(object, "vrr.scale");
@@ -351,6 +380,10 @@ function syncObjectProperties(object) {
// ===========================================================================
function syncElementProperties(element) {
if(!areServerElementsSupported()) {
return false;
}
if(doesEntityDataExist(element, "vrr.interior")) {
if(typeof element.interior != "undefined") {
element.interior = getEntityData(element, "vrr.interior");
@@ -389,4 +422,16 @@ function receiveHouseFromServer(houseId, entrancePosition, blipModel, pickupMode
}
}
// ===========================================================================
function setLocalPlayerPedPartsAndProps(parts, props) {
for(let i in parts) {
localPlayer.changeBodyPart(parts[i][0], parts[i][1], parts[i][2]);
}
for(let j in props) {
localPlayer.changeBodyProp(props[j][0], props[j][1]);
}
}
// ===========================================================================

View File

@@ -683,9 +683,11 @@ function processLocalPlayerVehicleEntryExitHandling() {
// ===========================================================================
function getVehicleForNetworkEvent(vehicleArg) {
// Soon this will also be used to get the IV vehicle via it's ID
return vehicleArg;
function getVehicleForNetworkEvent(vehicle) {
if(getGame() == VRR_GAME_GTA_IV) {
return natives.getNetworkIdFromVehicle(vehicle);
}
return vehicle;
}
// ===========================================================================