From 21f80ad17cc5fcb14ada2f9aa68d99dbafa33322 Mon Sep 17 00:00:00 2001 From: irbizzelus <117110119+irbizzelus@users.noreply.github.com> Date: Fri, 12 May 2023 20:36:57 +0300 Subject: [PATCH] 1.6 --- lua/copdamage.lua | 29 ++++++------ lua/copmovement.lua | 96 +++++++++++++++++++++++++--------------- main.xml | 2 +- menus/immdomcopsmenu.lua | 4 -- mod.txt | 4 +- 5 files changed, 79 insertions(+), 56 deletions(-) diff --git a/lua/copdamage.lua b/lua/copdamage.lua index e7041ec..87fc66b 100644 --- a/lua/copdamage.lua +++ b/lua/copdamage.lua @@ -1,19 +1,22 @@ -Hooks:PostHook(CopDamage, "damage_melee", "meleeinstakillonhostages", function(self,attack_data) - if immdomcops.settings.meleekill == true and immdomcops.hostages[self._unit:id()] == true and attack_data.damage > 0 then - attack_data.damage = 999999 - self._unit:character_damage():set_invulnerable(false) - self._unit:character_damage():set_immortal(false) - self._unit:network():send("set_unit_invulnerable", false, false) - self:damage_melee(attack_data) - - immdomcops.hostages[self._unit:id()] = nil - managers.money:civilian_killed() -- thats what you get for killing prisoners of war lmao +Hooks:PreHook(CopDamage, "damage_melee", "IDC_melee_insta_kill_on_hostages", function(self,attack_data) + if immdomcops.settings.meleekill == true and immdomcops.hostages[self._unit:id()] and attack_data.damage > 0 then + if immdomcops.hostages[self._unit:id()] == "tied_down" then + attack_data.damage = 999999 + + self._unit:character_damage():set_invulnerable(false) + self._unit:character_damage():set_immortal(false) + self._unit:network():send("set_unit_invulnerable", false, false) + + immdomcops.hostages[self._unit:id()] = nil + + managers.money:civilian_killed() -- thats what you get for killing prisoners of war lmao + end end -end ) +end) -Hooks:PostHook(CopDamage, "die", "postcopdeathcountourcleanup", function(self,attack_data) +Hooks:PostHook(CopDamage, "die", "IDC_post_cop_death_countour_cleanup", function(self,attack_data) if immdomcops.settings.highlights == true then self._unit:contour():remove( "friendly" , true ) self._unit:contour():remove( "highlight_character" , true ) -- not really needed cuz we dont use this highlight, but this should help in case clients run intim. highlights or something end -end ) \ No newline at end of file +end) \ No newline at end of file diff --git a/lua/copmovement.lua b/lua/copmovement.lua index c154ba6..5eca069 100644 --- a/lua/copmovement.lua +++ b/lua/copmovement.lua @@ -1,10 +1,11 @@ -Hooks:PostHook(CopMovement, "action_request", "postactionrequesttweakunitdata" , function(self,action_desc) +Hooks:PostHook(CopMovement, "action_request", "IDC_post_action_request_tweak_unit_data" , function(self,action_desc) if not Network:is_server() then return end - if self._unit:base().mic_is_being_moved then -- idk, some check if unit is busy or something? ask Undeadsewer, thats his code + -- idk, some check if unit is busy or something? ask Undeadsewer, thats his code + if self._unit:base().mic_is_being_moved then return end @@ -12,62 +13,85 @@ Hooks:PostHook(CopMovement, "action_request", "postactionrequesttweakunitdata" , return end - if self._unit:base():char_tweak().access == "teamAI4" then -- Check if 'cop' action is requested by an actuall cop and not by Hoxton or other friendly ai, who are supposed to be immortal + -- Check if 'cop' action is requested by an actuall cop and not by Hoxton or other friendly ai, who are supposed to be immortal + if self._unit:base():char_tweak().access == "teamAI4" then return end - -- Wacky zany First World Bank stealth retention code by Divided By Zero² - if Global.game_settings and Global.game_settings.level_id == "red2" and managers.groupai:state():whisper_mode() then - return - end - - -- Much better way to make sure that wrong 'enemies' dont get immortal/mortal is to only allow enemies from a list that we make ourselves to become mortal/immortal - -- Pros: - -- 1) less bugs - -- Cons: - -- 1) will take time a bit of time to figure out all enemy types that we need - -- 2) will have to make updates if ovkl adds more units who can give up + if managers.groupai:state():whisper_mode() and action_desc.variant == "tied_all_in_one" then - -- teamAI4 workaround seems to work fine since its used for every allied 'cop' as far as i know - -- 1.3 update: everything works great for now, so unless ovkl patches a new ally who works differently we are good - - if managers.groupai:state():whisper_mode() and action_desc.variant == "tied_all_in_one" then -- Only add highlight in stealth + -- Only add highlights in stealth if immdomcops.settings.highlights == true then self._unit:contour():add( "friendly" , true ) end - elseif action_desc.variant == "hands_up" then -- If hands are up activate highlights and invulnerability, and sync that info to clients + + -- If hands are up activate highlights and invulnerability, and sync that info to clients + elseif action_desc.variant == "hands_up" then + if immdomcops.settings.highlights == true then self._unit:contour():add( "friendly" , true ) end + self._unit:network():send("set_unit_invulnerable", true, true) self._unit:character_damage():set_invulnerable(true) self._unit:character_damage():set_immortal(true) + + -- add unit's id to our list of immortal hostages + immdomcops.hostages[self._unit:id()] = "hands_up" + elseif action_desc.variant == "hands_back" then + -- dont remove highlights if getting on knees + elseif action_desc.variant == "tied" then + -- dont remove highlights if cuffed - immdomcops.hostages[self._unit:id()] = true -- add unit's id to our list of hostages for melee insta kill tracking - else - if immdomcops.hostages[self._unit:id()] then -- remove unit's id if they are no longer a hostage - immdomcops.hostages[self._unit:id()] = nil - end - if immdomcops.settings.highlights == true then -- remove highlights - self._unit:contour():remove( "friendly" , true ) - end + -- add unit's id to our list of immortal hostages for melee insta kill tracking + immdomcops.hostages[self._unit:id()] = "tied_down" - if managers.groupai:state():is_enemy_converted_to_criminal(self._unit) then -- but if enemy is converted add a highlight - if immdomcops.settings.highlights == true then - self._unit:contour():add( "friendly" , true ) + else + + if immdomcops.settings.highlights == true then + if managers.groupai:state():is_enemy_converted_to_criminal(self._unit) then + -- dont remove highlights if enemy is converted + else + -- remove highlights otherwise + -- sanity check #1 + if self._unit:contour() then + -- sanity check #2 + if self._unit:contour()._contour_list then + if #self._unit:contour()._contour_list >= 1 then + + for i=1, #self._unit:contour()._contour_list do + if self._unit:contour()._contour_list[i].type == "friendly" then + self._unit:contour():remove( "friendly" , true ) + end + end + + end + end + end end end - if self._unit:character_damage().set_immortal then -- check that unit can be immortal - if self._unit:character_damage()._immortal ~= false then -- check that unit is allready immortal, then remove immortality and sync that to clients - self._unit:character_damage():set_invulnerable(false) - self._unit:character_damage():set_immortal(false) - self._unit:network():send("set_unit_invulnerable", false, false) + -- if unit is part of our hostage list and requests a new action, remove their immortality since they are now untied/converted and their AI sends requests again + if immdomcops.hostages[self._unit:id()] then + -- check that unit can be immortal, just in case + if self._unit:character_damage().set_immortal then + -- check that unit is allready immortal + if self._unit:character_damage()._immortal ~= false then + + self._unit:character_damage():set_invulnerable(false) + self._unit:character_damage():set_immortal(false) + self._unit:network():send("set_unit_invulnerable", false, false) + + -- remove unit's id from our hostage list + immdomcops.hostages[self._unit:id()] = nil + end end end + end -end ) \ No newline at end of file + +end) \ No newline at end of file diff --git a/main.xml b/main.xml index ff0defd..9993619 100644 --- a/main.xml +++ b/main.xml @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/menus/immdomcopsmenu.lua b/menus/immdomcopsmenu.lua index 4cf8e9d..f71cd17 100644 --- a/menus/immdomcopsmenu.lua +++ b/menus/immdomcopsmenu.lua @@ -33,10 +33,6 @@ Hooks:Add('MenuManagerInitialize', 'immdomcops_init', function(menu_manager) MenuCallbackHandler.idc_immdomcopssave = function(this, item) immdomcops:Save() end - - MenuCallbackHandler.idc_donothing = function(this, item) - -- do nothing - end MenuCallbackHandler.idc_cb_highlights = function(this, item) immdomcops.settings[item:name()] = item:value() == 'on' diff --git a/mod.txt b/mod.txt index db4861b..3791522 100644 --- a/mod.txt +++ b/mod.txt @@ -1,9 +1,9 @@ { "name" : "Immortal dominated cops", - "description" : "Gives immportality and visual highlight to dominated enemies.", + "description" : "Gives immportality and visual highlights to dominated enemies.", "author" : "irbizzelus\nBased on Undeadsewer's Intimidated Outlines", "contact" : "Steam profile link is on my modworkshop account\nUndeadsewer: undeadsewer@gmail.com", - "version" : "1.5.1", + "version" : "1.6", "hooks" : [ { "hook_id" : "lib/units/enemies/cop/copmovement", "script_path" : "lua/copmovement.lua" }, { "hook_id" : "lib/units/enemies/cop/copdamage", "script_path" : "lua/copdamage.lua" },