CreateExplosion: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Updated syntax, added sections, fixed clientside example)
Line 4: Line 4:


==Syntax==  
==Syntax==  
<section name="Server" class="server">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool createExplosion ( float x, float y, float z, int type [, player creator = nil, bool makeSound = true, float camShake = -1.0, bool damaging = true ] )
bool createExplosion ( float x, float y, float z, int type [, player creator = nil, bool makeSound = true, float camShake = -1.0, bool damaging = true ] )
Line 20: Line 21:
*'''camShake:''' A float specifying the camera shake's intensity.
*'''camShake:''' A float specifying the camera shake's intensity.
*'''damaging:''' A boolean specifying whether the explosion should cause damage or not.
*'''damaging:''' A boolean specifying whether the explosion should cause damage or not.
</section>
<section name="Client" class="client">
<syntaxhighlight lang="lua">
bool createExplosion ( float x, float y, float z, int type [, bool makeSound = true, float camShake = -1.0, bool damaging = true ] )
</syntaxhighlight>
===Required Arguments===
*'''x:''' A float value that specifies the X world coordinate where the explosion is created at.
*'''y:''' A float value that specifies the Y world coordinate where the explosion is created at.
*'''z:''' A float value that specifies the Z world coordinate where the explosion is created at.
*'''type:''' A integer specifying the explosion type. Valid types are:
{{Explosions}}
===Optional Arguments===
*'''makeSound:''' A boolean specifying whether the explosion should be heard or not.
*'''camShake:''' A float specifying the camera shake's intensity.
*'''damaging:''' A boolean specifying whether the explosion should cause damage or not.
</section>


===Returns===
===Returns===
Line 68: Line 88:
   -- get the spawned player's position
   -- get the spawned player's position
   local pX, pY, pZ = getElementPosition ( source )
   local pX, pY, pZ = getElementPosition ( source )
   -- and create an explosion there, making him the creator
   -- and create an explosion there
   createExplosion ( pX, pY, pZ, 6, source )
   createExplosion ( pX, pY, pZ, 6 )
end
end
-- add this function as a handler for any player that spawns
-- add this function as a handler for any player that spawns

Revision as of 22:23, 22 September 2007

Creates an explosion of a certain type at a specified point in the world.

Syntax

Click to expand [+]
Server
Click to expand [+]
Client

Returns

Returns true if the explosion was created, false if invalid parameters were passed.

Example

Click to collapse [-]
Server

Example 1: This code will create an explosion at the player's position when they spawn.

function explosionOnSpawn ( )
  -- get the spawned player's position
  local pX, pY, pZ = getElementPosition ( source )
  -- and create an explosion there, making him the creator
  createExplosion ( pX, pY, pZ, 6, source )
end
-- add this function as a handler for any player that spawns
addEventHandler ( "onPlayerSpawn", getRootElement(), explosionOnSpawn )

Example 2: This example allows creation of claymore mines, which trigger and explode.

function createClaymore ( creator )
	local x, y, z = getElementPosition ( creator )
	local claymoreObject = createObject ( 1945, x, y, z - 1, 0, 0, 90 ) --create an object which looks like a claymore
	local claymoreCol = createColSphere ( x, y, z, 1 ) --create a collision sphere with radius 1
	setElementData ( claymoreCol , "type", "claymore" ) --store the type of colshape so it can be retrieved
	setElementData ( claymoreCol, "object", claymoreObject ) --store the object of the claymore
	setElementData ( claymoreCol, "creatorPlayer", creator ) --store the person who created it
end

function claymoreHit ( player )
	if getElementData ( source, "type" ) == "claymore" then --ensure its a claymore
		--retrieve the object associated to the claymore, and who created it
		local claymoreObject = getElementData ( source, "object" )
		local claymoreCreator = getElementData ( source, "creatorPlayer" )
		--get the position of the claymore
		local x, y, z = getElementPosition ( source )
		createExplosion ( x, y, z, 12, claymoreCreator ) --create an explosion, associated to the creator, of a small size at the col's position
		--destroy the claymore object, and the col shape so it doesnt trigger again.
		destroyElement ( claymoreObject )
		destroyElement ( source )
	end
end
addEventHandler ( "onColShapeHit", getRootElement(), claymoreHit )
Click to expand [+]
Client

See Also