local function removeCallbacks(player, callbacks) if not IsValid(player) then return end for _, callbackId in pairs(callbacks) do player:RemoveCallback(callbackId) end end function FrontierGainOnTeammateDeath(_, activator) local callbacks = {} local check local terminated = false anyonediedCallback = AddEventCallback("player_death", function(eventTable) local victim = Entity(eventTable.victim_entindex) local victimPos = victim:GetAbsOrigin() local activatorPos = activator:GetAbsOrigin() if victim == activator then terminate(anyonediedCallback) anyonediedCallback = nil return end if victim.m_iTeamNum == activator.m_iTeamNum and victimPos:Distance(activatorPos) < 600 then activator.m_iRevengeCrits = activator.m_iRevengeCrits + 2 local allPlayers = ents.GetAllPlayers() for _, player in pairs(allPlayers) do player:AcceptInput("$PlaySoundToSelf", "weapons/widow_maker_dry_fire.wav") end local teleParticle = ents.CreateWithKeys("info_particle_system", { effect_name = "teleportedin_blue", start_active = 1, flag_as_weather = 0, }, true, true) teleParticle:SetAbsOrigin(activator:GetAbsOrigin()) teleParticle:Start() timer.Simple(1, function () teleParticle:Remove() end) end end) local function terminate(eventcallback) if terminated then return end terminated = true timer.Stop(check) removeCallbacks(activator, callbacks) RemoveEventCallback(eventcallback) eventcallback = nil end check = timer.Create(0.015, function() if not IsValid(activator) or not activator:IsAlive() then terminate(anyonediedCallback) return end end, 0) callbacks.died = activator:AddCallback(ON_DEATH, function() terminate(anyonediedCallback) anyonediedCallback = nil end) callbacks.removed = activator:AddCallback(ON_REMOVE, function() terminate(anyonediedCallback) anyonediedCallback = nil end) callbacks.spawned = activator:AddCallback(ON_SPAWN, function() terminate(anyonediedCallback) anyonediedCallback = nil end) end