Divergent/mods/Nitpicker's Modpack/gamedata/scripts/ish_proper_unload.script

86 lines
2.1 KiB
Plaintext
Raw Normal View History

2024-03-17 20:18:03 -04:00
-- UnloadAll - Nitpicker's Modpack
-- Last modified: 2023.07.30
-- https://github.com/Ishmaeel/NitpickerModpack
--
local Base_OnKeyboard = nil
local E_RELEASE = ui_events.WINDOW_KEY_RELEASED
local unload_strategies = {}
function on_game_start()
item_weapon.unload_all_weapons = no_stop_what_are_you_doing
Base_OnKeyboard = ui_inventory.UIInventory.OnKeyboard
ui_inventory.UIInventory.OnKeyboard = Ishy_OnKeyboard
table.insert(unload_strategies, validate)
if magazines and magazine_binder and magazines.eject_magazine and magazine_binder.is_supported_weapon then
table.insert(unload_strategies, eject_magazine)
end
table.insert(unload_strategies, unload_vanilla)
end
function Ishy_OnKeyboard(self, dik, keyboard_action)
Base_OnKeyboard(self, dik, keyboard_action)
if keyboard_action == E_RELEASE then
local bind = dik_to_bind(dik)
if bind == key_bindings.kCUSTOM15 then
unload_all_the_things(self)
end
end
end
function unload_all_the_things(self)
if self.mode == "inventory" then
db.actor:iterate_ruck(unload_weapon)
end
if self.mode == "loot" then
local npc = self.npc_id and get_object_by_id(self.npc_id)
if npc then
if npc.iterate_inventory then
npc:iterate_inventory(unload_weapon)
end
if npc.iterate_inventory_box then
npc:iterate_inventory_box(unload_weapon)
self.update_info = true
end
end
end
end
function unload_weapon(_, obj)
for _, strategy in ipairs(unload_strategies) do
local handled = strategy(obj)
if handled then
return
end
end
end
function validate(obj)
if not IsWeapon(obj) or IsItem("fake_ammo_wpn", obj:section()) then
return true
end
end
function eject_magazine(obj)
if magazine_binder.is_supported_weapon(obj) then
magazines.eject_magazine(obj)
return true
end
end
function unload_vanilla(obj)
obj:force_unload_magazine(true)
return true
end
function no_stop_what_are_you_doing()
-- stop doing things the wrong way.
end