fix slow motion killcams

This commit is contained in:
m 2023-01-26 23:47:42 -06:00
parent e14000a997
commit ef572f27f7

View File

@ -10,6 +10,20 @@
namespace slowmotion
{
namespace
{
template <typename T, typename T2>
T get_timescale_safe(const scripting::value_wrap& arg)
{
if (arg.is<T>())
{
return arg.as<T>();
}
return static_cast<T>(arg.as<T2>());
}
}
class component final : public component_interface
{
public:
@ -28,8 +42,8 @@ namespace slowmotion
}
const auto start = args[0].as<float>();
const auto end = (args.size() > 0 ? args[1].as<float>() : 1.0f);
const auto duration = (args.size() > 1 ? args[2].as<int>() : 1) * 1000;
const auto end = (args.size() > 0 ? get_timescale_safe<float, int>(args[1]) : 1.0f);
const auto duration = (args.size() > 1 ? get_timescale_safe<int, float>(args[2]) : 1) * 1000;
game::SV_SetConfigstring(10, utils::string::va("%i %i %g %g", *game::mp::gameTime, duration, start, end));
game::Com_SetSlowMotion(start, end, duration);