Check some props before using
This commit is contained in:
@@ -121,7 +121,10 @@ function sendResourceStoppedSignalToServer() {
|
||||
function setPlayer2DRendering(hudState, labelState, smallGameMessageState, scoreboardState, hotBarState, itemActionDelayState) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Main] Updating render states (HUD: ${hudState}, Labels: ${labelState}, Bottom Text: ${smallGameMessageState}, Scoreboard: ${scoreboardState}, HotBar: ${hotBarState}, Item Action Delay: ${itemActionDelayState})`);
|
||||
renderHUD = hudState;
|
||||
setHUDEnabled(hudState);
|
||||
|
||||
if(typeof setHUDEnabled != "undefined") {
|
||||
setHUDEnabled(hudState);
|
||||
}
|
||||
|
||||
renderLabels = labelState;
|
||||
renderSmallGameMessage = smallGameMessageState;
|
||||
@@ -272,7 +275,9 @@ function setLocalPlayerPedPartsAndProps(parts, props) {
|
||||
// ===========================================================================
|
||||
|
||||
function setLocalPlayerArmour(armour) {
|
||||
localPlayer.armour = armour;
|
||||
if(typeof localPlayer.armour != "undefined") {
|
||||
localPlayer.armour = armour;
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -358,7 +358,9 @@ function syncObjectProperties(object) {
|
||||
|
||||
function syncElementProperties(element) {
|
||||
if(doesEntityDataExist(element, "vrr.interior")) {
|
||||
element.interior = getEntityData(element, "vrr.interior");
|
||||
if(typeof element.interior != "undefined") {
|
||||
element.interior = getEntityData(element, "vrr.interior");
|
||||
}
|
||||
}
|
||||
|
||||
switch(element.type) {
|
||||
|
||||
@@ -292,9 +292,15 @@ function giveLocalPlayerWeapon(weaponId, ammo, active) {
|
||||
|
||||
function giveLocalPlayerWeapon(weaponId, ammo, active) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Utilities] Giving weapon ${weaponId} with ${ammo} ammo`);
|
||||
localPlayer.giveWeapon(weaponId, ammo, active);
|
||||
forceWeaponAmmo = localPlayer.getWeaponAmmunition(getWeaponSlot(weaponId));
|
||||
forceWeaponClipAmmo = localPlayer.getWeaponClipAmmunition(getWeaponSlot(weaponId));
|
||||
if(getGame() == VRR_GAME_MAFIA_ONE) {
|
||||
localPlayer.giveWeapon(weaponId, 0, ammo);
|
||||
forceWeaponAmmo = 0;
|
||||
forceWeaponClipAmmo = ammo;
|
||||
} else {
|
||||
localPlayer.giveWeapon(weaponId, ammo, active);
|
||||
forceWeaponAmmo = localPlayer.getWeaponAmmunition(getWeaponSlot(weaponId));
|
||||
forceWeaponClipAmmo = localPlayer.getWeaponClipAmmunition(getWeaponSlot(weaponId));
|
||||
}
|
||||
forceWeapon = weaponId;
|
||||
}
|
||||
|
||||
@@ -318,15 +324,22 @@ function getClosestVehicle(pos) {
|
||||
|
||||
function setLocalPlayerPosition(position) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Utilities] Setting position to ${position.x}, ${position.y}, ${position.z}`);
|
||||
localPlayer.velocity = toVector3(0.0, 0.0, 0.0);
|
||||
localPlayer.position = position;
|
||||
if(typeof localPlayer.velocity != "undefined") {
|
||||
localPlayer.velocity = toVector3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if(typeof localPlayer.position != "undefined") {
|
||||
localPlayer.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setLocalPlayerHeading(heading) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Utilities] Setting heading to ${heading}`);
|
||||
localPlayer.heading = heading;
|
||||
if(typeof localPlayer.heading != "undefined") {
|
||||
localPlayer.heading = heading;
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -484,13 +497,15 @@ function setPlayerWeaponDamageEnabled(clientName, state) {
|
||||
|
||||
function setLocalPlayerCash(amount) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Utilities] Setting local player money`);
|
||||
localPlayer.money = toInteger(amount);
|
||||
if(typeof localPlayer.money != "undefined") {
|
||||
localPlayer.money = toInteger(amount);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function destroyAutoCreatedPickups() {
|
||||
if(arePickupsSupported()) {
|
||||
if(typeof ELEMENT_PICKUP != "undefined") {
|
||||
getElementsByType(ELEMENT_PICKUP).forEach(function(pickup) {
|
||||
if(pickup.isOwner) {
|
||||
destroyElement(pickup);
|
||||
@@ -526,7 +541,9 @@ function processWantedLevelReset() {
|
||||
return false;
|
||||
}
|
||||
|
||||
localPlayer.wantedLevel = 0;
|
||||
if(typeof localPlayer.wantedLevel != "undefined") {
|
||||
localPlayer.wantedLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -537,8 +554,11 @@ function processLocalPlayerVehicleControlState() {
|
||||
if(areServerElementsSupported()) {
|
||||
if(inVehicle && localPlayer.vehicle != null) {
|
||||
if(!localPlayer.vehicle.engine) {
|
||||
localPlayer.vehicle.velocity = toVector3(0.0, 0.0, 0.0);
|
||||
localPlayer.vehicle.turnVelocity = toVector3(0.0, 0.0, 0.0);
|
||||
if(typeof localPlayer.vehicle.velocity != "undefined") {
|
||||
localPlayer.vehicle.velocity = toVector3(0.0, 0.0, 0.0);
|
||||
localPlayer.vehicle.turnVelocity = toVector3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if(parkedVehiclePosition) {
|
||||
localPlayer.vehicle.position = parkedVehiclePosition;
|
||||
localPlayer.vehicle.heading = parkedVehicleHeading;
|
||||
@@ -591,18 +611,20 @@ function processJobRouteSphere() {
|
||||
// ===========================================================================
|
||||
|
||||
function forceLocalPlayerEquippedWeaponItem() {
|
||||
if(forceWeapon != 0) {
|
||||
if(localPlayer.weapon != forceWeapon) {
|
||||
localPlayer.weapon = forceWeapon;
|
||||
localPlayer.setWeaponClipAmmunition(getWeaponSlot(forceWeapon), forceWeaponClipAmmo);
|
||||
localPlayer.setWeaponAmmunition(getWeaponSlot(forceWeapon), forceWeaponAmmo);
|
||||
if(typeof localPlayer.weapon != "undefined") {
|
||||
if(forceWeapon != 0) {
|
||||
if(localPlayer.weapon != forceWeapon) {
|
||||
localPlayer.weapon = forceWeapon;
|
||||
localPlayer.setWeaponClipAmmunition(getWeaponSlot(forceWeapon), forceWeaponClipAmmo);
|
||||
localPlayer.setWeaponAmmunition(getWeaponSlot(forceWeapon), forceWeaponAmmo);
|
||||
} else {
|
||||
forceWeaponClipAmmo = localPlayer.getWeaponClipAmmunition(getWeaponSlot(forceWeapon));
|
||||
forceWeaponAmmo = localPlayer.getWeaponAmmunition(getWeaponSlot(forceWeapon));
|
||||
}
|
||||
} else {
|
||||
forceWeaponClipAmmo = localPlayer.getWeaponClipAmmunition(getWeaponSlot(forceWeapon));
|
||||
forceWeaponAmmo = localPlayer.getWeaponAmmunition(getWeaponSlot(forceWeapon));
|
||||
}
|
||||
} else {
|
||||
if(localPlayer.weapon > 0) {
|
||||
localPlayer.clearWeapons();
|
||||
if(localPlayer.weapon > 0) {
|
||||
localPlayer.clearWeapons();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -702,15 +724,17 @@ function getPlayerFromParams(params) {
|
||||
// ===========================================================================
|
||||
|
||||
function processNearbyPickups() {
|
||||
let pickups = getElementsByType(ELEMENT_PICKUP);
|
||||
for(let i in pickups) {
|
||||
if(getDistance(pickups[i].position, localPlayer.position) < 5) {
|
||||
//if(pickups[i].interior == localPlayer.interior && pickups[i].dimension == localPlayer.dimension) {
|
||||
if(currentPickup != pickups[i]) {
|
||||
currentPickup = pickups[i];
|
||||
triggerNetworkEvent("vrr.pickup", pickups[i].id);
|
||||
}
|
||||
//}
|
||||
if(typeof ELEMENT_PICKUP != "undefined") {
|
||||
let pickups = getElementsByType(ELEMENT_PICKUP);
|
||||
for(let i in pickups) {
|
||||
if(getDistance(pickups[i].position, localPlayer.position) < 5) {
|
||||
//if(pickups[i].interior == localPlayer.interior && pickups[i].dimension == localPlayer.dimension) {
|
||||
if(currentPickup != pickups[i]) {
|
||||
currentPickup = pickups[i];
|
||||
triggerNetworkEvent("vrr.pickup", pickups[i].id);
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,13 @@ function getPlayerVehicle(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerDimension(client) {
|
||||
return client.player.dimension;
|
||||
if(!areServerElementsSupported()) {
|
||||
return getPlayerData(client).syncDimension;
|
||||
} else {
|
||||
if(client.player != null) {
|
||||
return client.player.dimension;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -74,7 +80,13 @@ function getPlayerInterior(client) {
|
||||
|
||||
function setPlayerDimension(client, dimension) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s dimension to ${dimension}`);
|
||||
client.player.dimension = dimension;
|
||||
if(!areServerElementsSupported()) {
|
||||
getPlayerData(client).syncDimension = dimension;
|
||||
} else {
|
||||
if(client.player != null) {
|
||||
client.player.dimension = dimension;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -288,25 +300,37 @@ function getPlayerWeaponAmmo(client) {
|
||||
|
||||
function setPlayerVelocity(client, velocity) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s velocity to ${velocity.x}, ${velocity.y}, ${velocity.z}`);
|
||||
client.player.velocity = velocity;
|
||||
if(typeof client.player.velocity != "undefined") {
|
||||
client.player.velocity = velocity;
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerVelocity(client, velocity) {
|
||||
return client.player.velocity;
|
||||
if(typeof client.player.velocity != "undefined") {
|
||||
return client.player.velocity;
|
||||
}
|
||||
return toVector3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getElementDimension(element) {
|
||||
return element.dimension;
|
||||
if(typeof element.dimension != "undefined") {
|
||||
return element.dimension;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setElementDimension(element, dimension) {
|
||||
return element.dimension = dimension;
|
||||
if(typeof element.dimension != "undefined") {
|
||||
element.dimension = dimension;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -603,7 +627,20 @@ function isTaxiVehicle(vehicle) {
|
||||
// ===========================================================================
|
||||
|
||||
function getVehicleName(vehicle) {
|
||||
return getVehicleNameFromModel(vehicle.modelIndex) || "Unknown";
|
||||
let model = getElementModel(vehicle);
|
||||
return getVehicleNameFromModel(model) || "Unknown";
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getElementModel(element) {
|
||||
if(typeof element.modelIndex != "undefined") {
|
||||
return element.modelIndex;
|
||||
}
|
||||
|
||||
if(typeof element.model != "undefined") {
|
||||
return element.model;
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
Reference in New Issue
Block a user