Skip to content

Instantly share code, notes, and snippets.

@ThangCZ
Last active November 17, 2023 18:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThangCZ/6b44389e96917acbc1d32629b0f836a0 to your computer and use it in GitHub Desktop.
Save ThangCZ/6b44389e96917acbc1d32629b0f836a0 to your computer and use it in GitHub Desktop.
let flashlightDistance = 20;
let flashlightBrightness = 5;
let flashlightRoundness = 0.1;
let flashlightRadius = 30;
let flashlightFalloff = 2;
const IS_FLASH_LIGHT_ON = '0x4B7620C47217126C';
const GET_CURRENT_PED_WEAPON_ENTITY_INDEX = '0x3B390A939AF0B5FC';
mp.events.add('render', () => {
mp.players.forEachInStreamRange((player) => {
if (player.weapon != 0x8BB05FD7 || (player == mp.players.local &&
mp.game.invoke(IS_FLASH_LIGHT_ON, mp.players.local.handle) == 1)) {
return;
}
const flashlightHandle = mp.game.invoke(GET_CURRENT_PED_WEAPON_ENTITY_INDEX,
player.handle);
if (!flashlightHandle) {
return;
}
const flashlight = mp.objects.newWeak(flashlightHandle);
if (!flashlight) {
return;
}
const coords = flashlight.getCoords(false);
const rotation = flashlight.getRotation(2);
const fwdVector = getWeaponForwardVector(rotation.x, rotation.y,
rotation.z);
mp.game.graphics.drawSpotLightWithShadow(coords.x + (fwdVector.x * 0.3),
coords.y + (fwdVector.y * 0.3), coords.z + (fwdVector.z * 0.3),
fwdVector.x, fwdVector.y, fwdVector.z, 255, 255, 230,
flashlightDistance, flashlightBrightness, flashlightRoundness,
flashlightRadius, flashlightFalloff, player.remoteId + 1);
});
});
function getWeaponForwardVector(x, y, z) {
x *= Math.PI / 180;
y *= Math.PI / 180;
z *= Math.PI / 180;
const cosx = Math.cos(x);
const sinx = Math.sin(x);
const cosy = Math.cos(y);
const siny = Math.sin(y);
const cosz = Math.cos(z);
const sinz = Math.sin(z);
const m20 = cosz*siny + cosy*sinz*sinx;
const m21 = sinz*siny - cosz*cosy*sinx;
const m22 = cosx*cosy;
return new mp.Vector3(m20, m21, m22);
}
// Debug commands
mp.events.add('playerCommand', (command) => {
const args = command.split(/[ ]+/);
const commandName = args[0];
args.shift();
if (commandName == 'brightness') {
flashlightBrightness = Number(args[0]);
}
if (commandName == 'roundness') {
flashlightRoundness = Number(args[0]);
}
if (commandName == 'radius') {
flashlightRadius = Number(args[0]);
}
if (commandName == 'falloff') {
flashlightFalloff = Number(args[0]);
}
if (commandName == 'distance') {
flashlightDistance = Number(args[0]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment