Add MP.Get

This commit is contained in:
Tixx 2024-09-21 23:17:08 +02:00
parent 7f69e336a9
commit 17185da53b
3 changed files with 32 additions and 0 deletions

View File

@ -37,6 +37,7 @@ namespace MP {
std::pair<bool, std::string> SendChatMessage(int ID, const std::string& Message);
std::pair<bool, std::string> RemoveVehicle(int PlayerID, int VehicleID);
void Set(int ConfigID, sol::object NewValue);
TLuaValue Get(int ConfigID);
bool IsPlayerGuest(int ID);
bool IsPlayerConnected(int ID);
void Sleep(size_t Ms);

View File

@ -292,6 +292,36 @@ void LuaAPI::MP::Set(int ConfigID, sol::object NewValue) {
}
}
TLuaValue LuaAPI::MP::Get(int ConfigID) {
switch (ConfigID) {
case 0: // debug
return Application::Settings.getAsBool(Settings::Key::General_Debug);
break;
case 1: // private
return Application::Settings.getAsBool(Settings::Key::General_Private);
break;
case 2: // max cars
return Application::Settings.getAsInt(Settings::Key::General_MaxCars);
break;
case 3: // max players
return Application::Settings.getAsInt(Settings::Key::General_MaxPlayers);
break;
case 4: // Map
return Application::Settings.getAsString(Settings::Key::General_Map);
break;
case 5: // Name
return Application::Settings.getAsString(Settings::Key::General_Name);
break;
case 6: // Desc
return Application::Settings.getAsString(Settings::Key::General_Description);
break;
default:
beammp_warn("Invalid config ID \"" + std::to_string(ConfigID) + "\". Use `MP.Settings.*` enum for this.");
return 0;
break;
}
}
void LuaAPI::MP::Sleep(size_t Ms) {
std::this_thread::sleep_for(std::chrono::milliseconds(Ms));
}

View File

@ -910,6 +910,7 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI
mEngine->CancelEventTimers(EventName, mStateId);
});
MPTable.set_function("Set", &LuaAPI::MP::Set);
MPTable.set_function("Get", &LuaAPI::MP::Get);
auto UtilTable = StateView.create_named_table("Util");
UtilTable.set_function("LogDebug", [this](sol::variadic_args args) {