From 8a3120be39683332180dae673875e7e6ae6b1cd9 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sat, 19 Feb 2022 13:26:02 +0100 Subject: [PATCH] AUTOLASE - added nil check for CanLase() --- .../Moose/Functional/Autolase.lua | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Moose Development/Moose/Functional/Autolase.lua b/Moose Development/Moose/Functional/Autolase.lua index 606f9c94b..b67313f44 100644 --- a/Moose Development/Moose/Functional/Autolase.lua +++ b/Moose Development/Moose/Functional/Autolase.lua @@ -674,25 +674,27 @@ end function AUTOLASE:CanLase(Recce,Unit) local canlase = false -- cooldown? - local name = Recce:GetName() - local cooldown = self.RecceUnits[name].cooldown and self.forcecooldown - if cooldown then - local Tdiff = timer.getAbsTime() - self.RecceUnits[name].timestamp - if Tdiff < self.cooldowntime then - return false - else - self.RecceUnits[name].cooldown = false + if Recce and Recce:IsAlive() == true then + local name = Recce:GetName() + local cooldown = self.RecceUnits[name].cooldown and self.forcecooldown + if cooldown then + local Tdiff = timer.getAbsTime() - self.RecceUnits[name].timestamp + if Tdiff < self.cooldowntime then + return false + else + self.RecceUnits[name].cooldown = false + end + end + -- calculate LOS + local reccecoord = Recce:GetCoordinate() + local unitcoord = Unit:GetCoordinate() + local islos = reccecoord:IsLOS(unitcoord,2.5) + -- calculate distance + local distance = math.floor(reccecoord:Get3DDistance(unitcoord)) + local lasedistance = self:GetLosFromUnit(Recce) + if distance <= lasedistance and islos then + canlase = true end - end - -- calculate LOS - local reccecoord = Recce:GetCoordinate() - local unitcoord = Unit:GetCoordinate() - local islos = reccecoord:IsLOS(unitcoord,2.5) - -- calculate distance - local distance = math.floor(reccecoord:Get3DDistance(unitcoord)) - local lasedistance = self:GetLosFromUnit(Recce) - if distance <= lasedistance and islos then - canlase = true end return canlase end