Untitled

mail@pastecode.io avatar
unknown
lua
2 years ago
3.2 kB
59
Indexable
Never
local mod_name = "minion value changer"
local loaded = rawget(_G, mod_name)
local c = not loaded and rawset(_G, mod_name, {toggle = false}) and _G[mod_name] or loaded
 
if not loaded then
	function c:init()
		self.accuracy_multiplier = 9999			-- False or number: 99 e.g
		self.damage_multiplier = 9999			-- False or number: 99 e.g
		self.minion_drop_ammo = 5				-- Minions drop ammo on toggle, convert and death, 0 for only death
		self.immortal = false					-- Reach low health and become invulnerable, can still be killed in a high dmg attack before low health
		self.invulnerable = true
		self.every_minion = true				-- Apply settings to others minions
	end

	function c:toggle_mod()
		if game_state_machine:verify_game_state(GameStateFilters.any_ingame_playing) then
			if not Network:is_server() then
				return managers.mission._fading_debug_output:script().log(string.format("%s: HOST ONLY", mod_name), Color.red)
			end
			
			self:init()
			self.toggle = not self.toggle
			self:find_minion()
			managers.mission._fading_debug_output:script().log(string.format("%s: %s", mod_name, (self.toggle and "ON" or "OFF")), (self.toggle and Color.green or Color.red))
		end
	end
	
	function c:change_minion_values(unit)
		if not Network:is_server() then
			return
		end
		
		local unit_damage = unit:character_damage()
		local unit_inventory = unit:inventory()
		local weapon_unit = unit_inventory:equipped_unit()
		
		unit_damage:set_immortal(self.toggle and self.immortal or false)
		unit_damage:set_invulnerable(self.toggle and self.invulnerable or false)
		unit_damage:set_accuracy_multiplier(self.toggle and self.accuracy_multiplier or 2)
		unit_damage._ON_STUN_ACCURACY_DECREASE = unit_damage._accuracy_multiplier
		unit_damage._immune_to_knockback = self.toggle
		unit_damage:set_pickup("ammo")
		for i = 1, self.minion_drop_ammo do
			unit_damage:drop_pickup(true)
		end
		
		if not weapon_unit then
			if unit_inventory:num_selections() <= 0 then
				local weap_name = unit:base():default_weapon_name()

				if weap_name then
					unit_inventory:add_unit_by_name(weap_name, true, true)
				end
			else
				unit_inventory:equip_selection(1, true)
			end
		end
		
		if weapon_unit then
			weapon_unit:base()._damage = self.toggle and self.damage_multiplier or tweak_data.weapon[weapon_unit:base():get_name_id()].DAMAGE
		end
	end
	
	function c:is_sowner(minion_unit)
		local ai_state = managers.groupai:state()
		local player_unit = ai_state and ai_state._criminals[managers.player:player_unit():key()]
		if player_unit and player_unit.minions and player_unit.minions[minion_unit:key()] then
			return true
		end
	end
	
	function c:find_minion()
		for _, u_data in pairs(managers.enemy:all_enemies()) do
			local unit = u_data.unit
			if unit:in_slot(16) and (self.every_minion or self:is_sowner(unit)) then
				self:change_minion_values(unit)
			end
		end
	end
	
	local orig_func_convert_to_criminal = CopDamage.convert_to_criminal
	function CopDamage:convert_to_criminal(...)
		orig_func_convert_to_criminal(self, ...)
		c:change_minion_values(self._unit)
	end
end
c:toggle_mod()