Skip to content

Commit d669641

Browse files
Add some vehicle funcs and refactor OOP info display
1 parent 4fe7dc0 commit d669641

File tree

15 files changed

+282
-71
lines changed

15 files changed

+282
-71
lines changed

elements/Matrix/Matrix.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: 'matrix'
22
description: |
33
Matrices are one of the most powerful features of MTA [OOP](/OOP_Introduction). We did have a presence of Matrices before with [getElementMatrix](/getElementMatrix), but we were given an ugly disgusting table to play with. Now, with the new Matrix class, we can make and magically manipulate Matrices.
44
5-
oop_methods:
5+
oop_only_methods:
66
- name: create
77
description: |
88
Default constructor for the Matrix class. Returns a Matrix object.

elements/Vector/Vector2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'vector2'
22
description: |
33
This is a 2D [Vector](/Vector) class.
4-
oop_methods:
4+
oop_only_methods:
55
- name: create
66
description: |
77
Default constructor for the Vector2 class. Returns a Vector2 object.

elements/Vector/Vector3.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Vector3
22
type: class
33
description: |
44
Represents a 3D [Vector](/Vector). Used for storing and manipulating three-dimensional coordinates (x, y, z).
5-
oop_methods:
5+
oop_only_methods:
66
- name: create
77
description: |
88
Default constructor for the Vector3 class. Returns a Vector3 object.

elements/Vector/Vector4.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Vector4
22
type: class
33
description: |
44
Represents a 4D [Vector](/Vector).
5-
oop_methods:
5+
oop_only_methods:
66
- name: create
77
description: |
88
Default constructor for the Vector4 class. Returns a Vector4 object.

functions/Vehicle/createVehicle.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
shared: &shared
2+
name: 'createVehicle'
3+
notes:
4+
- type: 'info'
5+
content: |
6+
Vehicles (and other elements) created client-side are only seen by the client that created them, aren't synced and players cannot enter them. They are essentially for display only.
7+
- type: 'info'
8+
content: |
9+
Due to how GTA works, creating a lot of vehicles in the same place will cause lag. The more geometries and unique textures has model the bigger the lag is. Even a lot of default vehicles will cause lag if in the same place.
10+
- type: 'important'
11+
content: |
12+
It's worth nothing that the position of the vehicle is the center point of the vehicle, not its base. As such, you need to ensure that the z value (vertical axis) is some height above the ground. You can find the exact height using the client side function [getElementDistanceFromCentreOfMassToBaseOfModel](/getElementDistanceFromCentreOfMassToBaseOfModel), or you can estimate it yourself and just spawn the vehicle so it drops to the ground.
13+
oop:
14+
entity: vehicle
15+
constructorclass: Vehicle
16+
description: |
17+
This function creates a [vehicle](/vehicle) at the specified location.
18+
parameters:
19+
- name: 'model'
20+
type: 'int'
21+
description: "The [vehicle ID](/Vehicle_IDs) of the vehicle being created."
22+
- name: 'x'
23+
type: 'float'
24+
description: "A floating point number representing the X coordinate on the map."
25+
- name: 'y'
26+
type: 'float'
27+
description: "A floating point number representing the Y coordinate on the map."
28+
- name: 'z'
29+
type: 'float'
30+
description: "A floating point number representing the Z coordinate on the map."
31+
- name: 'rx'
32+
type: 'float'
33+
default: '0'
34+
description: "A floating point number representing the rotation about the X axis in degrees."
35+
- name: 'ry'
36+
type: 'float'
37+
default: '0'
38+
description: "A floating point number representing the rotation about the Y axis in degrees."
39+
- name: 'rz'
40+
type: 'float'
41+
default: '0'
42+
description: "A floating point number representing the rotation about the Z axis in degrees."
43+
- name: 'numberplate'
44+
type: 'string'
45+
default: 'random'
46+
description: "A string representing the vehicle's number plate. If not specified, the vehicle will have a random number plate."
47+
- name: 'bDirection'
48+
type: 'boolean'
49+
default: 'false'
50+
description: "*(Serverside only)*: Placeholder boolean which provides backward compatibility with some scripts. **It never had any effect, but it is read by the code.** It is recommended to ignore this argument, passing *false* or the next `variant1` argument in its place."
51+
- name: 'variant1'
52+
type: 'int'
53+
default: 'random'
54+
description: "An integer for the first vehicle variant. See [vehicle variants](/Vehicle_variants)."
55+
- name: 'variant2'
56+
type: 'int'
57+
default: 'random'
58+
description: "An integer for the second vehicle variant. See [vehicle variants](/Vehicle_variants)."
59+
- name: 'synced'
60+
type: 'boolean'
61+
default: 'true'
62+
description: "*(Serverside only)*: A boolean value representing whether or not the vehicle will be synced. Disabling the sync might be useful for frozen or static vehicles to increase the server performance."
63+
returns:
64+
description: |
65+
Returns the [vehicle](/vehicle) element that was created. Returns *false* if the arguments are incorrect, or if the vehicle limit of `65535` is exceeded.
66+
values:
67+
- type: 'vehicle|false'
68+
name: 'theVehicle'
69+
70+
# TODO: add examples from wiki
71+
72+
server:
73+
<<: *shared
74+
75+
client:
76+
<<: *shared
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function example_onVehicleEnter ( thePlayer, seat, jacked )
2+
--If the player entered as a driver
3+
if ( seat == 0 ) then
4+
--If siren was off
5+
if not getVehicleSirensOn ( source ) then
6+
setVehicleSirensOn ( source, true ) --Turn it on
7+
else
8+
setVehicleSirensOn ( source, false ) --Turn it off
9+
end
10+
end
11+
end
12+
addEventHandler ( "onVehicleEnter", getRootElement(), example_onVehicleEnter )
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
shared: &shared
2+
name: 'setVehicleSirensOn'
3+
oop:
4+
entity: vehicle
5+
method: setSirensOn
6+
variable: sirensOn
7+
pair: 'getVehicleSirensOn'
8+
description: |
9+
This function changes the state of the sirens on the specified [vehicle](/vehicle).
10+
parameters:
11+
- name: 'theVehicle'
12+
type: 'vehicle'
13+
description: 'The [vehicle](/vehicle) that will have the sirens set.'
14+
- name: 'sirensOn'
15+
type: 'bool'
16+
description: 'The state to set the sirens to (*true* for on, *false* for off).'
17+
returns:
18+
description: |
19+
Returns *true* if the sirens are set for the specified vehicle, *false* if the sirens can't be set for the specified vehicle, if the vehicle doesn't have sirens or if invalid arguments are specified.
20+
values:
21+
- type: 'bool'
22+
name: 'result'
23+
24+
server:
25+
<<: *shared
26+
examples:
27+
- path: 'examples/setVehicleSirensOn-1.lua'
28+
description: |
29+
This example toggles siren state when a player enters a vehicle as a driver.
30+
31+
client:
32+
<<: *shared

