Skip to content

Commit

Permalink
ChaosMod/LuaScripts: Expose GetRandomInt and GetRandomFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Jan 18, 2025
1 parent 55519b5 commit 90741d5
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions ChaosMod/Components/LuaScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,11 @@ LuaScripts::ParseScriptRaw(std::string scriptName, std::string_view script, Pars
lua.new_enum("EOverrideShaderType", "LensDistortion", OverrideShaderType::LensDistortion, "Snow",
OverrideShaderType::Snow);

#define E(x, y) \
{ \
x, [=](sol::state &lua) \
{ \
lua[x] = y; \
} \
}
#define E(x, y) \
{ x, [=](sol::state &lua) \
{ \
lua[x] = y; \
} }
struct ExposableFunc
{
const char *Name;
Expand Down Expand Up @@ -639,6 +637,26 @@ LuaScripts::ParseScriptRaw(std::string scriptName, std::string_view script, Pars

E("AddCustomLabel", Hooks::AddCustomLabel),
E("DisplayHelpText", DisplayHelpText),

E("GetRandomInt",
[](int lower, int upper)
{
if (lower > upper)
return 0;
else if (lower == upper)
return lower;
return g_Random.GetRandomInt(lower, upper);
}),

E("GetRandomFloat",
[](float lower, float upper)
{
if (lower > upper)
return 0.f;
else if (lower == upper)
return lower;
return g_Random.GetRandomFloat(lower, upper);
}),
};
#undef E

Expand Down

0 comments on commit 90741d5

Please sign in to comment.