Divergent/mods/Outfit Animations/gamedata/scripts/backpack_animations.script

96 lines
3.2 KiB
Plaintext

local fov_manager = outfit_animations_fov_manager
local mcm_allow_movement = outfit_animations_mcm.get_config("allow_movement")
function on_game_start()
RegisterScriptCallback("on_option_change", on_option_change)
end
function on_option_change()
mcm_allow_movement = outfit_animations_mcm.get_config("allow_movement")
end
------------------------------------------------------------------------------
-- main
------------------------------------------------------------------------------
local anm_info = nil --it's he cuz of stalke engine magic that I don't know
local cur_slot
local det_active
function play_animation_delayed(obj, is_equip, callback)
--prepare
Invoke("play_backpack_animation_te0", 0.01, function ()
hide_hud_inventory()
cur_slot = db.actor:active_slot()
det_active = db.actor:active_detector() or nil
if det_active then det_active:switch_state(2) end
db.actor:activate_slot(0)
if headgear_animations then headgear_animations.enable_animations = false end
end)
wait_for_free_hands(function()
--play
fov_manager.restore_fov()
if mcm_allow_movement then game.only_allow_movekeys(true) else level.disable_input() end
local anm_info = select_animation(obj, is_equip)
local delay = 0.25
local length = 0
length = length + game.get_motion_length(anm_info.section_name, anm_info.anm, 1) / 1000
Invoke("play_backpack_animation_te1", delay, function()
xr_effects.play_snd(db.actor, nil, {[1] = anm_info.snd})
level.add_cam_effector(anm_info.cam, 1300, false, "")
game.play_hud_motion(2, anm_info.section_name, anm_info.anm, false, 1)
end)
--restore
Invoke("play_backpack_animation_te2", delay + length + 0.25, function()
callback() -- perform inventory ui action
if mcm_allow_movement then game.only_allow_movekeys(false) else level.enable_input() end
if headgear_animations then headgear_animations.enable_animations = true end
-- db.actor:activate_slot(cur_slot or 0)
-- if det_active then det_active:switch_state(1) end
end)
end)
end
function select_animation(obj, is_equip)
--select backpack texture based on faction, like in fdda
local faction = character_community(db.actor):sub(7)
local m_section = is_equip and "outfit_animation_backpack_equip" or "outfit_animation_backpack_unequip"
m_section = m_section .. "_" .. faction .. "_hud"
local m_animation = "anm_use"
return {
section_name = m_section,
anm = m_animation,
cam = ini_sys:r_string_ex(m_section, "cam"),
snd = ini_sys:r_string_ex(m_section, "snd")
}
end
function wait_for_free_hands(action_to_perform)
local force_timer = 0
CreateTimeEvent("outfit_animations", "wait_for_free_hands_te0", 0.1, function()
if (db.actor:active_slot() == 0 and not db.actor:active_detector() and not enhanced_animations.used_item) or (force_timer > 5) then
Invoke("wait_for_free_hands_te1", 0, action_to_perform) --i don understan y this works on 1.5.1 (ノへ ̄、)
return true
end
force_timer = force_timer + (device().time_delta/1000)
return false
end)
end
function Invoke(name, time, action)
CreateTimeEvent("outfit_animations", name, time, function()
action()
return true
end)
end