Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. function widget:GetInfo()
  2.   return {
  3.     name      = "attack warning",
  4.     desc      = "warns if stuff gets attacked",
  5.     author    = "knorke",
  6.     date      = "Oct 2011",
  7.     license   = "GNU GPL, v2 or later or horse",
  8.     layer     = 0,
  9.     enabled   = true,
  10.   }
  11. end
  12.  
  13. local warningDelay = 30 * 5     --in frames
  14. local lastWarning = 0           --in frames
  15. local localTeamID = Spring.GetLocalTeamID ()
  16.  
  17. function widget:UnitDamaged (unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam)
  18.     local currentFrame = Spring.GetGameFrame ()
  19.     if (lastWarning+warningDelay > currentFrame) then      
  20.         return
  21.     end
  22.     if (localTeamID==unitTeam and not Spring.IsUnitInView (unitID)) then
  23.         lastWarning = currentFrame
  24.         local attackedUnit = unitName (unitID) or "Unit"
  25.         Spring.Echo ("-> " .. attackedUnit  .." is being attacked!")
  26.         --Spring.PlaySoundFile (blabla attack.wav, ... "userinterface")
  27.         local x,y,z = Spring.GetUnitPosition (unitID)
  28.         if (x and y and z) then Spring.SetLastMessagePosition (x,y,z) end
  29.     end
  30. end
  31.  
  32. function unitName (unitID)
  33.     if (not unitID) then return nil end
  34.     local unitDefID = Spring.GetUnitDefID(unitID)
  35.     if (unitDefID) then
  36.         local unitDef = UnitDefs[unitDefID]
  37.         if (unitDef) then
  38.             return unitDef.humanName
  39.         end
  40.     end
  41.     return nil
  42. end
  43.  
  44. --changing teams, rejoin, becoming spec etc
  45. function widget:PlayerChanged (playerID)
  46.     localTeamID = Spring.GetLocalTeamID () 
  47. end
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement