76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import { read } from "fs";
|
|
|
|
const Natives = {
|
|
SET_BLIP_CATEGORY: RageEnums.Natives.Ui.SET_BLIP_CATEGORY,
|
|
SHOW_HEADING_INDICATOR_ON_BLIP: RageEnums.Natives.Ui.SHOW_HEADING_INDICATOR_ON_BLIP,
|
|
SET_BLIP_AS_SHORT_RANGE: RageEnums.Natives.Ui.SET_BLIP_AS_SHORT_RANGE,
|
|
SET_BLIP_DISPLAY: RageEnums.Natives.Ui.SET_BLIP_DISPLAY
|
|
};
|
|
|
|
export default function playerBlips() {
|
|
|
|
|
|
var playerBlipMap: Map<PlayerMp, BlipMp>;
|
|
var ready = false;
|
|
|
|
setInterval(() => {
|
|
if (!ready) return;
|
|
if (!playerBlipMap) playerBlipMap = new Map<PlayerMp, BlipMp>();
|
|
|
|
mp.players.forEachInStreamRange(
|
|
(player) => {
|
|
if (!playerBlipMap.has(player)) {
|
|
let pBlip = mp.blips.new(1, player.position);
|
|
|
|
let color = player.getVariable("blipColor");
|
|
pBlip.setColour(isNaN(color) ? 0 : color);
|
|
|
|
|
|
playerBlipMap.set(player, pBlip);
|
|
}
|
|
let pBlip = playerBlipMap.get(player);
|
|
pBlip.setPosition(player.position.x, player.position.y, player.position.z);
|
|
pBlip.setRotation(player.heading);
|
|
});
|
|
}, 100);
|
|
|
|
mp.events.add("playerReady", () => {
|
|
ready = true;
|
|
});
|
|
|
|
mp.events.add("entityStreamOut", (entity) => {
|
|
if (playerBlipMap && entity.type === "player") {
|
|
if (playerBlipMap.has(entity)) {
|
|
var pBlip = playerBlipMap.get(entity);
|
|
pBlip.destroy();
|
|
playerBlipMap.delete(entity);
|
|
}
|
|
}
|
|
});
|
|
|
|
/*
|
|
mp.events.add("entityStreamIn", async (entity) => {
|
|
await mp.game.waitAsync(100);
|
|
if (entity.type === "player") {
|
|
let color = parseInt(entity.getVariable("blipColor"));
|
|
if (entity.blip == 0) entity.createBlip(1);
|
|
|
|
entity.setBlipColor(isNaN(color) ? 0 : color);
|
|
|
|
mp.game.invoke(Natives.SET_BLIP_CATEGORY, entity.blip, 7);
|
|
mp.game.invoke(Natives.SHOW_HEADING_INDICATOR_ON_BLIP, entity.blip, true);
|
|
mp.game.invoke(Natives.SET_BLIP_AS_SHORT_RANGE, entity.blip, true);
|
|
mp.game.invoke(Natives.SET_BLIP_DISPLAY, entity.blip, 8);
|
|
|
|
}
|
|
});
|
|
*/
|
|
|
|
|
|
mp.events.addDataHandler("blipColor", (entity, value) => {
|
|
if (entity.type === "player") {
|
|
let color = parseInt(value);
|
|
entity.setBlipColor(isNaN(color) ? 0 : color);
|
|
}
|
|
});
|
|
} |