I have most of it done but it keeps crashing. If you activate "No Alarm" then walk up to a guard and nudge him or do other things around him will eventually go into a hostile crouching state and never get up. At this point if you deactivate "No Alarm" it will crash. Because of the restore method(which as far as I know Transcend made it) I believe it tries to restore his position of "idle" but cant. Because of a couple of complications I don't want to use Interception.RestoreAll() or other things to completely rewrite the code. How can I fix them being able to change state to crouching with a restore is my overall question.


 

Interception = Interception or class()
Interception.Backups = Interception.Backups or { }

-- eg. local old_function = Interception.Backup(PlayerManager, "upgrade_value")
function Interception.Backup(class, func)
if not class[func] then
io.stderr:write("Cannot backup '" .. func .. "'.\n")
return nil
end
local prefix = "__"
if not class[prefix .. func] then
class[prefix .. func] = class[func]
table.insert(Interception.Backups, { class = class, func = func })
end
return class[func]
end

function Interception.RestoreAll()
for _,v in pairs(Interception.Backups) do
Interception.Restore(v.class, v.func)
end
Interception.Backups = { }
end

-- eg. Interception.Restore("PlayerManager", "upgrade_value")
function Interception.Restore(class, func)
local prefix = "__"
if class[prefix .. func] then
class[func] = class[prefix .. func]
class[prefix .. func] = nil
end
end

-------------------------------------------------------------------------

if managers.hud then
managers.hud:show_hint( { text = "No Alarm Mode Activated!" } )
end

Interception.Backup(CopMovement, "set_cool")
Interception.Backup(GroupAIStateBase, "set_whisper_mode")
Interception.Backup(CopBrain, "set_objective")
Interception.Backup(CopMovement, "set_stance")
Interception.Backup(CopMovement, "set_stance_by_code")
Interception.Backup(CopLogicInactive, "_set_interaction")
Interception.Backup(CopMovement, "set_allow_fire")
Interception.Backup(CopMovement, "set_allow_fire_on_client")
Interception.Backup(CopMovement, "action_request")
Interception.Backup(CopLogicArrest, "_say_call_the_police")
Interception.Backup(CopMovement, "on_suppressed")
Interception.Backup(CopLogicBase, "_get_logic_state_from_reaction")
Interception.Backup(CopLogicIdle, "on_alert")
Interception.Backup(GroupAIStateBase, "on_police_called")
Interception.Backup(GroupAIStateBase, "on_police_weapons_hot")
Interception.Backup(GroupAIStateBase, "on_gangster_weapons_hot")
Interception.Backup(GroupAIStateBase, "on_enemy_weapons_hot")
Interception.Backup(GroupAIStateBase, "add_alert_listener")
Interception.Backup(GroupAIStateBase, "criminal_spotted")
Interception.Backup(GroupAIStateBase, "report_aggression")
Interception.Backup(GroupAIStateBase, "propagate_alert")
Interception.Backup(GroupAIStateBase, "on_criminal_suspicion_progress")
Interception.Backup(PlayerMovement, "on_suspicion")
Interception.Backup(SecurityCamera, "_upd_suspicion")
Interception.Backup(SecurityCamera, "_sound_the_alarm")
Interception.Backup(SecurityCamera, "_set_suspicion_sound")


if not _setCool then _setCool = CopMovement.set_cool end
function CopMovement:set_cool( state, giveaway )
if state == true then _setCool(self, state, giveaway) end
end

if not _setWhisper then _setWhisper = GroupAIStateBase.set_whisper_mode end

function GroupAIStateBase:set_whisper_mode( enabled )
if enabled == true then _setWhisper(self, true) end
end

if not _setObjective then _setObjective = CopBrain.set_objective end

function CopBrain:set_objective( new_objective )
if (not new_objective) or (new_objective.stance ~= "hos" and new_objective.attitude ~= "engage") then _setObjective(self, new_objective) end
end

if not _setStance then _setStance = CopMovement.set_stance end

function CopMovement:set_stance( new_stance_name )
if new_stance_name ~= "hos" then _setStance(self, new_stance_name) end
end

if not _setStanceCode then _setStanceCode = CopMovement.set_stance_by_code end

function CopMovement:set_stance_by_code( new_stance_code )
if new_stance_code == 1 then _setStanceCode(self, new_stance_code) end
end

if not _setInteraction then _setInteraction = CopLogicInactive._set_interaction end

function CopLogicInactive._set_interaction( data, my_data )
data.char_tweak.has_alarm_pager = false
_setInteraction(data, my_data)
end

if not _setAllowFire then _setAllowFire = CopMovement.set_allow_fire end

function CopMovement:set_allow_fire( state )
if state == false then _setAllowFire(self, state) end
end

if not _setAllowFireClient then _setAllowFireClient = CopMovement.set_allow_fire_on_client end

function CopMovement:set_allow_fire_on_client( state, unit )
if state == false then _setAllowFireClient(self, state, unit) end
end

