Skip to content

Commit 28a23a9

Browse files
committed
Explosion functions & Explosion types ID list
1 parent c601ded commit 28a23a9

File tree

9 files changed

+177
-51
lines changed

9 files changed

+177
-51
lines changed
Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,78 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/CreateExplosion
2-
client:
1+
shared: &shared
32
name: createExplosion
43
description: Creates an explosion of a certain type at a specified point in the
54
world. If creator is specified, the explosion will occur only in its dimension.
5+
parameters: []
6+
returns:
7+
values:
8+
- type: bool
9+
name: result
10+
description: Return **true** if the explosion was created. **false** if invalid parameters were
11+
passed.
12+
13+
client:
14+
<<: *shared
615
parameters:
716
- name: x
817
type: float
9-
description: a float value that specifies the X world coordinate where the explosion
18+
description: A float value that specifies the X world coordinate where the explosion
1019
is created at.
1120
- name: "y"
1221
type: float
13-
description: a float value that specifies the Y world coordinate where the explosion
22+
description: A float value that specifies the Y world coordinate where the explosion
1423
is created at.
1524
- name: z
1625
type: float
17-
description: a float value that specifies the Z world coordinate where the explosion
26+
description: A float value that specifies the Z world coordinate where the explosion
1827
is created at.
1928
- name: theType
2029
type: int
21-
description: 'a integer specifying the explosion type, see: Explosion types'
30+
description: 'An integer specifying the explosion type, see: [Explosion types](/reference/ID_Lists/Explosion_types).'
2231
- name: makeSound
2332
type: bool
24-
description: a boolean specifying whether the explosion should be heard or not.
33+
description: A boolean specifying whether the explosion should be heard or not.
2534
default: 'true'
2635
- name: camShake
2736
type: float
28-
description: a float specifying the camera shake's intensity.
37+
description: A float specifying the camera shake's intensity.
2938
default: '-1.0'
3039
- name: damaging
3140
type: bool
32-
description: a boolean specifying whether the explosion should cause damage or
41+
description: A boolean specifying whether the explosion should cause damage or
3342
not.
3443
default: 'true'
3544
examples:
36-
- path: examples/createExplosion-2.lua
37-
description: Example 1:This code will create an explosion for the local player
38-
when they spawn.
39-
side: client
40-
returns:
41-
values:
42-
- type: bool
43-
name: value
44-
description: true if the explosion was created. false if invalid parameters were
45-
passed.
46-
requires_review: true
45+
- path: examples/createExplosion-4.lua
46+
description: This code will create an explosion for the local player when they spawn.
47+
- path: examples/createExplosion-5.lua
48+
description: This will cause an explosion that will not harm the player.
49+
4750
server:
48-
name: createExplosion
49-
description: Creates an explosion of a certain type at a specified point in the
50-
world. If creator is specified, the explosion will occur only in its dimension.
51+
<<: *shared
5152
parameters:
5253
- name: x
5354
type: float
54-
description: a float value that specifies the X world coordinate where the explosion
55+
description: A float value that specifies the X world coordinate where the explosion
5556
is created at.
5657
- name: "y"
5758
type: float
58-
description: a float value that specifies the Y world coordinate where the explosion
59+
description: A float value that specifies the Y world coordinate where the explosion
5960
is created at.
6061
- name: z
6162
type: float
62-
description: a float value that specifies the Z world coordinate where the explosion
63+
description: A float value that specifies the Z world coordinate where the explosion
6364
is created at.
6465
- name: theType
6566
type: int
66-
description: 'an integer specifying the explosion type, see: Explosion types'
67+
description: 'An integer specifying the explosion type, see: [Explosion types](/reference/ID_Lists/Explosion_types).'
6768
- name: creator
6869
type: player
69-
description: the explosion's simulated creator, the player responsible for it.
70+
description: The explosion's simulated creator, the player responsible for it.
7071
default: nil
7172
examples:
7273
- path: examples/createExplosion-1.lua
73-
description: Example 1:This code will create an explosion at the player's position
74-
when they spawn.
75-
side: server
76-
returns:
77-
values:
78-
- type: bool
79-
name: value
80-
description: true if the explosion was created. false if invalid parameters were
81-
passed.
82-
requires_review: true
74+
description: This code will create an explosion at the player's position when they spawn.
75+
- path: examples/createExplosion-2.lua
76+
description: This example allows creation of claymore mines, which trigger and explode.
77+
- path: examples/createExplosion-3.lua
78+
description: This will cause an explosion that will not harm the player.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
function explosionOnSpawn ( )
2-
-- get the spawned player's position
3-
local pX, pY, pZ = getElementPosition ( source )
4-
-- and create an explosion there, making him the creator
5-
createExplosion ( pX, pY, pZ, 6, source )
1+
function explosionOnSpawn()
2+
-- get the spawned player's position
3+
local pX, pY, pZ = getElementPosition(source)
4+
-- and create an explosion there, making him the creator
5+
createExplosion(pX, pY, pZ, 6, source)
66
end
77
-- add this function as a handler for any player that spawns
8-
addEventHandler ( "onPlayerSpawn", root, explosionOnSpawn )
8+
addEventHandler("onPlayerSpawn", root, explosionOnSpawn)
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
function explosionOnSpawn ( )
2-
-- get the spawned player's position
3-
local pX, pY, pZ = getElementPosition ( source )
4-
-- and create an explosion there
5-
createExplosion ( pX, pY, pZ, 6 )
1+
function createClaymore(creator)
2+
local x, y, z = getElementPosition(creator)
3+
local claymoreObject = createObject(1945, x, y, z - 1, 0, 0, 90) -- create an object which looks like a claymore
4+
local claymoreCol = createColSphere(x, y, z, 1) -- create a collision sphere with radius 1
5+
setElementData(claymoreCol, "type", "claymore") -- store the type of colshape so it can be retrieved
6+
setElementData(claymoreCol, "object", claymoreObject) -- store the object of the claymore
7+
setElementData(claymoreCol, "creatorPlayer", creator) -- store the person who created it
68
end
7-
-- add this function as a handler for any player that spawns
8-
addEventHandler ( "onClientPlayerSpawn", localPlayer, explosionOnSpawn )
9+
10+
function claymoreHit(player)
11+
if getElementData(source, "type") == "claymore" then -- ensure its a claymore
12+
-- retrieve the object associated to the claymore, and who created it
13+
local claymoreObject = getElementData(source, "object")
14+
local claymoreCreator = getElementData(source, "creatorPlayer")
15+
-- get the position of the claymore
16+
local x, y, z = getElementPosition(source)
17+
createExplosion(x, y, z, 12, claymoreCreator) -- create an explosion, associated to the creator, of a small size at the col's position
18+
-- destroy the claymore object, and the col shape so it doesnt trigger again.
19+
destroyElement(claymoreObject)
20+
destroyElement(source)
21+
end
22+
end
23+
addEventHandler("onColShapeHit", root, claymoreHit)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function fakeBombAt(el)
2+
if isElement(el) then
3+
local x, y, z = getElementPosition(el)
4+
triggerClientEvent("fakeBomb", root, x, y, z, 0)
5+
end
6+
end
7+
8+
function onPlayerSpawnEvent(spawnpoint, team)
9+
fakeBombAt(source)
10+
end
11+
12+
function onPlayerQuitEvent(reason)
13+
fakeBombAt(source)
14+
end
15+
16+
function onPlayerDiedEvent(totalAmmo, killer, killerWeapon, bodypart)
17+
setTimer(fadeCamera, 2000, 1, source, false)
18+
fakeBombAt(source)
19+
setTimer(spawnPlayer, 4000, 1, source, 0, 0, 0)
20+
setTimer(fadeCamera, 4500, 1, source, true)
21+
end
22+
23+
addEventHandler("onPlayerQuit", root, onPlayerQuitEvent)
24+
addEventHandler("onPlayerWasted", root, onPlayerDiedEvent)
25+
addEventHandler("onPlayerSpawn", root, onPlayerSpawnEvent)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function explosionOnSpawn()
2+
-- get the spawned player's position
3+
local pX, pY, pZ = getElementPosition(source)
4+
-- and create an explosion there
5+
createExplosion(pX, pY, pZ, 6)
6+
end
7+
-- add this function as a handler for any player that spawns
8+
addEventHandler("onClientPlayerSpawn", localPlayer, explosionOnSpawn)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function fakeBomb(x, y, z, d)
2+
if d then -- Check the players Dimension
3+
if getElementDimension(localPlayer) == d then
4+
-- If the players Dimension is the current dimension
5+
-- Then people on other dimensions cant see this explosion
6+
createExplosion(x, y, z, 0, true, -1.0, false)
7+
end
8+
else
9+
createExplosion(x, y, z, 0, true, -1.0, false)
10+
end
11+
end
12+
addEvent("fakeBomb", true)
13+
addEventHandler("fakeBomb", root, fakeBomb)

