h1-mod/src/client/component/slowmotion.cpp

44 lines
975 B
C++
Raw Normal View History

2022-02-21 14:39:44 -05:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
2022-11-01 01:09:02 -04:00
#include "gsc/script_extension.hpp"
2022-02-21 14:39:44 -05:00
#include "game/game.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
namespace slowmotion
{
class component final : public component_interface
{
public:
void post_unpack() override
{
if (!game::environment::is_dedi())
{
return;
}
2022-11-01 01:09:02 -04:00
gsc::function::add("setslowmotion", [](const gsc::function_args& args)
{
if (args.size() == 0)
{
return scripting::script_value{};
}
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;
game::SV_SetConfigstring(10, utils::string::va("%i %i %g %g", *game::mp::gameTime, duration, start, end));
game::Com_SetSlowMotion(start, end, duration);
return scripting::script_value{};
});
2022-02-21 14:39:44 -05:00
}
};
}
2022-05-28 15:26:48 -04:00
REGISTER_COMPONENT(slowmotion::component)