Add natives + fix add ped native

This commit is contained in:
Vortrex
2022-05-22 13:30:00 -05:00
parent 355e57ab34
commit 6634f3b72c
2 changed files with 35 additions and 7 deletions

View File

@@ -155,6 +155,12 @@ function getClosestCivilian(position) {
// =========================================================================== // ===========================================================================
function getClosestPlayer(position) {
return getElementsByType(ELEMENT_PLAYER).reduce((i, j) => ((i.position.distance(position) <= j.position.distance(position)) ? i : j));
}
// ===========================================================================
function is2dPositionOnScreen(pos2d) { function is2dPositionOnScreen(pos2d) {
return pos2d.x >= 0 && pos2d.y >= 0 && pos2d.x <= game.width && pos2d.y <= game.height; return pos2d.x >= 0 && pos2d.y >= 0 && pos2d.x <= game.width && pos2d.y <= game.height;
} }
@@ -675,3 +681,20 @@ function setPedInvincible(ped, state) {
} }
// =========================================================================== // ===========================================================================
function setPedLookAt(ped, position) {
if(getGame() == VRR_GAME_GTA_SA) {
ped.lookAt(position, 10000);
return true;
} else {
setElementHeading(ped.id, getHeadingFromPosToPos(getElementPosition(ped.id), position));
}
}
// ===========================================================================
function setElementHeading(elementId, heading) {
getElementFromId(elementId).heading = heading;
}
// ===========================================================================

View File

@@ -619,14 +619,13 @@ function createGameVehicle(modelIndex, position, heading, toClient = null) {
// =========================================================================== // ===========================================================================
function createGameCivilian(modelIndex, position, heading, toClient = null) { function createGamePed(modelIndex, position, heading, toClient = null) {
if(areServerElementsSupported()) { if(areServerElementsSupported()) {
let civilian = game.createCivilian(getGameConfig().skins[getGame()][modelIndex][1], 0); let ped = game.createPed(getGameConfig().skins[getGame()][modelIndex][0], position);
if(!isNull(civilian)) { if(ped) {
civilian.position = position; //ped.position = position;
civilian.heading = heading; ped.heading = heading;
addToWorld(civilian); return ped;
return civilian;
} }
} }
@@ -1352,3 +1351,9 @@ function bindServerEventHandler(eventName, bindTo, handlerFunction) {
} }
// =========================================================================== // ===========================================================================
function setElementName(element, name) {
element.name = name;
}
// ===========================================================================