web/src/data/explosion_types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const explosionTypesById: Record<number, { name: string; info?: string }> = {
2+
0: { name: "Grenade", info: "When a grenade or satchel projectile explodes." },
3+
1: { name: "Molotov", info: "When a molotov projectile explodes" },
4+
2: { name: "Rocket", info: "When a rocket projectile explodes. When a type 7 explosion occurs (with a victim i.e. vehicle source) and a 5% chance. If plane or heli (not RC vehicle) and below 250 hp and a 1.2% chance." },
5+
3: { name: "Rocket Weak", info: "If a HS rocket projectile and the launcher is not local player." },
6+
4: { name: "Car", info: "When a car or bike explodes." },
7+
5: { name: "Car Quick", info: "When ID 564 or 441 blows up. (RC Tiger & Bandit)" },
8+
6: { name: "Boat", info: "When a boat blows up." },
9+
7: { name: "Aircraft", info: "When a plane or helicopter blows up." },
10+
8: { name: "Mine", info: "Related to PICKUP_NAUTICAL_MINE_ARMED." },
11+
9: { name: "Object", info: "Exploding object e.g. explosive barrel, tank stations." },
12+
10: { name: "Tank Grenade", info: "Rhino shooting." },
13+
11: { name: "Small", info: "Most likely only used by scripts." },
14+
12: { name: "Tiny", info: "When ID 464, 465 or 501 (RC Baron, RC Raider, Goblin) blows up." },
15+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
import AutoStarlightPage from "@src/components/AutoStarlightPage.astro";
3+
import { getSeeAlsoLinksFromList } from '@src/utils/general';
4+
import SeeAlsoSection from '@src/components/SeeAlsoSection.astro';
5+
import { Code } from '@astrojs/starlight/components';
6+
import { explosionTypesById } from '@src/data/explosion_types';
7+
8+
let luaTable = `local explosionTypes = {\n`;
9+
Object.entries(explosionTypesById).forEach(([id, { name, info }], index) => {
10+
luaTable += `\t[${id}] = "${name}"`;
11+
if (info) {
12+
luaTable += `, -- ${info}`;
13+
}
14+
luaTable += `\n`;
15+
});
16+
luaTable += `}`;
17+
18+
---
19+
<AutoStarlightPage frontmatter={{
20+
template: 'doc',
21+
title: 'Explosion Types',
22+
tableOfContents: false,
23+
}}>
24+
<p>The following explosion types are used by <a href="/reference/createExplosion">createExplosion</a> function.
25+
26+
<table class="damage-types-table">
27+
<thead>
28+
<tr>
29+
<th>ID</th>
30+
<th>Name</th>
31+
<th>Description</th>
32+
</tr>
33+
</thead>
34+
<tbody>
35+
{Object.entries(explosionTypesById).map(([id, { name, info }]) => (
36+
<tr>
37+
<td>{id}</td>
38+
<td>{name}</td>
39+
<td>{info || ''}</td>
40+
</tr>
41+
))}
42+
</tbody>
43+
</table>
44+
45+
<section data-pagefind-ignore>
46+
<h4>Explosion types in a Lua table:</h4>
47+
<Code lang="lua" code={luaTable}/>
48+
</section>
49+
50+
<SeeAlsoSection seeAlsoLinks={getSeeAlsoLinksFromList([
51+
'reference:ID_Lists',
52+
])} currentId='' />
53+
</AutoStarlightPage>

web/src/pages/reference/ID_Lists/index.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import SeeAlsoSection from "@src/components/SeeAlsoSection.astro";
1818
<li>👕 <a href="/reference/ID_Lists/CJ_Clothes">CJ Clothes</a></li>
1919
<li>💥 <a href="/reference/ID_Lists/Damage_Types">Damage Types</a></li>
2020
<li>🪄 <a href="/reference/ID_Lists/Effects">Effects</a></li>
21+
<li>💣 <a href="/reference/ID_Lists/Explosion_types">Explosion Types</a></li>
2122
<li>🚗 <a href="/reference/ID_Lists/Garages">Garages</a></li>
2223
<li>🏠 <a href="/reference/ID_Lists/Interiors">Interiors</a></li>
2324
<li>

0 commit comments

Comments
 (0)