xponen

Store radar contact info

Feb 1st, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local dots = {} --//variable: store enemy position.
  2. local dotsEnterLos = {} --//variable: remember if enemy is in LOS.
  3.  
  4. function widget:UnitEnteredRadar(unitID, allyTeam)
  5.     dots[unitID] = {wasInLOS=false}--store something something
  6.     if (dotsEnterLos[unitID] == true) then
  7.         dots[unitID].wasInLOS = true
  8.     end
  9. end
  10.  
  11. function widget:UnitLeftRadar(unitID, allyTeam)
  12.     dots[unitID] = nil
  13. end
  14.  
  15. function widget:UnitEnteredLos(unitID, allyTeam )
  16.     dotsEnterLos[unitID] = true
  17.     if ( dots[unitID] ~= nil ) then
  18.         dots[unitID].wasInLOS = true
  19.     end
  20. end
  21.  
  22. function widget:UnitLeftLos(unitID, allyTeam)
  23.     dotsEnterLos[unitID] = nil
  24. end
  25.  
  26. function widget:Update(n)
  27.     for unitID, content in pairs(dots) do --//iterate over all dots and draw them
  28.         if (dotsEnterLos[unitID] == nil) then
  29.             local x, y, z = spGetUnitPosition(unitID)
  30.             if x == nil then
  31.                 dots[unitID] = nil
  32.                 Spring.Echo("I am non-existent!")
  33.             else
  34.                 if content.wasInLOS then
  35.                     Spring.Echo("I am identified radar contact!")
  36.                 else
  37.                     Spring.Echo("I am UN-identified radar contact!")
  38.                 end
  39.             end
  40.         else
  41.             Spring.Echo("I am Visible to naked eye!")
  42.         end
  43.     end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment