Divergent/mods/Spas-12 Reanimation/gamedata/scripts/utjan_mag_check.script

94 lines
3.2 KiB
Plaintext
Raw Normal View History

2024-03-17 20:18:03 -04:00
local common = animation_common
do_ammo_check_anim = nil
if ammo_check_mcm then
base_check_Ammo = ammo_check_mcm.check_Ammo
function ammo_check_mcm.check_Ammo()
if busy_hands_fix then
base_check_Ammo()
return
end
if ammo_check_mcm.actor_on_hud_animation_play then
printf("!Old mag check script (ammo_check_mcm) detected. Remove it to get full features of mag checks")
base_check_Ammo()
return
end
local weapon = db.actor:active_item()
-- ends if no weapon is in hand etc.
if (weapon == nil or (not IsWeapon(weapon)) or IsItem("fake_ammo_wpn", nil, weapon)) then
base_check_Ammo()
return
end
local currentState = weapon:get_state()
if not (currentState == 0 or weapon:weapon_in_grenade_mode()) then
base_check_Ammo()
return
end
-- if magazine weapon
local currentAmmo = weapon:get_ammo_in_magazine()
if (currentAmmo == nil) then
base_check_Ammo()
return
end
local sec = SYS_GetParam(0, weapon:section(), "parent_section") or weapon:section()
local anm_ammo_check = SYS_GetParam(0, sec .. "_hud", "anm_ammo_check")
if not anm_ammo_check then
base_check_Ammo()
return
end
if do_ammo_check_anim then return end -- If an ammo check is already happening, don't do anything
if ammo_check_mcm.busy_hands_fix ~= nil then -- If busy_hands_fix is unlocalized
local prev_hands_fix = ammo_check_mcm.busy_hands_fix
ammo_check_mcm.busy_hands_fix = true
base_check_Ammo()
ammo_check_mcm.busy_hands_fix = prev_hands_fix
else -- Else fall back to workaround
local prev_hands_fix = ui_mcm.get("rax_ammo_check/busy_hands_fix")
ui_mcm.set("rax_ammo_check/busy_hands_fix", true)
ammo_check_mcm.on_option_change()
base_check_Ammo()
ui_mcm.set("rax_ammo_check/busy_hands_fix", prev_hands_fix)
ammo_check_mcm.on_option_change()
end
do_ammo_check_anim = 1
weapon:switch_state(4)
CreateTimeEvent("mag_check", "mag_check_reset", 3, function()
do_ammo_check_anim = nil
return true
end)
end
end
-- Catch the inspect weapon state switch and do the ammo check animation instead
function mag_check_animation(anm_table, obj)
if not (do_ammo_check_anim == 1 and obj and obj:get_state() == 4) then return end
local is_supported, has_mag_data
if magazine_binder then
is_supported = magazine_binder.is_supported_weapon(obj:section())
has_mag_data = magazine_binder.get_mag_loaded(obj:id())
end
if is_supported and not has_mag_data and common.has_animation(obj:section(), "anm_ammo_check_no_mag") then
anm_table.anm_name = "anm_ammo_check_no_mag"
else
anm_table.anm_name = "anm_ammo_check"
end
do_ammo_check_anim = 2
end
if ammo_check_mcm.actor_on_hud_animation_play then
printf("!Old mag check script (ammo_check_mcm) detected. Remove it to get full features of mag checks")
else
common.add_anim_mutator(mag_check_animation, 0.1)
end