-- Prevents panic buttons & intel burning (intercepting the 'run' action is the only way; for example, if you intercept events such as 'e_so_alarm_under_table' to prevent intel burning, the animation will not happen but the fire will still appear)
if not _actionRequest then _actionRequest = CopMovement.action_request end

function CopMovement:action_request( action_desc )
-- action_desc.variant == "e_so_alarm_under_table": gangsters lighting intel on fire in Big Oil Day 1, etc
-- action_desc.variant == "cmf_so_press_alarm_wall": civilian in Bank Heist pressing panic button, etc
-- action_desc.variant == "cmf_so_press_alarm_table": tellers in Bank Heist pressing panic button, etc
-- action_desc.variant == "cmf_so_call_police": civilians calling the police
-- action_desc.variant == "arrest_call": cops saying they are calling the police

-- Stops panic buttons & intel burning
if action_desc.variant == "run" then return false end

return _actionRequest(self, action_desc)
end


function CopLogicArrest._say_call_the_police( data, my_data ) end
function CopMovement:on_suppressed( state ) end
function CopLogicBase._get_logic_state_from_reaction( data, reaction ) return "idle" end
function CopLogicIdle.on_alert( data, alert_data ) end
function GroupAIStateBase:on_police_called( called_reason ) end
function GroupAIStateBase:on_police_weapons_hot( called_reason ) end
function GroupAIStateBase:on_gangster_weapons_hot( called_reason ) end
function GroupAIStateBase:on_enemy_weapons_hot( is_delayed_callback ) end
function GroupAIStateBase:add_alert_listener( id, clbk, filter_num, types, m_pos ) end
function GroupAIStateBase:criminal_spotted( unit ) end
function GroupAIStateBase:report_aggression( unit ) end
function GroupAIStateBase:propagate_alert( alert_data ) end
function GroupAIStateBase:on_criminal_suspicion_progress( u_suspect, u_observer, status ) end
function PlayerMovement:on_suspicion( observer_unit, status ) end
function SecurityCamera:_upd_suspicion( t ) end
function SecurityCamera:_sound_the_alarm( detected_unit ) end
function SecurityCamera:_set_suspicion_sound( suspicion_level ) end

if not _toggle then _toggle = true
else
_toggle = false


Interception.Restore(CopMovement, "set_cool")
Interception.Restore(GroupAIStateBase, "set_whisper_mode")
Interception.Restore(CopBrain, "set_objective")
Interception.Restore(CopMovement, "set_stance")
Interception.Restore(CopMovement, "set_stance_by_code")
Interception.Restore(CopLogicInactive, "_set_interaction")
Interception.Restore(CopMovement, "set_allow_fire")
Interception.Restore(CopMovement, "set_allow_fire_on_client")
Interception.Restore(CopMovement, "action_request")
Interception.Restore(CopLogicArrest, "_say_call_the_police")
Interception.Restore(CopMovement, "on_suppressed")
Interception.Restore(CopLogicBase, "_get_logic_state_from_reaction")
Interception.Restore(CopLogicIdle, "on_alert")
Interception.Restore(GroupAIStateBase, "on_police_called")
Interception.Restore(GroupAIStateBase, "on_police_weapons_hot")
Interception.Restore(GroupAIStateBase, "on_gangster_weapons_hot")
Interception.Restore(GroupAIStateBase, "on_enemy_weapons_hot")
Interception.Restore(GroupAIStateBase, "add_alert_listener")
Interception.Restore(GroupAIStateBase, "criminal_spotted")
Interception.Restore(GroupAIStateBase, "report_aggression")
Interception.Restore(GroupAIStateBase, "propagate_alert")
Interception.Restore(GroupAIStateBase, "on_criminal_suspicion_progress")
Interception.Restore(PlayerMovement, "on_suspicion")
Interception.Restore(SecurityCamera, "_upd_suspicion")
Interception.Restore(SecurityCamera, "_sound_the_alarm")
Interception.Restore(SecurityCamera, "_set_suspicion_sound")

if managers.hud then
managers.hud:show_hint( { text = "No Alarm Mode Dectivated!" } )
end

end



Also here is the crash report:
Code:
Application has crashed: C++ exception
[string "lib/units/enemies/cop/copbrain.lua"]:283: attempt to index local 'logic' (a nil value)
Which refers to this:
Code:
function CopBrain:set_logic( name, enter_params )
    local logic = self._logics[ name ]
    local l_data = self._logic_data
    l_data.t = self._timer:time()
    l_data.dt = self._timer:delta_time()
    self._current_logic.exit( l_data, name, enter_params )
    l_data.name = name
    l_data.logic = logic
    self._current_logic = logic
    self._current_logic_name = name
    logic.enter( l_data, name, enter_params ) -- line 283
end
Feel free to try it out yourself. It is mostly working.(not sure about multiplayer yet though)
I know it may be a little challenging or boring to read through this but any information/fixes you have would be great