Skip to main content

CreateProjectile

Description​

Creates a projectile (such as an egg or spud) at the specified position and direction. The direction values also determine the speed of the projectile. For example, (1, 0, 0) would be straight right on the X axis.

function CreateProjectile(projectileId, posx, posy, posz, dirx, diry, dirz, damage) --[[ ... ]] end

Parameters​

  • projectileId: integer - The weapon ID of the projectile to spawn.
  • posx: number - X coordinate where the projectile will appear.
  • posy: number - Y coordinate where the projectile will appear.
  • posz: number - Z coordinate where the projectile will appear.
  • dirx: number - X component of the direction/speed vector.
  • diry: number - Y component of the direction/speed vector.
  • dirz: number - Z component of the direction/speed vector.
  • damage: number - Amount of health to reduce from peds on impact.

Return Values​

  • handle: integer - A handle to the created projectile.

Example​

local X, Y, Z = PedGetOffsetInWorldCoords(gPlayer, 1, 0, 1) -- get front-mid coords of the player
local H = PedGetHeading(gPlayer) -- heading
CreateProjectile(322, X, Y, Z, -math.sin(H) / 5, math.cos(H) / 5, 0, 9999)

See Also​