CreateExplosion: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(28 intermediate revisions by 16 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
Creates an explosion of a certain type at a specified point in the world.
{{Server client function}}
Creates an explosion of a certain type at a specified point in the world. If creator is specified, the explosion will occur only in its dimension.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">bool createExplosion ( float x, float y, float z, int type, [ player creator ] )</syntaxhighlight>  
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
bool createExplosion ( float x, float y, float z, int theType [, player creator = nil ] )
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''x:''' A float value that specifies the X coordinate where the object is spawned at in the [[world]]
*'''x:''' a float value that specifies the X world coordinate where the explosion is created at.
*'''y:''' A float value that specifies the Y coordinate where the object is spawned at in the world
*'''y:''' a float value that specifies the Y world coordinate where the explosion is created at.
*'''z:''' A float value that specifies the Z coordinate where the object is spawned at in the world
*'''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:
*'''theType:''' an integer specifying the explosion type, see: [[Explosion types]]
{{Explosions}}


===Returns===
===Optional Arguments===
Returns ''true'' if the explosion was created, ''false'' if invalid parameters were passed.
*'''creator:''' the explosion's simulated creator, the [[player]] responsible for it.
</section>
 
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
bool createExplosion ( float x, float y, float z, int theType [, 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.
*'''theType:''' a integer specifying the explosion type, see: [[Explosion types]]


===Optional Arguments===
===Optional Arguments===
*'''creator:''' The explosion's simulated creator, responsible for it.  
*'''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===
*''true'' if the explosion was created.
* ''false'' if invalid parameters were passed.


==Example==  
==Example==  
This code will create an explosion at the player's position when they spawn.
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">root = getRootElement ()
'''Example 1:''' This code will create an explosion at the player's position when they spawn.
addEventHandler ( "onPlayerSpawn", root, "onPlayerSpawn" )
<syntaxhighlight lang="lua">function explosionOnSpawn ( )
function onPlayerSpawn ( spawnpoint )
  -- get the spawned player's position
   createExplosion ( getElementPosition ( source ), 6, source )
  local pX, pY, pZ = getElementPosition ( source )
end</syntaxhighlight>
  -- 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", root, explosionOnSpawn )
</syntaxhighlight>
 
'''Example 2:''' This example allows creation of claymore mines, which trigger and explode.
<syntaxhighlight lang="lua">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", root, claymoreHit )
</syntaxhighlight>
'''Example 3:''' This will cause an explosion that will not harm the player.
<syntaxhighlight lang="lua">function fakeBombAt(el)
if isElement(el) then
local x,y,z = getElementPosition(el)
triggerClientEvent ( "fakeBomb", root, x, y, z, 0 )
end
end
 
function onPlayerSpawnEvent(spawnpoint, team)
fakeBombAt(source)
end
 
function onPlayerQuitEvent(reason)
fakeBombAt(source)
end
 
function onPlayerDiedEvent(totalAmmo, killer, killerWeapon, bodypart)
setTimer(fadeCamera, 2000, 1, source, false)
fakeBombAt(source)
setTimer(spawnPlayer, 4000, 1, source, 0, 0, 0)
setTimer(fadeCamera, 4500, 1, source, true)
end
 
addEventHandler("onPlayerQuit",root,onPlayerQuitEvent)
addEventHandler("onPlayerWasted",root,onPlayerDiedEvent)
addEventHandler("onPlayerSpawn",root,onPlayerSpawnEvent)
</syntaxhighlight>
</section>
<section name="Client" class="client" show="true">
'''Example 1:''' This code will create an explosion for the local player when they spawn.
<syntaxhighlight lang="lua">function explosionOnSpawn ( )
   -- get the spawned player's position
  local pX, pY, pZ = getElementPosition ( source )
  -- and create an explosion there
  createExplosion ( pX, pY, pZ, 6 )
end
-- add this function as a handler for any player that spawns
addEventHandler ( "onClientPlayerSpawn", localPlayer, explosionOnSpawn )
</syntaxhighlight>
'''Example 2:''' This will cause an explosion that will not harm the player.
<syntaxhighlight lang="lua">function fakeBomb(x,y,z,d)
if d then --Check the players Dimension
if getElementDimension(localPlayer) == d then
                        --If the players Dimension is the current dimension
                        --Then people on other dimensions cant see this explosion
createExplosion(x, y, z, 0, true, -1.0, false)
end
else
createExplosion(x,y,z,0,true,-1.0,false)
end
end
addEvent("fakeBomb",true)
addEventHandler("fakeBomb",root,fakeBomb)
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Explosion functions}}
{{Explosion functions}}
[[ru:createExplosion]]

Latest revision as of 11:44, 11 January 2024

Creates an explosion of a certain type at a specified point in the world. If creator is specified, the explosion will occur only in its dimension.

Syntax

Click to collapse [-]
Server
bool createExplosion ( float x, float y, float z, int theType [, player creator = nil ] )

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.
  • theType: an integer specifying the explosion type, see: Explosion types

Optional Arguments

  • creator: the explosion's simulated creator, the player responsible for it.
Click to collapse [-]
Client
bool createExplosion ( float x, float y, float z, int theType [, bool makeSound = true, float camShake = -1.0, bool damaging = true ] )

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.
  • theType: a integer specifying the explosion type, see: Explosion types

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.

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", root, 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", root, claymoreHit )

Example 3: This will cause an explosion that will not harm the player.

function fakeBombAt(el)
	if isElement(el) then
		local x,y,z = getElementPosition(el)
		triggerClientEvent ( "fakeBomb", root, x, y, z, 0 )
	end
end

function onPlayerSpawnEvent(spawnpoint, team)
	fakeBombAt(source)
end

function onPlayerQuitEvent(reason)
	fakeBombAt(source)
end

function onPlayerDiedEvent(totalAmmo, killer, killerWeapon, bodypart)
	setTimer(fadeCamera, 2000, 1, source, false)
	fakeBombAt(source)
	setTimer(spawnPlayer, 4000, 1, source, 0, 0, 0)
	setTimer(fadeCamera, 4500, 1, source, true)
end

addEventHandler("onPlayerQuit",root,onPlayerQuitEvent)
addEventHandler("onPlayerWasted",root,onPlayerDiedEvent)
addEventHandler("onPlayerSpawn",root,onPlayerSpawnEvent)
Click to collapse [-]
Client

Example 1: This code will create an explosion for the local player when they spawn.

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

Example 2: This will cause an explosion that will not harm the player.

function fakeBomb(x,y,z,d)
	if d then --Check the players Dimension
		if getElementDimension(localPlayer) == d then
                        --If the players Dimension is the current dimension
                        --Then people on other dimensions cant see this explosion
			createExplosion(x, y, z, 0, true, -1.0, false)
		end
	else
		createExplosion(x,y,z,0,true,-1.0,false)
	end
end
addEvent("fakeBomb",true)
addEventHandler("fakeBomb",root,fakeBomb)

See Also