CreateProjectile: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__
This creates a projectile of the specified type on the specified coords. Returns [[true]] if creation was succesfull or [[false]] otherwise.
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool createProjectile ( element creator, int weapon, [ float x = x, float y = y, float z = z, float force = 1.0, element target = nil ] )
bool createProjectile ( element creator, int weapon, [ float x = x, float y = y, float z = z, float force = 1.0, element target = nil ] )
</syntaxhighlight>
==Required Arguments==
*'''creator:''' The [[element]] representing creator of the projectile. In case you want the projectile to be synced for everybody creator must be [[getLocalPlayer]]().
*'''weapon:''' [[int]] representing the [[projectiles|projectile weapon ID]].
==Optional Arguments==
{{OptionalArg}}
*'''x''','''y''','''z''': [[float]] starting coordinates for the projectile. They are coordinates of creator by default.
*'''force''': [[float]] representing the starting force of the projectile.
*'''target''': [[element]] target used for heat seeking rockets.
==Example==
This example makes a rocket minigun (minigun shooting with rockets).
<syntaxhighlight lang="lua">
-- This function gets triggered everytime player shoots.
function onClientPlayerWeaponFireFunc(weapon,ammo,ammoInClip,hitX,hitY,hitZ,hitElement)
if source == getLocalPlayer() and weapon == 38 then -- if source is a local player and he uses minigun...
if not createProjectile(getLocalPlayer(),19,getElementPosition(getLocalPlayer()),200) then -- then we either create a projectile...
outputChatBox ( "Rocket minigun overheated! Give it a rest pal!", source ) -- or if projectile limit is reached we output player a chat message
end
end
end
-- Don't forget to add the onClientPlayerWeaponFireFunc function as a handler for onClientPlayerWeaponFire.
addEventHandler("onClientPlayerWeaponFire",getRootElement(),onClientPlayerWeaponFireFunc)
</syntaxhighlight>
</syntaxhighlight>

Revision as of 22:26, 6 July 2007

This creates a projectile of the specified type on the specified coords. Returns true if creation was succesfull or false otherwise.

Syntax

bool createProjectile ( element creator, int weapon, [ float x = x, float y = y, float z = z, float force = 1.0, element target = nil ] )

Required Arguments

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.

  • x,y,z: float starting coordinates for the projectile. They are coordinates of creator by default.
  • force: float representing the starting force of the projectile.
  • target: element target used for heat seeking rockets.


Example

This example makes a rocket minigun (minigun shooting with rockets).

-- This function gets triggered everytime player shoots.
function onClientPlayerWeaponFireFunc(weapon,ammo,ammoInClip,hitX,hitY,hitZ,hitElement)
	if source == getLocalPlayer() and weapon == 38 then -- if source is a local player and he uses minigun...
		if not createProjectile(getLocalPlayer(),19,getElementPosition(getLocalPlayer()),200) then -- then we either create a projectile...
			outputChatBox ( "Rocket minigun overheated! Give it a rest pal!", source ) -- or if projectile limit is reached we output player a chat message
		end
	end
end
-- Don't forget to add the onClientPlayerWeaponFireFunc function as a handler for onClientPlayerWeaponFire.
addEventHandler("onClientPlayerWeaponFire",getRootElement(),onClientPlayerWeaponFireFunc)