Graphics::drawSpotLightWithShadow

From RAGE Multiplayer Wiki

Syntax

mp.game.graphics.drawSpotLightWithShadow(posX, posY, posZ, dirX, dirY, dirZ, colorR, colorG, colorB, distance, brightness, roundness, radius, falloff, shadow);

Required Arguments

  • posX: float
  • posY: float
  • posZ: float
  • dirX: float
  • dirY: float
  • dirZ: float
  • colorR: int
  • colorG: int
  • colorB: int
  • distance: float
  • brightness: float
  • roundness: float
  • radius: float
  • falloff: float
  • shadow: float

Return value

  • Undefined

Example

This draws a spotlight with shadow from the source to the target, like a helicopter spotlight.

// Clientside
let veh = mp.vehicles.at(0); 
let target = mp.players.at(0);
// Examples, use any entity or even just a position as target

mp.events.add('render', () => {
    let forward = veh.getForwardVector();
    // returns the entity forward vector; Example: {"x": 0.5455624, "y": 0.00233556, "z": 0.00021313}
    
    let dist = Math.round(mp.game.system.vdist2(veh.position.x, veh.position.y, veh.position.z, target.position.x, target.position.y, target.position.z) / 3);
    // Calculates the distance between the given coords; you can also use mp.game.gameplay.getDistanceBetweenCoords(), but it's slower

    let dest = new mp.Vector3((target.position.x - veh.position.x - forward.x * 3.4), (target.position.y - veh.position.y - forward.y * 3.4), (target.position.z - veh.position.z - forward.z * 3.4));
    // This is the destinated direction of the spotlight relative to the starting point (start.pos - target.pos - forward.pos * 3.4); "3.4" is just a multiplier to get the correct starting point of the spotlight
    // These are NOT the destinated coordinates, it's the direction where the spotlight have to aim at, relative to the global coordinate system

    let origin = new mp.Vector3(veh.position.x + forward.x * 3.4, veh.position.y + forward.y * 3.4, (veh.position.z + forward.z * 3.4) - 1);
    // Starting point
                                         
    mp.game.graphics.drawSpotLightWithShadow(origin.x, origin.y, origin.z, dest.x, dest.y, dest.z, 255, 255, 255, dist + 10, 10, 1, 5, 1, 0);
    // Draws the spotlight every frame.
});

See also