Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MP.Get #369

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/LuaAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions src/LuaAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
lionkor marked this conversation as resolved.
Show resolved Hide resolved
}
}

void LuaAPI::MP::Sleep(size_t Ms) {
std::this_thread::sleep_for(std::chrono::milliseconds(Ms));
}
Expand Down
1 change: 1 addition & 0 deletions src/TLuaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading