[][src]Function smash::app::sv_kinetic_energy::set_speed

pub unsafe extern "C" fn set_speed(arg1: u64)

Sets the current speed

This is a lua stack based function - it takes in one argument, the lua state, and relies on the current lua stack to

Arguments

Example

l2c_agent.clear_lua_stack(); //clear the stack from any previous args
l2c_agent.push_lua_stack(&mut L2CValue::new_int(*FIGHTER_KINETIC_ENERGY_ID_CONTROL as u64)); //push the first arg, that being a KINETIC_ENERGY_ID const
l2c_agent.push_lua_stack(&mut L2CValue::new_num(5.0)); //push the second arg, that being a float of the new speed we want to set 
sv_kinetic_energy::set_speed(lua_state); //call the desired function with the lua state which will grab the args we previously pushed

An L2CAgent can be obtained in multiple different contexts. One common place you'd have access to one is in sys_line_system_control_fighter That function runs once-per-frame per-fighter. As an arg it takes an L2CFighterCommon, and when hooking it, we can use that L2CFighterCommon to get an L2CAgent, which we can then use to manipulate the lua stack. To get an L2CAgent you might do something like this:

use smash::lib::{L2CValue, L2CAgent};
use smash::lua2cpp::L2CFighterCommon;
use smash::app::sv_system;
#[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_sys_line_system_control_fighter)]
pub unsafe fn sys_line_system_control_fighter_hook(fighter: &mut L2CFighterCommon) -> L2CValue {
    let module_accessor = sv_system::battle_object_module_accessor(fighter.lua_state_agent); //you can also use an L2CFighterCommon to get a module_accessor
    let mut lua_state = fighter.lua_state_agent;
    let mut l2c_agent = L2CAgent::new(lua_state);

    original!()(fighter)
}