mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2024-12-22 20:17:24 +08:00
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:
parent
cf02476c58
commit
d2a7ff8ba4
@ -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.
|
||||
|
@ -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:**
|
||||
|
@ -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)`
|
||||
@ -344,3 +344,5 @@ local pstat_value = stats.get_packed_stat_int(index)
|
||||
```lua
|
||||
stats.set_packed_stat_int(index, value)
|
||||
```
|
||||
|
||||
|
||||
|
63
docs/lua/tables/vehicles.md
Normal file
63
docs/lua/tables/vehicles.md
Normal 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
152
docs/lua/tables/weapons.md
Normal 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'))
|
||||
```
|
@ -2,6 +2,7 @@
|
||||
#include "globals.hpp"
|
||||
#include "memory.hpp"
|
||||
#include "script_global.hpp"
|
||||
#include "vector.hpp"
|
||||
|
||||
namespace lua::globals
|
||||
{
|
||||
@ -26,9 +27,9 @@ namespace lua::globals
|
||||
// Param: global: integer: index of the global
|
||||
// Returns: integer: value of the global
|
||||
// Retrieves an uint global value.
|
||||
static int get_uint(int global)
|
||||
static std::uint32_t get_uint(int global)
|
||||
{
|
||||
return *big::script_global(global).as<unsigned int*>();
|
||||
return *big::script_global(global).as<std::uint32_t*>();
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
@ -37,7 +38,7 @@ namespace lua::globals
|
||||
// Param: global: integer: index of the global
|
||||
// Returns: float: value of the global
|
||||
// Retrieves a float global value.
|
||||
static int get_float(int global)
|
||||
static float get_float(int global)
|
||||
{
|
||||
return *big::script_global(global).as<float*>();
|
||||
}
|
||||
@ -53,6 +54,17 @@ namespace lua::globals
|
||||
return std::string(big::script_global(global).as<char*>());
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: globals
|
||||
// Name: get_vec3
|
||||
// Param: global: integer: index of the global
|
||||
// Returns: Vector3: value of the global
|
||||
// Retrieves a Vector3 global value.
|
||||
static Vector3 get_vec3(int global)
|
||||
{
|
||||
return *big::script_global(global).as<Vector3*>();
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: globals
|
||||
// Name: set_int
|
||||
@ -70,9 +82,9 @@ namespace lua::globals
|
||||
// Param: global: integer: index of the global
|
||||
// Param: val: integer: new value for the global
|
||||
// Sets an uint global value.
|
||||
static void set_uint(int global, unsigned int val)
|
||||
static void set_uint(int global, std::uint32_t val)
|
||||
{
|
||||
*big::script_global(global).as<unsigned int*>() = val;
|
||||
*big::script_global(global).as<std::uint32_t*>() = val;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
@ -97,6 +109,17 @@ namespace lua::globals
|
||||
strncpy(big::script_global(global).as<char*>(), str.data(), max_length);
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: globals
|
||||
// Name: set_vec3
|
||||
// Param: global: integer: index of the global
|
||||
// Param: param: Vector3: new value for the global
|
||||
// Sets a Vector3 global value.
|
||||
static void set_vec3(int global, Vector3 param)
|
||||
{
|
||||
*big::script_global(global).as<Vector3*>() = param;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: globals
|
||||
// Name: get_pointer
|
||||
@ -115,10 +138,12 @@ namespace lua::globals
|
||||
ns["get_uint"] = get_uint;
|
||||
ns["get_float"] = get_float;
|
||||
ns["get_string"] = get_string;
|
||||
ns["get_vec3"] = get_vec3;
|
||||
ns["set_int"] = set_int;
|
||||
ns["set_uint"] = set_uint;
|
||||
ns["set_float"] = set_float;
|
||||
ns["set_string"] = set_string;
|
||||
ns["set_vec3"] = set_vec3;
|
||||
ns["get_pointer"] = get_pointer;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "locals.hpp"
|
||||
#include "memory.hpp"
|
||||
#include "vector.hpp"
|
||||
|
||||
namespace lua::locals
|
||||
{
|
||||
@ -18,6 +19,16 @@ namespace lua::locals
|
||||
{
|
||||
return *get<int*>(script, index);
|
||||
}
|
||||
// Lua API: Function
|
||||
// Table: locals
|
||||
// Name: get_uint
|
||||
// Param: script: string: The name of the script
|
||||
// Param: index: index: Index of the script local.
|
||||
// Returns: unsigned integer: The value of the given local.
|
||||
static std::uint32_t get_uint(const std::string& script, int index)
|
||||
{
|
||||
return *get<std::uint32_t*>(script, index);
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: locals
|
||||
@ -25,11 +36,22 @@ namespace lua::locals
|
||||
// Param: script: string: The name of the script
|
||||
// Param: index: index: Index of the script local.
|
||||
// Returns: float: The value of the given local.
|
||||
static int get_float(const std::string& script, int index)
|
||||
static float get_float(const std::string& script, int index)
|
||||
{
|
||||
return *get<float*>(script, index);
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: locals
|
||||
// Name: get_vec3
|
||||
// Param: script: string: The name of the script
|
||||
// Param: index: index: Index of the script local.
|
||||
// Returns: Vector3: The value of the given local.
|
||||
static Vector3 get_vec3(const std::string& script, int index)
|
||||
{
|
||||
return *get<Vector3*>(script, index);
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: locals
|
||||
// Name: set_int
|
||||
@ -41,6 +63,17 @@ namespace lua::locals
|
||||
*get<int*>(script, index) = val;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: locals
|
||||
// Name: set_int
|
||||
// Param: script: string: The name of the script
|
||||
// Param: index: index: Index of the script local.
|
||||
// Param: val: unsigned integer: The new value of the given local.
|
||||
static void set_uint(const std::string& script, int index, std::uint32_t val)
|
||||
{
|
||||
*get<std::uint32_t*>(script, index) = val;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: locals
|
||||
// Name: set_float
|
||||
@ -52,6 +85,17 @@ namespace lua::locals
|
||||
*get<float*>(script, index) = val;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: locals
|
||||
// Name: set_vec3
|
||||
// Param: script: string: The name of the script
|
||||
// Param: index: index: Index of the script local.
|
||||
// Param: val: Vector3: The new value of the given local.
|
||||
static void set_vec3(const std::string& script, int index, Vector3 val)
|
||||
{
|
||||
*get<Vector3*>(script, index) = val;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: locals
|
||||
// Name: get_pointer
|
||||
@ -67,9 +111,13 @@ namespace lua::locals
|
||||
{
|
||||
auto ns = state["locals"].get_or_create<sol::table>();
|
||||
ns["get_int"] = get_int;
|
||||
ns["get_uint"] = get_uint;
|
||||
ns["get_float"] = get_float;
|
||||
ns["get_vec3"] = get_vec3;
|
||||
ns["set_int"] = set_int;
|
||||
ns["set_uint"] = set_uint;
|
||||
ns["set_float"] = set_float;
|
||||
ns["set_vec3"] = set_vec3;
|
||||
ns["get_pointer"] = get_pointer;
|
||||
}
|
||||
}
|
97
src/lua/bindings/vehicles.cpp
Normal file
97
src/lua/bindings/vehicles.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
#include "vehicles.hpp"
|
||||
#include "services/gta_data/gta_data_service.hpp"
|
||||
|
||||
namespace lua::vehicles
|
||||
{
|
||||
// Lua API: Table
|
||||
// Name: vehicles
|
||||
// Table containing functions for getting information about vehicles in GTA V.
|
||||
|
||||
// Lua API: Function
|
||||
// Table: vehicles
|
||||
// Name: get_vehicle_display_name
|
||||
// Param: 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'))
|
||||
//```
|
||||
static std::string get_vehicle_display_name(Hash vehicle_hash)
|
||||
{
|
||||
return big::g_gta_data_service->vehicle_by_hash(vehicle_hash).m_display_name;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: vehicles
|
||||
// Name: get_vehicle_display_name
|
||||
// Param: 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'))
|
||||
//```
|
||||
static std::string get_vehicle_display_name_string(std::string vehicle_name)
|
||||
{
|
||||
return big::g_gta_data_service->vehicle_by_hash(rage::joaat(vehicle_name)).m_display_name;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: vehicles
|
||||
// Name: get_all_vehicles_by_class
|
||||
// Param: 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
|
||||
//```
|
||||
static std::vector<std::string> get_all_vehicles_by_class(std::string vehicle_class)
|
||||
{
|
||||
std::vector<std::string> return_value;
|
||||
for (auto& [name, vehicle] : big::g_gta_data_service->vehicles())
|
||||
{
|
||||
if (vehicle.m_vehicle_class == vehicle_class)
|
||||
{
|
||||
return_value.push_back(vehicle.m_name);
|
||||
}
|
||||
}
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
// Lua API: Function
|
||||
// Table: vehicles
|
||||
// Name: get_all_vehicles_by_mfr
|
||||
// Param: 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
|
||||
//```
|
||||
static std::vector<std::string> get_all_vehicles_by_mfr(std::string manufacturer)
|
||||
{
|
||||
std::vector<std::string> return_value;
|
||||
for (auto& [name, vehicle] : big::g_gta_data_service->vehicles())
|
||||
{
|
||||
if (vehicle.m_display_manufacturer == manufacturer)
|
||||
{
|
||||
return_value.push_back(vehicle.m_name);
|
||||
}
|
||||
}
|
||||
return return_value;
|
||||
}
|
||||
|
||||
void bind(sol::state& state)
|
||||
{
|
||||
auto ns = state["vehicles"].get_or_create<sol::table>();
|
||||
ns["get_vehicle_display_name"] = sol::overload(get_vehicle_display_name, get_vehicle_display_name_string);
|
||||
ns["get_all_vehicles_by_class"] = get_all_vehicles_by_class;
|
||||
ns["get_all_vehicles_by_mfr"] = get_all_vehicles_by_mfr;
|
||||
}
|
||||
}
|
7
src/lua/bindings/vehicles.hpp
Normal file
7
src/lua/bindings/vehicles.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include "lua/sol.hpp"
|
||||
|
||||
namespace lua::vehicles
|
||||
{
|
||||
void bind(sol::state& state);
|
||||
}
|
198
src/lua/bindings/weapons.cpp
Normal file
198
src/lua/bindings/weapons.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
#pragma once
|
||||
#include "weapons.hpp"
|
||||
#include "services/gta_data/gta_data_service.hpp"
|
||||
|
||||
namespace lua::weapons
|
||||
{
|
||||
// Lua API: Table
|
||||
// Name: weapons
|
||||
// Table containing functions for getting information about weapons in GTA V.
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_weapon_display_name
|
||||
// Param: 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')))
|
||||
//```
|
||||
static std::string get_weapon_display_name(Hash weapon_hash)
|
||||
{
|
||||
return big::g_gta_data_service->weapon_by_hash(weapon_hash).m_display_name;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_weapon_display_name
|
||||
// Param: 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'))
|
||||
//```
|
||||
static std::string get_weapon_display_name_string(std::string weapon_name)
|
||||
{
|
||||
return big::g_gta_data_service->weapon_by_hash(rage::joaat(weapon_name)).m_display_name;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_all_weapons_of_group_type
|
||||
// Param: 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
|
||||
//```
|
||||
static std::vector<std::string> get_all_weapons_of_group_type(Hash group_hash)
|
||||
{
|
||||
std::vector<std::string> return_value;
|
||||
for (auto& [name, weapon] : big::g_gta_data_service->weapons())
|
||||
{
|
||||
if (rage::joaat("GROUP_" + weapon.m_weapon_type) == group_hash)
|
||||
{
|
||||
return_value.push_back(weapon.m_name);
|
||||
}
|
||||
}
|
||||
return return_value;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_all_weapons_of_group_type
|
||||
// Param: 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
|
||||
//```
|
||||
static std::vector<std::string> get_all_weapons_of_group_type_string(std::string group_name)
|
||||
{
|
||||
std::transform(group_name.begin(), group_name.end(), group_name.begin(), ::toupper);
|
||||
if (group_name.find("GROUP_") == 0)
|
||||
{
|
||||
group_name.erase(0, 6);
|
||||
}
|
||||
std::vector<std::string> return_value;
|
||||
for (auto& [name, weapon] : big::g_gta_data_service->weapons())
|
||||
{
|
||||
if (weapon.m_weapon_type == group_name)
|
||||
{
|
||||
return_value.push_back(weapon.m_name);
|
||||
}
|
||||
}
|
||||
return return_value;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_all_weapon_components
|
||||
// Param: 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
|
||||
//```
|
||||
static std::vector<std::string> get_all_weapon_components(Hash weapon_hash)
|
||||
{
|
||||
return big::g_gta_data_service->weapon_by_hash(weapon_hash).m_attachments;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_all_weapon_components
|
||||
// Param: 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
|
||||
//```
|
||||
static std::vector<std::string> get_all_weapon_components_string(std::string weapon_name)
|
||||
{
|
||||
return big::g_gta_data_service->weapon_by_hash(rage::joaat(weapon_name)).m_attachments;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_weapon_component_display_name
|
||||
// Param: 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')))
|
||||
//```
|
||||
static std::string get_weapon_component_display_name(Hash weapon_component_hash)
|
||||
{
|
||||
return big::g_gta_data_service->weapon_component_by_hash(weapon_component_hash).m_display_name;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_weapon_component_display_name
|
||||
// Param: 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'))
|
||||
//```
|
||||
static std::string get_weapon_component_display_name_string(std::string weapon_component)
|
||||
{
|
||||
return big::g_gta_data_service->weapon_component_by_hash(rage::joaat(weapon_component)).m_display_name;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_weapon_component_display_desc
|
||||
// Param: 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')))
|
||||
//```
|
||||
static std::string get_weapon_component_display_desc(Hash weapon_component_hash)
|
||||
{
|
||||
return big::g_gta_data_service->weapon_component_by_hash(weapon_component_hash).m_display_desc;
|
||||
}
|
||||
|
||||
// Lua API: Function
|
||||
// Table: weapons
|
||||
// Name: get_weapon_component_display_desc
|
||||
// Param: 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'))
|
||||
//```
|
||||
static std::string get_weapon_component_display_desc_string(std::string weapon_component)
|
||||
{
|
||||
return big::g_gta_data_service->weapon_component_by_hash(rage::joaat(weapon_component)).m_display_desc;
|
||||
}
|
||||
|
||||
void bind(sol::state& state)
|
||||
{
|
||||
auto ns = state["weapons"].get_or_create<sol::table>();
|
||||
ns["get_weapon_display_name"] = sol::overload(get_weapon_display_name, get_weapon_display_name_string);
|
||||
ns["get_all_weapons_of_group_type"] = sol::overload(get_all_weapons_of_group_type, get_all_weapons_of_group_type_string);
|
||||
ns["get_all_weapon_components"] = sol::overload(get_all_weapon_components, get_all_weapon_components_string);
|
||||
ns["get_weapon_component_display_name"] = sol::overload(get_weapon_component_display_name, get_weapon_component_display_name_string);
|
||||
ns["get_weapon_component_display_desc"] = sol::overload(get_weapon_component_display_desc, get_weapon_component_display_desc_string);
|
||||
}
|
||||
}
|
7
src/lua/bindings/weapons.hpp
Normal file
7
src/lua/bindings/weapons.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include "lua/sol.hpp"
|
||||
|
||||
namespace lua::weapons
|
||||
{
|
||||
void bind(sol::state& state);
|
||||
}
|
@ -16,6 +16,8 @@
|
||||
#include "bindings/stats.hpp"
|
||||
#include "bindings/tunables.hpp"
|
||||
#include "bindings/vector.hpp"
|
||||
#include "bindings/weapons.hpp"
|
||||
#include "bindings/vehicles.hpp"
|
||||
#include "file_manager.hpp"
|
||||
#include "script_mgr.hpp"
|
||||
|
||||
@ -210,6 +212,8 @@ namespace big
|
||||
lua::imgui::bind(m_state, m_state.globals());
|
||||
lua::entities::bind(m_state);
|
||||
lua::stats::bind(m_state);
|
||||
lua::weapons::bind(m_state);
|
||||
lua::vehicles::bind(m_state);
|
||||
}
|
||||
|
||||
void lua_module::load_and_call_script()
|
||||
|
@ -73,7 +73,7 @@ namespace big
|
||||
const ped_item& gta_data_service::ped_by_hash(uint32_t hash)
|
||||
{
|
||||
for (const auto& [name, ped] : m_peds)
|
||||
if (rage::joaat(name) == hash)
|
||||
if (ped.m_hash == hash)
|
||||
return ped;
|
||||
return gta_data_service::empty_ped;
|
||||
}
|
||||
@ -81,7 +81,7 @@ namespace big
|
||||
const vehicle_item& gta_data_service::vehicle_by_hash(uint32_t hash)
|
||||
{
|
||||
for (const auto& [name, veh] : m_vehicles)
|
||||
if (rage::joaat(name) == hash)
|
||||
if (veh.m_hash == hash)
|
||||
return veh;
|
||||
return gta_data_service::empty_vehicle;
|
||||
}
|
||||
@ -89,7 +89,7 @@ namespace big
|
||||
const weapon_item& gta_data_service::weapon_by_hash(uint32_t hash)
|
||||
{
|
||||
for (const auto& [name, weapon] : m_weapons_cache.weapon_map)
|
||||
if (rage::joaat(name) == hash)
|
||||
if (weapon.m_hash == hash)
|
||||
return weapon;
|
||||
return gta_data_service::empty_weapon;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user