Add del local player ped util

This commit is contained in:
Vortrex
2022-06-14 17:32:24 -05:00
parent d6f767e321
commit 8f02c5c3d8

View File

@@ -37,7 +37,7 @@ function getPlayerPosition() {
// ===========================================================================
function setPlayerPosition(position) {
if(getGame() == VRR_GAME_GTA_IV) {
if (getGame() == VRR_GAME_GTA_IV) {
natives.setCharCoordinates(localPlayer, position);
} else {
localPlayer.position = position;
@@ -59,11 +59,11 @@ function getElementHeading(elementId) {
// ===========================================================================
function setElementPosition(elementId, position) {
if(getElementFromId(elementId) == null) {
if (getElementFromId(elementId) == null) {
return false;
}
if(!getElementFromId(elementId).isSyncer) {
if (!getElementFromId(elementId).isSyncer) {
return false;
}
@@ -73,7 +73,7 @@ function setElementPosition(elementId, position) {
// ===========================================================================
function deleteGameElement(elementId, position) {
if(!getElementFromId(elementId).isOwner) {
if (!getElementFromId(elementId).isOwner) {
return false;
}
@@ -110,8 +110,8 @@ function getElementId(element) {
function getClientFromIndex(index) {
let clients = getClients();
for(let i in clients) {
if(clients[i].index == index) {
for (let i in clients) {
if (clients[i].index == index) {
return clients[i];
}
}
@@ -170,8 +170,8 @@ function is2dPositionOnScreen(pos2d) {
function getVehiclesInRange(position, range) {
let vehicles = getElementsByType(ELEMENT_VEHICLE);
let inRangeVehicles = [];
for(let i in vehicles) {
if(getDistance(position, vehicles[i].position) <= range) {
for (let i in vehicles) {
if (getDistance(position, vehicles[i].position) <= range) {
inRangeVehicles.push(vehicles[i]);
}
}
@@ -181,13 +181,13 @@ function getVehiclesInRange(position, range) {
// ===========================================================================
function createGameBlip(blipModel, position, name = "") {
if(getGame() == VRR_GAME_GTA_IV) {
if (getGame() == VRR_GAME_GTA_IV) {
let blipId = natives.addBlipForCoord(position);
if(blipId) {
if (blipId) {
natives.changeBlipSprite(blipId, blipModel);
natives.setBlipMarkerLongDistance(blipId, false);
natives.setBlipAsShortRange(blipId, true);
natives.changeBlipNameFromAscii(blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ...": ""}`);
natives.changeBlipNameFromAscii(blipId, `${name.substr(0, 24)}${(name.length > 24) ? " ..." : ""}`);
return blipId;
}
}
@@ -198,7 +198,7 @@ function createGameBlip(blipModel, position, name = "") {
// ===========================================================================
function setEntityData(entity, dataName, dataValue, syncToClients = true) {
if(entity != null) {
if (entity != null) {
return entity.setData(dataName, dataValue);
}
}
@@ -224,64 +224,64 @@ function repairVehicle(syncId) {
// ===========================================================================
function syncVehicleProperties(vehicle) {
if(doesEntityDataExist(vehicle, "vrr.lights")) {
if (doesEntityDataExist(vehicle, "vrr.lights")) {
let lightStatus = getEntityData(vehicle, "vrr.lights");
vehicle.lights = lightStatus;
}
if(doesEntityDataExist(vehicle, "vrr.invincible")) {
if (doesEntityDataExist(vehicle, "vrr.invincible")) {
let invincible = getEntityData(vehicle, "vrr.invincible");
element.setProofs(invincible, invincible, invincible, invincible, invincible);
}
if(doesEntityDataExist(vehicle, "vrr.panelStatus")) {
if (doesEntityDataExist(vehicle, "vrr.panelStatus")) {
let panelsStatus = getEntityData(vehicle, "vrr.panelStatus");
for(let i in panelsStatus) {
for (let i in panelsStatus) {
vehicle.setPanelStatus(i, panelsStatus[i]);
}
}
if(doesEntityDataExist(vehicle, "vrr.wheelStatus")) {
if (doesEntityDataExist(vehicle, "vrr.wheelStatus")) {
let wheelsStatus = getEntityData(vehicle, "vrr.wheelStatus");
for(let i in wheelsStatus) {
for (let i in wheelsStatus) {
vehicle.setWheelStatus(i, wheelsStatus[i]);
}
}
if(doesEntityDataExist(vehicle, "vrr.lightStatus")) {
if (doesEntityDataExist(vehicle, "vrr.lightStatus")) {
let lightStatus = getEntityData(vehicle, "vrr.lightStatus");
for(let i in lightStatus) {
for (let i in lightStatus) {
vehicle.setLightStatus(i, lightStatus[i]);
}
}
if(doesEntityDataExist(vehicle, "vrr.suspensionHeight")) {
if (doesEntityDataExist(vehicle, "vrr.suspensionHeight")) {
let suspensionHeight = getEntityData(vehicle, "vrr.suspensionHeight");
vehicle.setSuspensionHeight(suspensionHeight);
}
if(getGame() == VRR_GAME_GTA_SA) {
if (getGame() == VRR_GAME_GTA_SA) {
let allUpgrades = getGameConfig().vehicleUpgrades[getGame()];
for(let i in allUpgrades) {
for (let i in allUpgrades) {
vehicle.removeUpgrade(i);
}
if(doesEntityDataExist(vehicle, "vrr.upgrades")) {
if (doesEntityDataExist(vehicle, "vrr.upgrades")) {
let upgrades = getEntityData(vehicle, "vrr.upgrades");
for(let i in upgrades) {
if(upgrades[i] != 0) {
for (let i in upgrades) {
if (upgrades[i] != 0) {
vehicle.addUpgrade(upgrades[i]);
}
}
}
}
if(getGame() == VRR_GAME_GTA_SA || getGame() == VRR_GAME_GTA_IV) {
if(doesEntityDataExist(vehicle, "vrr.livery")) {
if (getGame() == VRR_GAME_GTA_SA || getGame() == VRR_GAME_GTA_IV) {
if (doesEntityDataExist(vehicle, "vrr.livery")) {
let livery = getEntityData(vehicle, "vrr.livery");
if(getGame() == VRR_GAME_GTA_SA) {
if (getGame() == VRR_GAME_GTA_SA) {
vehicle.setPaintJob(livery);
} else if(getGame() == VRR_GAME_GTA_IV) {
} else if (getGame() == VRR_GAME_GTA_IV) {
vehicle.livery = livery;
}
}
@@ -291,7 +291,7 @@ function syncVehicleProperties(vehicle) {
// ===========================================================================
function removeEntityData(entity, dataName) {
if(entity != null) {
if (entity != null) {
return entity.removeData(dataName);
}
return null;
@@ -300,7 +300,7 @@ function removeEntityData(entity, dataName) {
// ===========================================================================
function doesEntityDataExist(entity, dataName) {
if(entity != null) {
if (entity != null) {
return (entity.getData(dataName) != null);
}
return null;
@@ -309,8 +309,8 @@ function doesEntityDataExist(entity, dataName) {
// ===========================================================================
function syncCivilianProperties(civilian) {
if(getGame() == VRR_GAME_GTA_III) {
if(doesEntityDataExist(civilian, "vrr.scale")) {
if (getGame() == VRR_GAME_GTA_III) {
if (doesEntityDataExist(civilian, "vrr.scale")) {
let scaleFactor = getEntityData(civilian, "vrr.scale");
let tempMatrix = civilian.matrix;
tempMatrix.setScale(toVector3(scaleFactor.x, scaleFactor.y, scaleFactor.z));
@@ -321,78 +321,78 @@ function syncCivilianProperties(civilian) {
}
}
if(getGame() == VRR_GAME_GTA_SA) {
if(doesEntityDataExist(civilian, "vrr.fightStyle")) {
if (getGame() == VRR_GAME_GTA_SA) {
if (doesEntityDataExist(civilian, "vrr.fightStyle")) {
let fightStyle = getEntityData(civilian, "vrr.fightStyle");
civilian.setFightStyle(fightStyle[0], fightStyle[1]);
}
}
if(getGame() == VRR_GAME_GTA_III) {
if(doesEntityDataExist(civilian, "vrr.walkStyle")) {
if (getGame() == VRR_GAME_GTA_III) {
if (doesEntityDataExist(civilian, "vrr.walkStyle")) {
let walkStyle = getEntityData(civilian, "vrr.walkStyle");
civilian.walkStyle = walkStyle;
}
}
if(getGame() == VRR_GAME_GTA_IV) {
if(doesEntityDataExist(civilian, "vrr.bodyPropHair")) {
if (getGame() == VRR_GAME_GTA_IV) {
if (doesEntityDataExist(civilian, "vrr.bodyPropHair")) {
let bodyPropHair = getEntityData(civilian, "vrr.bodyPropHair");
civilian.changeBodyProp(0, bodyPropHair[0], bodyPropHair[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropHead")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropHead")) {
let bodyPropHead = getEntityData(civilian, "vrr.bodyPropHead");
civilian.changeBodyProp(1, bodyPropHead[0], bodyPropHead[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropEyes")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropEyes")) {
let bodyPropEyes = getEntityData(civilian, "vrr.bodyPropEyes");
civilian.changeBodyProp(1, bodyPropEyes[0], bodyPropEyes[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropLeftHand")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropLeftHand")) {
let bodyPropLeftHand = getEntityData(civilian, "vrr.bodyPropLeftHand");
civilian.changeBodyProp(1, bodyPropLeftHand[0], bodyPropLeftHand[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropRightHand")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropRightHand")) {
let bodyPropRightHand = getEntityData(civilian, "vrr.bodyPropRightHand");
civilian.changeBodyProp(1, bodyPropRightHand[0], bodyPropRightHand[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropLeftWrist")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropLeftWrist")) {
let bodyPropLeftWrist = getEntityData(civilian, "vrr.bodyPropLeftWrist");
civilian.changeBodyProp(1, bodyPropLeftWrist[0], bodyPropLeftWrist[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropRightWrist")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropRightWrist")) {
let bodyPropRightWrist = getEntityData(civilian, "vrr.bodyPropRightWrist");
civilian.changeBodyProp(1, bodyPropRightWrist[0], bodyPropRightWrist[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropRightWrist")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropRightWrist")) {
let bodyPropRightWrist = getEntityData(civilian, "vrr.bodyPropRightWrist");
civilian.changeBodyProp(1, bodyPropRightWrist[0], bodyPropRightWrist[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropHip")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropHip")) {
let bodyPropHip = getEntityData(civilian, "vrr.bodyPropHip");
civilian.changeBodyProp(1, bodyPropHip[0], bodyPropHip[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropLeftFoot")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropLeftFoot")) {
let bodyPropLeftFoot = getEntityData(civilian, "vrr.bodyPropLeftFoot");
civilian.changeBodyProp(1, bodyPropLeftFoot[0], bodyPropLeftFoot[1]);
}
if(doesEntityDataExist(civilian, "vrr.bodyPropRightFoot")) {
if (doesEntityDataExist(civilian, "vrr.bodyPropRightFoot")) {
let bodyPropRightFoot = getEntityData(civilian, "vrr.bodyPropRightFoot");
civilian.changeBodyProp(1, bodyPropRightFoot[0], bodyPropRightFoot[1]);
}
}
if(doesEntityDataExist(civilian, "vrr.anim")) {
if (doesEntityDataExist(civilian, "vrr.anim")) {
let animData = getEntityData(vehicle, "vrr.anim");
civilian.addAnimation(animData[0], animData[1]);
}
@@ -407,8 +407,8 @@ function preventDefaultEventAction(event) {
// ===========================================================================
function syncPlayerProperties(player) {
if(getGame() == VRR_GAME_GTA_III) {
if(doesEntityDataExist(player, "vrr.scale")) {
if (getGame() == VRR_GAME_GTA_III) {
if (doesEntityDataExist(player, "vrr.scale")) {
let scaleFactor = getEntityData(player, "vrr.scale");
let tempMatrix = player.matrix;
tempMatrix.setScale(toVector3(scaleFactor.x, scaleFactor.y, scaleFactor.z));
@@ -419,8 +419,8 @@ function syncPlayerProperties(player) {
}
}
if(getGame() == VRR_GAME_GTA_SA) {
if(doesEntityDataExist(player, "vrr.fightStyle")) {
if (getGame() == VRR_GAME_GTA_SA) {
if (doesEntityDataExist(player, "vrr.fightStyle")) {
let fightStyle = getEntityData(player, "vrr.fightStyle");
player.setFightStyle(fightStyle[0], fightStyle[1]);
}
@@ -433,80 +433,80 @@ function syncPlayerProperties(player) {
// }
//}
if(getGame() == VRR_GAME_GTA_IV) {
if(doesEntityDataExist(player, "vrr.bodyPartHair")) {
if (getGame() == VRR_GAME_GTA_IV) {
if (doesEntityDataExist(player, "vrr.bodyPartHair")) {
let bodyPartHead = getEntityData(player, "vrr.bodyPartHair");
player.changeBodyPart(0, bodyPartHead[0], bodyPartHair[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPartHead")) {
if (doesEntityDataExist(player, "vrr.bodyPartHead")) {
let bodyPartHead = getEntityData(player, "vrr.bodyPartHead");
player.changeBodyPart(1, bodyPartHead[0], bodyPartHead[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPartUpper")) {
if (doesEntityDataExist(player, "vrr.bodyPartUpper")) {
let bodyPartUpper = getEntityData(player, "vrr.bodyPartUpper");
player.changeBodyPart(1, bodyPartUpper[0], bodyPartUpper[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPartLower")) {
if (doesEntityDataExist(player, "vrr.bodyPartLower")) {
let bodyPartLower = getEntityData(player, "vrr.bodyPartLower");
player.changeBodyPart(1, bodyPartLower[0], bodyPartLower[1]);
}
}
if(getGame() == VRR_GAME_GTA_IV) {
if(doesEntityDataExist(player, "vrr.bodyPropHair")) {
if (getGame() == VRR_GAME_GTA_IV) {
if (doesEntityDataExist(player, "vrr.bodyPropHair")) {
let bodyPropHair = getEntityData(player, "vrr.bodyPropHair");
player.changeBodyProp(0, bodyPropHair[0], bodyPropHair[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropHead")) {
if (doesEntityDataExist(player, "vrr.bodyPropHead")) {
let bodyPropHead = getEntityData(player, "vrr.bodyPropHead");
player.changeBodyProp(1, bodyPropHead[0], bodyPropHead[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropEyes")) {
if (doesEntityDataExist(player, "vrr.bodyPropEyes")) {
let bodyPropEyes = getEntityData(player, "vrr.bodyPropEyes");
player.changeBodyProp(1, bodyPropEyes[0], bodyPropEyes[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropLeftHand")) {
if (doesEntityDataExist(player, "vrr.bodyPropLeftHand")) {
let bodyPropLeftHand = getEntityData(player, "vrr.bodyPropLeftHand");
player.changeBodyProp(1, bodyPropLeftHand[0], bodyPropLeftHand[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropRightHand")) {
if (doesEntityDataExist(player, "vrr.bodyPropRightHand")) {
let bodyPropRightHand = getEntityData(player, "vrr.bodyPropRightHand");
player.changeBodyProp(1, bodyPropRightHand[0], bodyPropRightHand[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropLeftWrist")) {
if (doesEntityDataExist(player, "vrr.bodyPropLeftWrist")) {
let bodyPropLeftWrist = getEntityData(player, "vrr.bodyPropLeftWrist");
player.changeBodyProp(1, bodyPropLeftWrist[0], bodyPropLeftWrist[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropRightWrist")) {
if (doesEntityDataExist(player, "vrr.bodyPropRightWrist")) {
let bodyPropRightWrist = getEntityData(player, "vrr.bodyPropRightWrist");
player.changeBodyProp(1, bodyPropRightWrist[0], bodyPropRightWrist[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropRightWrist")) {
if (doesEntityDataExist(player, "vrr.bodyPropRightWrist")) {
let bodyPropRightWrist = getEntityData(player, "vrr.bodyPropRightWrist");
player.changeBodyProp(1, bodyPropRightWrist[0], bodyPropRightWrist[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropHip")) {
if (doesEntityDataExist(player, "vrr.bodyPropHip")) {
let bodyPropHip = getEntityData(player, "vrr.bodyPropHip");
player.changeBodyProp(1, bodyPropHip[0], bodyPropHip[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropLeftFoot")) {
if (doesEntityDataExist(player, "vrr.bodyPropLeftFoot")) {
let bodyPropLeftFoot = getEntityData(player, "vrr.bodyPropLeftFoot");
player.changeBodyProp(1, bodyPropLeftFoot[0], bodyPropLeftFoot[1]);
}
if(doesEntityDataExist(player, "vrr.bodyPropRightFoot")) {
if (doesEntityDataExist(player, "vrr.bodyPropRightFoot")) {
let bodyPropRightFoot = getEntityData(player, "vrr.bodyPropRightFoot");
player.changeBodyProp(1, bodyPropRightFoot[0], bodyPropRightFoot[1]);
}
@@ -516,8 +516,8 @@ function syncPlayerProperties(player) {
// ===========================================================================
function syncObjectProperties(object) {
if(getGame() == VRR_GAME_GTA_III || getGame() == VRR_GAME_GTA_VC) {
if(doesEntityDataExist(object, "vrr.scale")) {
if (getGame() == VRR_GAME_GTA_III || getGame() == VRR_GAME_GTA_VC) {
if (doesEntityDataExist(object, "vrr.scale")) {
let scaleFactor = getEntityData(object, "vrr.scale");
let tempMatrix = object.matrix;
tempMatrix.setScale(toVector3(scaleFactor.x, scaleFactor.y, scaleFactor.z));
@@ -568,13 +568,13 @@ function getPlayerId(client) {
// ===========================================================================
function syncElementProperties(element) {
if(doesEntityDataExist(element, "vrr.interior")) {
if(typeof element.interior != "undefined") {
if (doesEntityDataExist(element, "vrr.interior")) {
if (typeof element.interior != "undefined") {
element.interior = getEntityData(element, "vrr.interior");
}
}
switch(element.type) {
switch (element.type) {
case ELEMENT_VEHICLE:
syncVehicleProperties(element);
break;
@@ -619,23 +619,23 @@ function getScreenHeight() {
// ===========================================================================
function openAllGarages() {
switch(getGame()) {
switch (getGame()) {
case VRR_GAME_GTA_III:
for(let i=0;i<=26;i++) {
for (let i = 0; i <= 26; i++) {
openGarage(i);
game.NO_SPECIAL_CAMERA_FOR_THIS_GARAGE(i);
}
break;
case VRR_GAME_GTA_VC:
for(let i=0;i<=32;i++) {
for (let i = 0; i <= 32; i++) {
openGarage(i);
game.NO_SPECIAL_CAMERA_FOR_THIS_GARAGE(i);
}
break;
case VRR_GAME_GTA_SA:
for(let i=0;i<=44;i++) {
for (let i = 0; i <= 44; i++) {
openGarage(i);
}
break;
@@ -648,23 +648,23 @@ function openAllGarages() {
// ===========================================================================
function closeAllGarages() {
switch(getGame()) {
switch (getGame()) {
case VRR_GAME_GTA_III:
for(let i=0;i<=26;i++) {
for (let i = 0; i <= 26; i++) {
closeGarage(i);
game.NO_SPECIAL_CAMERA_FOR_THIS_GARAGE(i);
}
break;
case VRR_GAME_GTA_VC:
for(let i=0;i<=32;i++) {
for (let i = 0; i <= 32; i++) {
closeGarage(i);
game.NO_SPECIAL_CAMERA_FOR_THIS_GARAGE(i);
}
break;
case VRR_GAME_GTA_SA:
for(let i=0;i<=44;i++) {
for (let i = 0; i <= 44; i++) {
closeGarage(i);
}
break;
@@ -683,7 +683,7 @@ function setPedInvincible(ped, state) {
// ===========================================================================
function setPedLookAt(ped, position) {
if(getGame() == VRR_GAME_GTA_SA) {
if (getGame() == VRR_GAME_GTA_SA) {
ped.lookAt(position, 10000);
return true;
} else {
@@ -697,4 +697,10 @@ function setElementHeading(elementId, heading) {
getElementFromId(elementId).heading = heading;
}
// ===========================================================================
function deleteLocalPlayerPed() {
destroyElement(localPlayer);
}
// ===========================================================================