CreateProjectile: Difference between revisions
Jump to navigation
Jump to search
m (Issue fixed) |
|||
(17 intermediate revisions by 8 users not shown) | |||
Line 2: | Line 2: | ||
{{Client function}} | {{Client function}} | ||
This function creates a projectile of the specified type on the specified coordinates. | This function creates a projectile of the specified type on the specified coordinates. | ||
{{Note| | |||
*'''Model''' argument is not synchronized between clients. Clients differs from local player see always standard projectile model. | |||
*'''Target''' argument valid elements are: [[player]], [[ped]], [[vehicle]] and [[object]]. | |||
}} | |||
==Syntax== | ==Syntax== | ||
Line 7: | Line 12: | ||
projectile createProjectile ( element creator, int weaponType [, float posX, float posY, float posZ, float force = 1.0, element target = nil, float rotX, float rotY, float rotZ, float velX, float velY, float velZ, int model ] ) | projectile createProjectile ( element creator, int weaponType [, float posX, float posY, float posZ, float force = 1.0, element target = nil, float rotX, float rotY, float rotZ, float velX, float velY, float velZ, int model ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[Projectile]]}} | |||
==Required Arguments== | ===Required Arguments=== | ||
*'''creator:''' The [[element]] representing creator of the projectile. In case you want the projectile to be synced for everybody creator must be the local player or his vehicle. | *'''creator:''' The [[element]] representing creator of the projectile. In case you want the projectile to be synced for everybody creator must be the local player or his vehicle. | ||
*'''weaponType:''' [[int]] representing the projectile weaponType (characteristics). Valid IDs are: | *'''weaponType:''' [[int]] representing the projectile weaponType (characteristics). Valid IDs are: | ||
{{Projectiles}} | {{Projectiles}} | ||
==Optional Arguments== | ===Optional Arguments=== | ||
{{OptionalArg}} | {{OptionalArg}} | ||
*'''posX''','''posY''','''posZ''': [[float]] starting coordinates for the projectile. They are coordinates of creator by default. | *'''posX''', '''posY''', '''posZ''': [[float]] starting coordinates for the projectile. They are coordinates of creator by default. | ||
*'''force''': [[float]] representing the starting force | *'''force''': [[float]] representing the starting force for throwable projectiles. | ||
*'''target''': [[element]] target used for heat seeking rockets. | *'''target''': [[element]] target used for heat seeking rockets. | ||
*'''rotX''','''rotY''','''rotZ''': [[float]] starting rotation for the projectile. | *'''rotX''', '''rotY''', '''rotZ''': [[float]] starting rotation for the projectile. | ||
*'''velX''','''velY''','''velZ''': [[float]] starting velocity for the projectile. | *'''velX''', '''velY''', '''velZ''': [[float]] starting velocity for the projectile. | ||
*'''model''': Integer representing the projectile's model, uses default model for weaponType if not specified. | *'''model''': Integer representing the projectile's model, uses default model for weaponType if not specified. | ||
==Returns== | ==Returns== | ||
Returns a ''[[projectile]]'' element if [[projectile]] creation was | Returns a ''[[projectile]]'' element if [[projectile]] creation was successful. Returns ''false'' if unable to create a [[projectile]] (wrong weapon ID or projectiles limit was reached). | ||
==Example== | ==Example== | ||
This example makes a rocket minigun (minigun shooting with rockets). | This example makes a rocket minigun (minigun shooting with rockets). | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function onClientPlayerWeaponFire(weaponID, weaponAmmo, weaponAmmoInClip, hitX, hitY, hitZ, hitElement) | |||
local minigunWeapon = (weaponID == 38) -- check if player is using minigun | |||
if (not minigunWeapon) then | |||
return false -- he doesn't, so don't continue | |||
end | |||
local playerX, playerY, playerZ = getElementPosition(source) -- get position of player | |||
local projectileType = 19 -- type of projectile | |||
local projectileForce = 200 -- force used for projectile | |||
local rocketProjectile = createProjectile(source, projectileType, playerX, playerY, playerZ, projectileForce) -- create rocket projectile | |||
if (not rocketProjectile) then -- if projectile limit is reached | |||
outputChatBox("Rocket minigun overheated! Give it a rest pal!", source) -- output a message | |||
end | end | ||
end | end | ||
addEventHandler("onClientPlayerWeaponFire", localPlayer, onClientPlayerWeaponFire) | |||
</syntaxhighlight> | |||
This example code shoots a projectile from your occupied vehicle that travels in the direction your vehicle is facing when you press vehicle_fire (left mouse button with default controls) | |||
<syntaxhighlight lang="lua"> | |||
function shootProjectile() | |||
local playerVehicle = getPedOccupiedVehicle(localPlayer) | |||
if (not playerVehicle) then -- only create projectile if we are inside a vehicle | |||
return false | |||
end | |||
-- | local projectileType = 19 -- rocket | ||
local vehicleX, vehicleY, vehicleZ = getElementPosition(playerVehicle) | |||
createProjectile(playerVehicle, projectileType, vehicleX, vehicleY, vehicleZ) | |||
end | |||
bindKey("vehicle_fire", "down", shootProjectile) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==Issues== | |||
{{Issues| | |||
{{Issue|584|createProjectile creates one projectile for every person in the vehicle}} | |||
{{Issue|616|Projectile rotation is set exactly opposite for creator}} | |||
}} | |||
==See also== | ==See also== |
Latest revision as of 14:01, 26 July 2024
This function creates a projectile of the specified type on the specified coordinates.
Syntax
projectile createProjectile ( element creator, int weaponType [, float posX, float posY, float posZ, float force = 1.0, element target = nil, float rotX, float rotY, float rotZ, float velX, float velY, float velZ, int model ] )
OOP Syntax Help! I don't understand this!
- Method: Projectile(...)
Required Arguments
- creator: The element representing creator of the projectile. In case you want the projectile to be synced for everybody creator must be the local player or his vehicle.
- weaponType: int representing the projectile weaponType (characteristics). Valid IDs are:
ID | Name/Description |
---|---|
16 | Grenade |
17 | Tear Gas Grenade |
18 | Molotov |
19 | Rocket (simple) |
20 | Rocket (heat seeking) |
21 | Air Bomb |
39 | Satchel Charge |
58 | Hydra flare |
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- posX, posY, posZ: float starting coordinates for the projectile. They are coordinates of creator by default.
- force: float representing the starting force for throwable projectiles.
- target: element target used for heat seeking rockets.
- rotX, rotY, rotZ: float starting rotation for the projectile.
- velX, velY, velZ: float starting velocity for the projectile.
- model: Integer representing the projectile's model, uses default model for weaponType if not specified.
Returns
Returns a projectile element if projectile creation was successful. Returns false if unable to create a projectile (wrong weapon ID or projectiles limit was reached).
Example
This example makes a rocket minigun (minigun shooting with rockets).
function onClientPlayerWeaponFire(weaponID, weaponAmmo, weaponAmmoInClip, hitX, hitY, hitZ, hitElement) local minigunWeapon = (weaponID == 38) -- check if player is using minigun if (not minigunWeapon) then return false -- he doesn't, so don't continue end local playerX, playerY, playerZ = getElementPosition(source) -- get position of player local projectileType = 19 -- type of projectile local projectileForce = 200 -- force used for projectile local rocketProjectile = createProjectile(source, projectileType, playerX, playerY, playerZ, projectileForce) -- create rocket projectile if (not rocketProjectile) then -- if projectile limit is reached outputChatBox("Rocket minigun overheated! Give it a rest pal!", source) -- output a message end end addEventHandler("onClientPlayerWeaponFire", localPlayer, onClientPlayerWeaponFire)
This example code shoots a projectile from your occupied vehicle that travels in the direction your vehicle is facing when you press vehicle_fire (left mouse button with default controls)
function shootProjectile() local playerVehicle = getPedOccupiedVehicle(localPlayer) if (not playerVehicle) then -- only create projectile if we are inside a vehicle return false end local projectileType = 19 -- rocket local vehicleX, vehicleY, vehicleZ = getElementPosition(playerVehicle) createProjectile(playerVehicle, projectileType, vehicleX, vehicleY, vehicleZ) end bindKey("vehicle_fire", "down", shootProjectile)
Issues
Issue ID | Description |
---|---|
#584 | createProjectile creates one projectile for every person in the vehicle |
#616 | Projectile rotation is set exactly opposite for creator |