• How to Delete WAC after submerging water?
    2 replies, posted
I'm having an issue where I cannot figure out how to delete a WAC vehicle such as a helicopter after it goes under the water. I found this in a few files i've had, but it really does nothing, and i'm not really surprised. [CODE]timer.Create("DeleteUnderwaterHeli", 59, 0, function() local tbl, class = ents.GetAll() for i=1, #tbl do class = tbl[i]:GetClass() for a=1, #flyVehClasses do if flyVehClasses[a] == class then local water = tbl[i]:WaterLevel() if water > 1 then if tbl[i].SubmergeTime and CurTime()-tbl[i].SubmergeTime > 180 then tbl[i]:Remove() else tbl[i].SubmergeTime = tbl[i].SubmergeTime or CurTime() end else tbl[i].SubmergeTime = nil end break end end end end)[/CODE]
That seems unnecessarily complicated. Try this: [code] timer.Create("DeleteUnderwaterHeli", 1, 0, function() for k,v in pairs(ents.GetAll()) do if table.HasValue(flyVehClasses, v:GetClass()) then if v:WaterLevel() > 1 and (v.SubmergeTime or 0) > 180 then SafeRemoveEntity(v) elseif v:WaterLevel() > 1 then v.SubmergeTime = (v.SubmergeTime or 0) + 1 else v.SubmergeTime = 0 end end end end) [/code]
Ah, thanks! I'll try it out in a bit!
Sorry, you need to Log In to post a reply to this thread.