Guest User

Untitled

a guest
Oct 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. TrashMobs = {FrostGiant={}};    -- Don't pollute global namespace
  2. local L = TrashMobs;            -- indexed global variables are cheaper than non-indexed ones.
  3.  
  4.  
  5. -- Mob;
  6. -- Casts Mortal Strike (43441) on Main Target - every 8 sec
  7. -- Charges (56104) a random target - 15 sec
  8. function L.FrostGiant.OnCombat(pUnit)
  9.     L.FrostGiant[pUnit:GetGUID()] = { m_lastTarget = nil; };
  10.    
  11.     pUnit:RegisterEvent(
  12.         function(pUnit)
  13.             if pUnit ~= nil and pUnit:GetMainTank() ~= nil then
  14.                 pUnit:CastSpellOnTarget( pUnit:GetMainTank(), 43441 );
  15.             end
  16.         end, 8000, 0
  17.     );
  18.     pUnit:RegisterEvent(
  19.         function(pUnit)
  20.             -- the following REALLY isn't necessary unlses you absolutely positively do not want it to cast on the previous target.
  21.             local i= 0;
  22.             local t = pUnit:GetRandomPlayer(7);
  23.             while t:GetName() == L.FrostGiant[pUnit:GetGUID()].m_lastTarget do
  24.                 t = pUnit:GetRandomPlayer(7);
  25.                 i = i +1;
  26.                 if i > 3 then -- if 3 iterations and no new player, break and cast on mt
  27.                     t = pUnit:GetMainTank();
  28.                     break;
  29.                 end
  30.             end
  31.             if pUnit ~= nil and t ~= nil then
  32.                 pUnit:CastSpellOnTarget( t, 56104 );
  33.             end
  34.         end, 15000, 0
  35.     );
  36. end
  37. function L.FrostGiant.OnLeaveCombat(pUnit)
  38.     pUnit:RemoveEvents();
  39.     L.FrostGiant[pUnit:GetGUID()] = nil;
  40. end
  41. function L.FrostGiant.OnDeath(pUnit)
  42.     pUnit:RemoveEvents();
  43.     L.FrostGiant[pUnit:GetGUID()] = nil;
  44. end
  45. RegisterUnitEvent(90098, 1, L.FrostGiant.OnCombat);
  46. RegisterUnitEvent(90098, 2, L.FrostGiant.OnLeaveCombat);
  47. RegisterUnitEvent(90098, 4, L.FrostGiant.OnDeath);
Add Comment
Please, Sign In to add comment