CreateExplosion: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
Line 19: | Line 19: | ||
==Example== | ==Example== | ||
This code will create an explosion at the player's position when they spawn. | '''Example 1:''' This code will create an explosion at the player's position when they spawn. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua">function explosionOnSpawn ( spawnpoint ) | ||
function | |||
createExplosion ( getElementPosition ( source ), 6, source ) | createExplosion ( getElementPosition ( source ), 6, source ) | ||
end</syntaxhighlight> | end | ||
addEventHandler ( "onPlayerSpawn", getRootElement(), explosionOnSpawn ) | |||
</syntaxhighlight> | |||
'''Example 2:''' This example allows creation of claymores, which trigger and explode. | |||
<syntaxhighlight lang="lua">function createClaymore ( x,y,z, 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 col 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, matchingDimension ) | |||
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 ) | |||
</syntaxhighlight> | |||
==See Also== | ==See Also== | ||
{{Explosion functions}} | {{Explosion functions}} |
Revision as of 21:38, 15 July 2007
Creates an explosion of a certain type at a specified point in the world.
Syntax
bool createExplosion ( float x, float y, float z, int type, [ player creator ] )
Required Arguments
- x: A float value that specifies the X coordinate where the object is spawned at in the world
- y: A float value that specifies the Y coordinate where the object is spawned at in the world
- z: A float value that specifies the Z coordinate where the object is spawned at in the world
- type: A integer specifying the explosion type. Valid types are:
- 0: Grenade
- 1: Molotov
- 2: Rocket
- 3: Rocket Weak
- 4: Car
- 5: Car Quick
- 6: Boat
- 7: Heli
- 8: Mine
- 9: Object
- 10: Tank Grenade
- 11: Small
- 12: Tiny
Returns
Returns true if the explosion was created, false if invalid parameters were passed.
Optional Arguments
- creator: The explosion's simulated creator, responsible for it.
Example
Example 1: This code will create an explosion at the player's position when they spawn.
function explosionOnSpawn ( spawnpoint ) createExplosion ( getElementPosition ( source ), 6, source ) end addEventHandler ( "onPlayerSpawn", getRootElement(), explosionOnSpawn )
Example 2: This example allows creation of claymores, which trigger and explode.
function createClaymore ( x,y,z, 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 col 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, matchingDimension ) 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 )
See Also