From 8253b580550cb22e425bf6f5da931f3cf9ce1f46 Mon Sep 17 00:00:00 2001 From: Quentin Date: Fri, 21 Jul 2023 21:21:51 +0200 Subject: [PATCH] feat(lua): Add entities.get_all_vehicles_as_handles() Add entities.get_all_peds_as_handles() Add entities.get_all_objects_as_handles() (#1795) --- docs/lua/classes/tab.md | 2 +- docs/lua/tables/entities.md | 37 ++++++++++++++++++++++++++++ docs/lua/tabs.md | 3 ++- src/lua/bindings/entities.cpp | 46 +++++++++++++++++++++++++++++++++++ src/lua/bindings/entities.hpp | 7 ++++++ src/lua/lua_module.cpp | 4 ++- 6 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 docs/lua/tables/entities.md create mode 100644 src/lua/bindings/entities.cpp create mode 100644 src/lua/bindings/entities.hpp diff --git a/docs/lua/classes/tab.md b/docs/lua/classes/tab.md index 89b7b3ff..d0c1087f 100644 --- a/docs/lua/classes/tab.md +++ b/docs/lua/classes/tab.md @@ -7,7 +7,7 @@ Class for representing a tab within the GUI. ### `is_selected()` - **Returns:** - - `boolean`: Returns true if this tab is the currently selected one in the GUI. + - `boolean`: Returns true if this tab is the one currently selected in the GUI. **Example Usage:** ```lua diff --git a/docs/lua/tables/entities.md b/docs/lua/tables/entities.md new file mode 100644 index 00000000..9edb0a79 --- /dev/null +++ b/docs/lua/tables/entities.md @@ -0,0 +1,37 @@ +# Table: entities + +Table for manipulating GTA entities. + +## Functions (3) + +### `get_all_vehicles_as_handles()` + +- **Returns:** + - `table`: Returns all vehicles as script handles + +**Example Usage:** +```lua +table = entities.get_all_vehicles_as_handles() +``` + +### `get_all_peds_as_handles()` + +- **Returns:** + - `table`: Returns all peds as script handles + +**Example Usage:** +```lua +table = entities.get_all_peds_as_handles() +``` + +### `get_all_objects_as_handles()` + +- **Returns:** + - `table`: Returns all objects as script handles + +**Example Usage:** +```lua +table = entities.get_all_objects_as_handles() +``` + + diff --git a/docs/lua/tabs.md b/docs/lua/tabs.md index 2e8c56af..241e980c 100644 --- a/docs/lua/tabs.md +++ b/docs/lua/tabs.md @@ -13,7 +13,7 @@ end) For a complete list of available gui functions, please refer to the tab class documentation and the gui table documentation. -## Tab Count: 43 +## Tab Count: 44 ### `GUI_TAB_SELF` ### `GUI_TAB_WEAPONS` @@ -38,6 +38,7 @@ For a complete list of available gui functions, please refer to the tab class do ### `GUI_TAB_TRAIN` ### `GUI_TAB_BLACKHOLE` ### `GUI_TAB_MODEL_SWAPPER` +### `GUI_TAB_VFX` ### `GUI_TAB_NETWORK` ### `GUI_TAB_MISSIONS` ### `GUI_TAB_SPOOFING` diff --git a/src/lua/bindings/entities.cpp b/src/lua/bindings/entities.cpp new file mode 100644 index 00000000..1a13ee54 --- /dev/null +++ b/src/lua/bindings/entities.cpp @@ -0,0 +1,46 @@ +#pragma once +#include "entities.hpp" + +#include "util/pools.hpp" + +namespace lua::entities +{ + // Lua API: Table + // Name: entities + // Table for manipulating GTA entities. + + // Lua API: Function + // Table: entities + // Name: get_all_vehicles_as_handles + // Returns: table: Returns all vehicles as script handles + static std::vector get_all_vehicles_as_handles() + { + return big::pools::get_all_vehicles_array(); + } + + // Lua API: Function + // Table: entities + // Name: get_all_peds_as_handles + // Returns: table: Returns all peds as script handles + static std::vector get_all_peds_as_handles() + { + return big::pools::get_all_peds_array(); + } + + // Lua API: Function + // Table: entities + // Name: get_all_objects_as_handles + // Returns: table: Returns all objects as script handles + static std::vector get_all_objects_as_handles() + { + return big::pools::get_all_props_array(); + } + + void bind(sol::state& state) + { + auto ns = state["entities"].get_or_create(); + ns["get_all_vehicles_as_handles"] = get_all_vehicles_as_handles; + ns["get_all_peds_as_handles"] = get_all_peds_as_handles; + ns["get_all_objects_as_handles"] = get_all_objects_as_handles; + } +} \ No newline at end of file diff --git a/src/lua/bindings/entities.hpp b/src/lua/bindings/entities.hpp new file mode 100644 index 00000000..0b420400 --- /dev/null +++ b/src/lua/bindings/entities.hpp @@ -0,0 +1,7 @@ +#pragma once +#include "lua/sol.hpp" + +namespace lua::entities +{ + void bind(sol::state& state); +} \ No newline at end of file diff --git a/src/lua/lua_module.cpp b/src/lua/lua_module.cpp index 0367ecb8..df3b3577 100644 --- a/src/lua/lua_module.cpp +++ b/src/lua/lua_module.cpp @@ -1,10 +1,12 @@ #include "lua_module.hpp" #include "bindings/command.hpp" +#include "bindings/entities.hpp" #include "bindings/event.hpp" #include "bindings/global_table.hpp" #include "bindings/globals.hpp" #include "bindings/gui.hpp" +#include "bindings/imgui.hpp" #include "bindings/locals.hpp" #include "bindings/log.hpp" #include "bindings/memory.hpp" @@ -13,7 +15,6 @@ #include "bindings/script.hpp" #include "bindings/tunables.hpp" #include "bindings/vector.hpp" -#include "bindings/imgui.hpp" #include "file_manager.hpp" #include "script_mgr.hpp" @@ -217,5 +218,6 @@ namespace big lua::vector::bind(state); lua::global_table::bind(state); lua::imgui::bind(state, state.globals()); + lua::entities::bind(state); } } \ No newline at end of file