diff --git a/scripts/client/native/connected.js b/scripts/client/native/connected.js index 3f03b76b..1cea7b56 100644 --- a/scripts/client/native/connected.js +++ b/scripts/client/native/connected.js @@ -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) { return pos2d.x >= 0 && pos2d.y >= 0 && pos2d.x <= game.width && pos2d.y <= game.height; } @@ -674,4 +680,21 @@ function setPedInvincible(ped, state) { ped.invincible = 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; +} + // =========================================================================== \ No newline at end of file diff --git a/scripts/server/native/connected.js b/scripts/server/native/connected.js index 3d564ace..8dc4ee8b 100644 --- a/scripts/server/native/connected.js +++ b/scripts/server/native/connected.js @@ -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()) { - let civilian = game.createCivilian(getGameConfig().skins[getGame()][modelIndex][1], 0); - if(!isNull(civilian)) { - civilian.position = position; - civilian.heading = heading; - addToWorld(civilian); - return civilian; + let ped = game.createPed(getGameConfig().skins[getGame()][modelIndex][0], position); + if(ped) { + //ped.position = position; + ped.heading = heading; + return ped; } } @@ -1351,4 +1350,10 @@ function bindServerEventHandler(eventName, bindTo, handlerFunction) { }); } +// =========================================================================== + +function setElementName(element, name) { + element.name = name; +} + // =========================================================================== \ No newline at end of file