Skip to content

Commit

Permalink
1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
irbizzelus committed May 12, 2023
1 parent d7bb390 commit 21f80ad
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 56 deletions.
29 changes: 16 additions & 13 deletions lua/copdamage.lua
Original file line number Diff line number Diff line change
@@ -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 )
end)
96 changes: 60 additions & 36 deletions lua/copmovement.lua
Original file line number Diff line number Diff line change
@@ -1,73 +1,97 @@
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

if managers.enemy:is_civilian( self._unit ) then
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 )

end)
2 changes: 1 addition & 1 deletion main.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<mod name="Immortal Dominated Cops" author="irbizzelus" color="Color(0.85,0,0.85)">
<AssetUpdates id="irbizzelus/IMMDOMCOPS" provider="github" release="true" version="1.5.1"/>
<AssetUpdates id="irbizzelus/IMMDOMCOPS" provider="github" release="true" version="1.6"/>
</mod>
4 changes: 0 additions & 4 deletions menus/immdomcopsmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions mod.txt
Original file line number Diff line number Diff line change
@@ -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: [email protected]",
"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" },
Expand Down

0 comments on commit 21f80ad

Please sign in to comment.