Is it possible here? I’m thinking modifying some of scripts from IDs. But may someone could do it better? Heheh
Healt & Armor bay above a players head. Might be possible, you’d need to do something similar to the 3dme script, but change it to where it displays the food & water, and other stats.
It is possible, but I don’t think with the current sync it will work out tho.
Here’s a code snippet of how I use this. It’s in Typescript, but should be easily translateable. If the person doesn’t have any armor, then the armor bar is not shown.
Green = health
Blue = armor
I used [Release] Custom Head Labels as a starting point.
What it looks like without the ID:
The snippet below also contains the ID that is drawn to the left of the bar.
import { ClientPlayerId, ClientPlayerPedId } from './common';
const maxDistance: number = 35;
const width: number = 0.03;
const height: number = 0.0085;
const border: number = 0.001;
const screenResolution: number[] = GetScreenActiveResolution();
setTick(() => {
const camCoords = GetGameplayCamCoords();
const fov = GetGameplayCamFov();
for (let index = 0; index < 255; index++) {
if (!NetworkIsPlayerActive(index)) {
continue;
}
const target = GetPlayerPed(index);
if (ClientPlayerPedId === target || !DoesEntityExist(target) || IsEntityDead(target)) {
continue;
}
const targetPos = GetEntityCoords(target, true);
DrawNameTag(targetPos[0], targetPos[1], targetPos[2] + 0.5, camCoords, fov, target, index);
}
});
function DrawNameTag(
x: number,
y: number,
z: number,
camCoords: number[],
camFov: number,
otherPed: number,
otherPlayer: number,
) {
const dist = GetDistanceBetweenCoords(camCoords[0], camCoords[1], camCoords[2], x, y, z, true);
if (dist <= maxDistance) {
const screenCoords: number[] = GetScreenCoordFromWorldCoord(x, y, z);
if (screenCoords[0] === 0) {
return;
}
let scale = dist / maxDistance;
scale = (scale + scale * camFov) / 2;
if (scale < 0.6) {
scale = 0.6;
}
let health = GetEntityHealth(otherPed);
health = health < 100 ? 0 : (health - 100) / 100;
const armour = GetPedArmour(otherPed) / 100;
y = screenCoords[2];
y -= scale * (0.005 * (screenResolution[1] / 1080));
x = screenCoords[1];
if (IsPlayerFreeAimingAtEntity(ClientPlayerId, otherPed)) {
const y2 = y;
DrawId(x - 0.0225, y2 - 0.0125, otherPlayer);
if (armour > 0) {
let x2 = x - width / 2 - border / 2;
DrawRect(x2, y2, width + border * 2, 0.0085, 0, 0, 0, 200);
DrawRect(x2, y2, width, height, 68, 121, 68, 255);
DrawRect(x2 - (width / 2) * (1 - health), y2, width * health, height, 114, 203, 114, 200);
x2 = x + width / 2 + border / 2;
DrawRect(x2, y2, width + border * 2, height + border * 2, 0, 0, 0, 200);
DrawRect(x2, y2, width, height, 41, 66, 78, 255);
DrawRect(x2 - (width / 2) * (1 - armour), y2, width * armour, height, 48, 108, 135, 200);
} else {
DrawRect(x, y2, width + border * 2, height + border * 2, 0, 0, 0, 200);
DrawRect(x, y2, width, height, 68, 121, 68, 255);
DrawRect(x - (width / 2) * (1 - health), y2, width * health, height, 114, 203, 114, 200);
}
}
}
}
function DrawId(x: number, y: number, id: number) {
SetTextFont(4);
SetTextScale(0.35, 0.35);
SetTextProportional(true);
SetTextColour(255, 255, 255, 225);
SetTextOutline();
SetTextEntry('STRING');
AddTextComponentString(`${GetPlayerServerId(id)}`);
DrawText(x, y);
}
(Yes I know, I could be using GetActivePlayers()
)
I’m knew to fivem scripting, but i’m willing to learn more. I just wanna ask if this going to JS or lua?
It’s a snippet, you can use it wherever you like. The logic stays the same.
Thank you sir, Understood.
Can someone please translate this to lua?
much appreciated
can do script for this sir
Thanks for posting the snippet, really helpful
It needs a couple of changes to work on lua but it was worth