Untitled

mail@pastecode.io avatar
unknown
lua
3 years ago
1.2 kB
206
Indexable
local mod_name = "Inf ammo with/without reload"
local not_exist = not rawget(_G, mod_name)
local c = not_exist and rawset(_G, mod_name, {toggle = false}) and _G[mod_name] or _G[mod_name]
if not_exist then

	local use_reload_animation = false
	
	function c:toggle_mod()
		self.toggle = not self.toggle
		managers.mission._fading_debug_output:script().log(string.format("%s", (self.toggle and "Inf Ammo Activated" or "Inf Ammo Deactivated")), (self.toggle and Color.green or Color.red))
	end
	
	local orig_func_reload = RaycastWeaponBase.on_reload
	function RaycastWeaponBase:on_reload(...)
		orig_func_reload(self, ...)
		if c.toggle and use_reload_animation and managers.player:player_unit() == self._setup.user_unit then
			self:replenish()
		end
	end
	 
	local orig_func_fire = RaycastWeaponBase.ammo_base
	function RaycastWeaponBase:ammo_base(...)
		local result = orig_func_fire(self, ...)
		if c.toggle and managers.player:player_unit() == self._setup.user_unit and ((self:get_ammo_total() <= 0) or not use_reload_animation and result:get_ammo_remaining_in_clip() <= (self.AKIMBO and 1 or 0)) then
			self:replenish()
		end
		return result
	end
end
c:toggle_mod()