schemas/element.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ properties:
2121
$ref: 'common-defs.yaml#/$defs/examples'
2222
see_also:
2323
$ref: 'common-defs.yaml#/$defs/see_also'
24-
oop_methods:
24+
oop_only_methods:
2525
type: array
2626
items:
2727
type: object

web/astro.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ export default defineConfig({
7676
]
7777
},
7878
{
79-
label: 'Elements',
79+
label: 'Element types',
8080
items: [
81-
{label: 'Element types', link: 'Element'},
81+
{label: 'Element', link: 'Element'},
8282
{label: 'Element tree', link: 'Element_tree'},
83-
{label: 'Entities', link: 'Entity'},
83+
{label: 'Entity', link: 'Entity'},
8484
]
8585
},
8686
{
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
import { Code } from '@astrojs/starlight/components';
3+
4+
export interface Props {
5+
element_name?: string | null;
6+
oop_only_methods: any[];
7+
oop_compatible_functions: any[];
8+
}
9+
10+
const { element_name = null, oop_only_methods, oop_compatible_functions } = Astro.props;
11+
12+
let oop_variables_by_var: Record<string, any[]> = {};
13+
for (const func of oop_compatible_functions) {
14+
if (func.oop.variable) {
15+
if (!oop_variables_by_var[func.oop.variable]) {
16+
oop_variables_by_var[func.oop.variable] = [];
17+
}
18+
oop_variables_by_var[func.oop.variable].push({
19+
functionName: func.name,
20+
functionLink: func.link,
21+
functionOop: func.oop,
22+
});
23+
}
24+
}
25+
let oop_constructor = oop_compatible_functions.find(func => func.oop.constructorclass);
26+
---
27+
{element_name && oop_constructor && (
28+
<section class="oop-constructor-section">
29+
<h4><a href="/OOP_Introduction">OOP</a> Constructor</h4>
30+
<p>
31+
<code>{oop_constructor.oop.constructorclass}(...)</code> is the constructor method for the <code>{element_name}</code> class (<a href={oop_constructor.link}>{oop_constructor.name}</a>).
32+
</p>
33+
</section>
34+
)}
35+
36+
{Object.keys(oop_variables_by_var).length > 0 && (
37+
<section class="oop-variables-section">
38+
<h4><a href="/OOP_Introduction">OOP</a> Variables and Methods</h4>
39+
<ul>
40+
{Object.entries(oop_variables_by_var).map(([variableName, functions]) => (
41+
<li>
42+
<code>{variableName}</code>:
43+
{functions.map((func: any, index: number) => (
44+
<Fragment>
45+
<a href={func.functionLink}>{func.functionOop.method}</a>
46+
{index < functions.length - 1 ? ', ' : ''}
47+
</Fragment>
48+
))}
49+
</li>
50+
))}
51+
</ul>
52+
</section>
53+
)}
54+
55+
56+
{oop_only_methods.length > 0 && (
57+
<section class="oop-methods-section">
58+
<h4><a href="/OOP_Introduction">OOP</a>-Only Methods</h4>
59+
60+
{oop_only_methods.map((method: any) => (
61+
<>
62+
<h5 id={method.name}><code>{method.name}</code></h5>
63+
{method.description && <p>{method.description}</p>}
64+
65+
{method.overloads?.length > 0 && (
66+
<div class="overloads">
67+
{method.overloads.map((overload: any) => (
68+
<div class="overload">
69+
<Code code={overload.signature} lang="lua" />
70+
{overload.description && <p>{overload.description}</p>}
71+
{overload.parameters?.length > 0 && (
72+
<ul class="parameters">
73+
{overload.parameters.map((param: any) => (
74+
<li>
75+
<strong>{param.name}</strong>
76+
{param.optional && ' (optional)'}: <code>{param.type}</code> – {param.description}
77+
</li>
78+
))}
79+
</ul>
80+
)}
81+
</div>
82+
))}
83+
</div>
84+
)}
85+
86+
{!method.overloads && method.signature && (
87+
<div class="signature">
88+
<Code code={method.signature} lang="lua" />
89+
</div>
90+
)}
91+
92+
{method.parameters?.length > 0 && (
93+
<ul class="parameters">
94+
{method.parameters.map((param: any) => (
95+
<li>
96+
<strong>{param.name}</strong>: <code>{param.type}</code> – {param.description}
97+
</li>
98+
))}
99+
</ul>
100+
)}
101+
</>
102+
))}
103+
104+
</section>
105+
)}

web/src/pages/Element.astro

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
33
import { getSeeAlsoLinksFromList } from '@src/utils/general';
44
import SeeAlsoSection from '@src/components/SeeAlsoSection.astro';
5-
import { getElementsByCategory, hasOopMethods } from '@src/utils/elements';
5+
import ElementOOPInfo from '@src/components/ElementOOPInfo.astro';
6+
import { getElementsByCategory, hasOopMethods, getOOPFunctionsForElement } from '@src/utils/elements';
67
const elementsByCategory = getElementsByCategory();
78
---
89
<StarlightPage frontmatter={{
910
template: 'doc',
10-
title: 'Element types',
11+
title: 'Element',
1112
tableOfContents: false,
1213
}}>
1314
<p>In order to perform operations on MTA objects via scripting, pointers to internal classes are exported to scripts as Lua userdata. Each of these classes has a number of exported scripting functions associated with them. Elements that have a physical representation in the game are also known as <a href="/Entity">Entities</a>.</p>
@@ -31,6 +32,13 @@ const elementsByCategory = getElementsByCategory();
3132
))}
3233
</ul>
3334

35+
<hr>
36+
37+
<ElementOOPInfo
38+
oop_only_methods={[]}
39+
oop_compatible_functions={getOOPFunctionsForElement('element')}
40+
/>
41+
3442
<SeeAlsoSection seeAlsoLinks={getSeeAlsoLinksFromList([
3543
'article:Element_tree',
3644
'article:Entity',

0 commit comments

Comments
 (0)