feat(lua): expose the self class and add new menu events (#2656)

This commit is contained in:
Arthur
2024-01-28 17:18:44 +03:00
committed by GitHub
parent ee707c538b
commit 96048fa0f6
8 changed files with 109 additions and 3 deletions

View File

@ -80,6 +80,28 @@ namespace lua::event
// end)
// ```
// Lua API: Field
// Table: menu_event
// Field: MenuUnloaded: integer
// Event that is triggered when we unload YimMenu.
// **Example Usage:**
// ```lua
// event.register_handler(menu_event.MenuUnloaded, function ()
// log.info("Menu unloaded.")
// end)
// ```
// Lua API: Field
// Table: menu_event
// Field: ScriptsReloaded: integer
// Event that is triggered when we reload the Lua scripts.
// **Example Usage:**
// ```lua
// event.register_handler(menu_event.ScriptsReloaded, function ()
// log.info("Scripts reloaded.")
// end)
// ```
// Lua API: Table
// Name: event
// Table for responding to various events. The list of events is available in the menu_event table.
@ -107,6 +129,8 @@ namespace lua::event
{"PlayerMgrShutdown", menu_event::PlayerMgrShutdown},
{"ChatMessageReceived", menu_event::ChatMessageReceived},
{"ScriptedGameEventReceived", menu_event::ScriptedGameEventReceived},
{"MenuUnloaded", menu_event::MenuUnloaded},
{"ScriptsReloaded", menu_event::ScriptsReloaded},
});

43
src/lua/bindings/self.cpp Normal file
View File

@ -0,0 +1,43 @@
#pragma once
#include "self.hpp"
namespace lua_self = self;
namespace lua::self
{
static Ped get_ped()
{
return lua_self::ped;
}
static Player get_id()
{
return lua_self::id;
}
static Vector3 get_pos()
{
return lua_self::pos;
}
static Vector3 get_rot()
{
return lua_self::rot;
}
static Vehicle get_veh()
{
return lua_self::veh;
}
void bind(sol::state& state)
{
auto ns = state["self"].get_or_create<sol::table>();
ns["get_ped"] = get_ped;
ns["get_id"] = get_id;
ns["get_pos"] = get_pos;
ns["get_rot"] = get_rot;
ns["get_veh"] = get_veh;
}
}

View File

@ -0,0 +1,6 @@
#pragma once
namespace lua::self
{
void bind(sol::state& state);
}

View File

@ -13,6 +13,7 @@
#include "bindings/native.hpp"
#include "bindings/network.hpp"
#include "bindings/script.hpp"
#include "bindings/self.hpp"
#include "bindings/stats.hpp"
#include "bindings/tunables.hpp"
#include "bindings/vector.hpp"
@ -283,6 +284,7 @@ namespace big
lua::global_table::bind(m_state);
lua::imgui::bind(m_state, m_state.globals());
lua::entities::bind(m_state);
lua::self::bind(m_state);
lua::stats::bind(m_state);
lua::weapons::bind(m_state);
lua::vehicles::bind(m_state);