feat(lua): added weapon and vehicle cache bindings (#2477)

* Replaced bad example in entities documentation.
* Updated Lua documentation for vehicles/weapons to allow for auto generation.
* Added Vector3 support to the Lua globals/locals class.
* Fixed a bug with get_float in globals/locals returning an int instead of a float.
* Fixed globals get_uint/set_uint using signed types for the return/parameter.
* Added unsigned int helpers to the locals Lua class.
This commit is contained in:
gir489
2023-12-05 03:58:35 -05:00
committed by GitHub
parent cf02476c58
commit d2a7ff8ba4
13 changed files with 700 additions and 17 deletions

View File

@ -2,7 +2,7 @@
Table containing functions for manipulating gta script globals.
## Functions (9)
## Functions (11)
### `get_int(global)`
@ -64,6 +64,21 @@ Retrieves a string global value.
string = globals.get_string(global)
```
### `get_vec3(global)`
Retrieves a Vector3 global value.
- **Parameters:**
- `global` (integer): index of the global
- **Returns:**
- `Vector3`: value of the global
**Example Usage:**
```lua
Vector3 = globals.get_vec3(global)
```
### `set_int(global, val)`
Sets an int global value.
@ -116,6 +131,19 @@ Sets a string global value.
globals.set_string(global, str)
```
### `set_vec3(global, param)`
Sets a Vector3 global value.
- **Parameters:**
- `global` (integer): index of the global
- `param` (Vector3): new value for the global
**Example Usage:**
```lua
globals.set_vec3(global, param)
```
### `get_pointer(global)`
Retrieves a pointer global.

View File

@ -2,7 +2,7 @@
Table for manipulating GTA scripts locals.
## Functions (5)
## Functions (9)
### `get_int(script, index)`
@ -18,6 +18,20 @@ Table for manipulating GTA scripts locals.
integer = locals.get_int(script, index)
```
### `get_uint(script, index)`
- **Parameters:**
- `script` (string): The name of the script
- `index` (index): Index of the script local.
- **Returns:**
- `unsigned integer`: The value of the given local.
**Example Usage:**
```lua
unsigned integer = locals.get_uint(script, index)
```
### `get_float(script, index)`
- **Parameters:**
@ -32,6 +46,20 @@ integer = locals.get_int(script, index)
float = locals.get_float(script, index)
```
### `get_vec3(script, index)`
- **Parameters:**
- `script` (string): The name of the script
- `index` (index): Index of the script local.
- **Returns:**
- `Vector3`: The value of the given local.
**Example Usage:**
```lua
Vector3 = locals.get_vec3(script, index)
```
### `set_int(script, index, val)`
- **Parameters:**
@ -44,6 +72,18 @@ float = locals.get_float(script, index)
locals.set_int(script, index, val)
```
### `set_int(script, index, val)`
- **Parameters:**
- `script` (string): The name of the script
- `index` (index): Index of the script local.
- `val` (unsigned integer): The new value of the given local.
**Example Usage:**
```lua
locals.set_int(script, index, val)
```
### `set_float(script, index, val)`
- **Parameters:**
@ -56,6 +96,18 @@ locals.set_int(script, index, val)
locals.set_float(script, index, val)
```
### `set_vec3(script, index, val)`
- **Parameters:**
- `script` (string): The name of the script
- `index` (index): Index of the script local.
- `val` (Vector3): The new value of the given local.
**Example Usage:**
```lua
locals.set_vec3(script, index, val)
```
### `get_pointer(script, index)`
- **Parameters:**

View File

@ -3,7 +3,7 @@
Table for manipulating GTA stats.
For stats that get prefixed by either `MP0` or `MP1`, you can use `MPX` instead and the menu will resolve to the correct number automatically.
## Functions (21)
## Functions (25)
### `get_character_index()`
@ -300,14 +300,14 @@ boolean = stats.set_masked_int(stat_name, new_value, bit_start, bit_size)
### `get_packed_stat_bool(index)`
- **Parameters:**
- `index` (int): packed stat's index.
- `index` (int): packed stat's index
- **Returns:**
- `boolean`: Value of the stat.
**Example Usage:**
```lua
local pstat_value = stats.get_packed_stat_bool(index)
boolean = stats.get_packed_stat_bool(index)
```
### `set_packed_stat_bool(index, value)`
@ -324,14 +324,14 @@ stats.set_packed_stat_bool(index, value)
### `get_packed_stat_int(index)`
- **Parameters:**
- `index` (int): packed stat's index
- `index` (int): packed stat's index.
- **Returns:**
- `int`: Value of the stat.
**Example Usage:**
```lua
local pstat_value = stats.get_packed_stat_int(index)
int = stats.get_packed_stat_int(index)
```
### `set_packed_stat_int(index, value)`
@ -343,4 +343,6 @@ local pstat_value = stats.get_packed_stat_int(index)
**Example Usage:**
```lua
stats.set_packed_stat_int(index, value)
```
```

View File

@ -0,0 +1,63 @@
# Table: vehicles
Table containing functions for getting information about vehicles in GTA V.
## Functions (4)
### `get_vehicle_display_name(vehicle_hash)`
- **Parameters:**
- `vehicle_hash` (Hash): JOAAT hash of the vehicle.
- **Returns:**
- `vehicle_display_string`: String: the in-game display string. If the vehicle is not found, or the call is made too early, a blank string will be returned. It is guranteed to return a safe value.
- **Example Usage:**
```lua
log.info(vehicles.get_vehicle_display_name('BTYPE2'))
```
### `get_vehicle_display_name(vehicle_name)`
- **Parameters:**
- `vehicle_name` (String): Name of the vehicle.
- **Returns:**
- `vehicle_display_string`: String: the in-game display string. If the vehicle is not found, or the call is made too early, a blank string will be returned. It is guranteed to return a safe value.
- **Example Usage:**
```lua
log.info(vehicles.get_vehicle_display_name('BTYPE2'))
```
### `get_all_vehicles_by_class(vehicle_class)`
- **Parameters:**
- `vehicle_class` (String): The vehicle class.
- **Returns:**
- `vehicles`: table<int, String>: a list of all vehicles that match the class passed in. The list can contain anything from 0 to n elements.
- **Example Usage:**
```lua
local sports_classics = vehicles.get_all_vehicles_by_class('Sports Classics')
for i = 1, #sports_classics do
log.info(sports_classics[i])
end
```
### `get_all_vehicles_by_mfr(manufacturer)`
- **Parameters:**
- `manufacturer` (String): The vehicle manufacturer.
- **Returns:**
- `vehicles`: table<int, String>: a list of all vehicles that match the manufacturer passed in. The list can contain anything from 0 to n elements.
- **Example Usage:**
```lua
local albanies = vehicles.get_all_vehicles_by_mfr('Albany')
for i = 1, #albanies do
log.info(albanies[i])
end
```

152
docs/lua/tables/weapons.md Normal file
View File

@ -0,0 +1,152 @@
# Table: weapons
Table containing functions for getting information about weapons in GTA V.
## Functions (10)
### `get_weapon_display_name(weapon_hash)`
- **Parameters:**
- `weapon_hash` (Hash): JOAAT hash of the weapon.
- **Returns:**
- `weapon_display_name`: String: the in-game display string. If the weapon is not found, or the call is made too early, a blank string will be returned. It is guranteed to return a safe value.
- **Example Usage:**
```lua
log.info(weapons.get_weapon_display_name(joaat('WEAPON_REVOLVER')))
```
### `get_weapon_display_name(weapon_name)`
- **Parameters:**
- `weapon_name` (String): Name of the weapon.
- **Returns:**
- `weapon_display_name`: String: the in-game display string. If the weapon is not found, or the call is made too early, a blank string will be returned. It is guranteed to return a safe value.
- **Example Usage:**
```lua
log.info(weapons.get_weapon_display_name('WEAPON_REVOLVER'))
```
### `get_all_weapons_of_group_type(group_hash)`
- **Parameters:**
- `group_hash` (Hash): The JOAAT hash of the group the weapon(s) belong to.
- **Returns:**
- `weapons_of_group_type`: table<int, String>: a list of all weapons that match the group hash passed in. The list can contain anything from 0 to n elements.
- **Example Usage:**
```lua
local pistols = weapons.get_all_weapons_of_group_type(joaat('GROUP_PISTOL'))
for i = 1, #pistols do
log.info(pistols[i])
end
```
### `get_all_weapons_of_group_type(group_name)`
- **Parameters:**
- `group_name` (String): The group the weapon(s) belong to. Can be in either GROUP_ format or not. Parameter is case-insensitive.
- **Returns:**
- `weapons_of_group_type`: table<int, String>: a list of all weapons that match the group hash passed in. The list can contain anything from 0 to n elements.
- **Example Usage:**
```lua
local pistols = weapons.get_all_weapons_of_group_type('GROUP_PISTOL')
for i = 1, #pistols do
log.info(pistols[i])
end
local pistols = weapons.get_all_weapons_of_group_type('PISTOL')
for i = 1, #pistols do
log.info(pistols[i])
end
```
### `get_all_weapon_components(weapon_hash)`
- **Parameters:**
- `weapon_hash` (Hash): The JOAAT hash of the weapon the component(s) belong to.
- **Returns:**
- `weapon_components`: table<int, String>: a list of all components that match the weapon passed in. The list can contain anything from 0 to n elements.
- **Example Usage:**
```lua
local pistol_attachments = weapons.get_all_weapon_components(joaat('WEAPON_PISTOL'))
for i = 1, #pistol_attachments do
log.info(pistol_attachments[i])
end
```
### `get_all_weapon_components(weapon_name)`
- **Parameters:**
- `weapon_name` (String): The weapon the component(s) belong to.
- **Returns:**
- `weapon_components`: table<int, String>: a list of all components that match the weapon passed in. The list can contain anything from 0 to n elements.
- **Example Usage:**
```lua
local pistol_attachments = weapons.get_all_weapon_components('WEAPON_PISTOL')
for i = 1, #pistol_attachments do
log.info(pistol_attachments[i])
end
```
### `get_weapon_component_display_name(weapon_component_hash)`
- **Parameters:**
- `weapon_component_hash` (Hash): JOAAT hash of the weapon component.
- **Returns:**
- `component_display_name`: String: the in-game display string. If the component is not found, or the call is made too early, a blank string will be returned. It is guranteed to return a safe value.
- **Example Usage:**
```lua
log.info(weapons.get_weapon_component_display_name(joaat('COMPONENT_PISTOL_CLIP_01')))
```
### `get_weapon_component_display_name(weapon_component)`
- **Parameters:**
- `weapon_component` (String): The weapon component.
- **Returns:**
- `component_display_name`: String: the in-game display string. If the component is not found, or the call is made too early, a blank string will be returned. It is guranteed to return a safe value.
- **Example Usage:**
```lua
log.info(weapons.get_weapon_component_display_name('COMPONENT_PISTOL_CLIP_01'))
```
### `get_weapon_component_display_desc(weapon_component_hash)`
- **Parameters:**
- `weapon_component_hash` (Hash): JOAAT hash of the weapon component.
- **Returns:**
- `component_display_desc`: String: the in-game display string. If the component is not found, or the call is made too early, a blank string will be returned. It is guranteed to return a safe value.
- **Example Usage:**
```lua
log.info(weapons.get_weapon_component_display_desc(joaat('COMPONENT_PISTOL_CLIP_01')))
```
### `get_weapon_component_display_desc(weapon_component)`
- **Parameters:**
- `weapon_component` (String): The weapon component.
- **Returns:**
- `component_display_desc`: String: the in-game display string. If the component is not found, or the call is made too early, a blank string will be returned. It is guranteed to return a safe value.
- **Example Usage:**
```lua
log.info(weapons.get_weapon_component_display_desc('COMPONENT_PISTOL_CLIP_01'))
```