Skip to content

Commit

Permalink
Merge pull request #53 from altmp/dev
Browse files Browse the repository at this point in the history
add mp.nametags.returnRenderNametags(bool) option
  • Loading branch information
Jengas authored Dec 28, 2024
2 parents 3907678 + ba2d825 commit b8d98f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions bindings/src/client/statics/Nametags.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,32 @@ class _Nametags {
#style;
#healthStyle;
#streamedPlayers = [];
#isNametagsProcessDisabled = false;

constructor() {
this.update();
alt.everyTick(this.#tick.bind(this));

alt.on('gameEntityCreate', (entity) => {
if (this.#isNametagsProcessDisabled) return;

if (entity && entity.type === BaseObjectType.Player) {
this.#streamedPlayers.push(entity);
}
});

alt.on('gameEntityDestroy', (entity) => {
if (this.#isNametagsProcessDisabled) return;

if (entity && entity.type === BaseObjectType.Player) {
const index = this.#streamedPlayers.indexOf(entity);
if (index !== -1) this.#streamedPlayers.splice(index, 1);
}
});

alt.on('baseObjectRemove', (entity) => {
if (this.#isNametagsProcessDisabled) return;

if (entity && entity.type === BaseObjectType.Player) {
const index = this.#streamedPlayers.indexOf(entity);
if (index !== -1) this.#streamedPlayers.splice(index, 1);
Expand All @@ -37,6 +44,11 @@ class _Nametags {
}

#tick() {
if (this.#isNametagsProcessDisabled) {
mp.events.dispatchLocal('render');
return;
}

const correction = getRenderCorrection();
const res = alt.getScreenResolution();
const localPos = alt.Player.local.pos;
Expand Down Expand Up @@ -127,6 +139,18 @@ class _Nametags {
useScreen2dCoords = true;
// todo orderByDistance
// todo useScreen2dCoordss

/**
* Enables or disables the nametags rendering process.
* @param {boolean} bool - If true, enables the nametags rendering process; if false, disables it.
*/
set returnRenderNametags(bool) {
this.#isNametagsProcessDisabled = !bool;

if (this.#isNametagsProcessDisabled) {
this.#streamedPlayers = [];
}
}
}

mp.nametags = new _Nametags;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ragemp-altv-bridge",
"version": "1.0.13",
"version": "1.0.14",
"description": "RAGE Multiplayer alt:V Bridge. This package provides a bridge between RAGE Multiplayer and alt:V. It allows you to use RAGEMP code in alt:V.",
"keywords": [
"ragemp",
Expand Down

0 comments on commit b8d98f7

Please sign in to comment.