diff --git a/code/datums/proximity_trigger/proximity_trigger.dm b/code/datums/proximity_trigger/proximity_trigger.dm index a4ffa41bbf795..186d723246a06 100644 --- a/code/datums/proximity_trigger/proximity_trigger.dm +++ b/code/datums/proximity_trigger/proximity_trigger.dm @@ -84,8 +84,10 @@ var/global/const/PROXIMITY_EXCLUDE_HOLDER_TURF = 1 // When acquiring turfs to mo for(var/t in (turfs_in_range - new_turfs)) GLOB.opacity_set_event.unregister(t, src, /datum/proximity_trigger/proc/on_turf_visibility_changed) + GLOB.destroyed_event.unregister(t, src, /datum/proximity_trigger/proc/on_turf_destroyed) for(var/t in (new_turfs - turfs_in_range)) GLOB.opacity_set_event.register(t, src, /datum/proximity_trigger/proc/on_turf_visibility_changed) + GLOB.destroyed_event.register(t, src, /datum/proximity_trigger/proc/on_turf_destroyed) turfs_in_range = new_turfs on_turf_visibility_changed() @@ -97,14 +99,23 @@ var/global/const/PROXIMITY_EXCLUDE_HOLDER_TURF = 1 // When acquiring turfs to mo for(var/t in turfs_in_range) GLOB.opacity_set_event.unregister(t, src, /datum/proximity_trigger/proc/on_turf_visibility_changed) + GLOB.destroyed_event.unregister(t, src, /datum/proximity_trigger/proc/on_turf_destroyed) for(var/t in seen_turfs_) GLOB.entered_event.unregister(t, src, /datum/proximity_trigger/proc/on_turf_entered) + GLOB.destroyed_event.unregister(t, src, /datum/proximity_trigger/proc/on_turf_destroyed) call(proc_owner, on_turfs_changed)(seen_turfs_.Copy(), list()) turfs_in_range.Cut() seen_turfs_.Cut() +/datum/proximity_trigger/proc/on_turf_destroyed(turf/destroyed) + GLOB.opacity_set_event.unregister(destroyed, src, /datum/proximity_trigger/proc/on_turf_visibility_changed) + GLOB.entered_event.unregister(destroyed, src, /datum/proximity_trigger/proc/on_turf_entered) + GLOB.destroyed_event.unregister(destroyed, src, /datum/proximity_trigger/proc/on_turf_destroyed) + // The cycle of when things run mean this is one of the only ways to make sure we don't encounter the debug log spam + addtimer(new Callback(src, .proc/register_turfs), 1, TIMER_UNIQUE | TIMER_OVERRIDE) + /datum/proximity_trigger/proc/on_turf_visibility_changed() var/list/new_seen_turfs_ = get_seen_turfs() if(listequal(seen_turfs_, new_seen_turfs_))