stoneharry

Untitled

Dec 18th, 2011
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.84 KB | None | 0 0
  1.  
  2. -- By Stoneharry
  3.  
  4. local Snow = {}
  5.  
  6. function SnowManStrangeOnSpawn(pUnit, Event)
  7.     pUnit:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0) -- random time so that functions are called seperately
  8. end
  9.  
  10. function HookTheSnowmenIntoOrder(pUnit)
  11.     if Snow.A == nil then
  12.         if PlayerIsNear(pUnit) then
  13.             pUnit:RemoveEvents()
  14.             pUnit:SetScale(2)
  15.             Snow.A = pUnit
  16.             Snow.B = nil
  17.             Snow.C = nil
  18.             Snow.D = nil
  19.             for k,Unit in pairs(pUnit:GetInRangeUnits()) do
  20.                 if Unit:GetEntry() == 13636 then
  21.                     if Snow.B == nil then
  22.                         Unit:SetScale(2)
  23.                         Unit:RemoveEvents()
  24.                         Snow.B = Unit
  25.                     elseif Snow.C == nil then
  26.                         Unit:SetScale(2)
  27.                         Unit:RemoveEvents()
  28.                         Snow.C  = Unit
  29.                     elseif Snow.D == nil then
  30.                         Unit:SetScale(2)
  31.                         Unit:RemoveEvents()
  32.                         Snow.D = Unit
  33.                     end
  34.                 end
  35.             end
  36.             if CheckSnowmenAreValid(pUnit) then
  37.                 Snow.i = 0
  38.                 pUnit:RegisterEvent("HandleSnowmanEventRepeat", 2500, 1)
  39.             end
  40.         end
  41.     end
  42. end
  43.  
  44. function PlayerIsNear(pUnit)
  45.     local plr = pUnit:GetClosestPlayer()
  46.     if plr ~= nil then
  47.         if plr:GetDistanceYards(pUnit) < 10 then
  48.             return true
  49.         end
  50.     end
  51.     return false
  52. end
  53.  
  54. function CheckSnowmenAreValid(pUnit)
  55.     if Snow.A ~= nil and Snow.B ~= nil and Snow.C ~= nil and Snow.D ~= nil then
  56.         return true
  57.     else
  58.         error("Four 'Strange Snowman' were not found. The Snow Man Event cannot continue.")
  59.         return false
  60.     end
  61. end
  62.  
  63. function HandleSnowmanEventRepeat(pUnit)
  64.     Snow.C:MoveTo(Snow.B:GetX(), Snow.B:GetY(), Snow.B:GetZ(), 0)
  65.     Snow.B:MoveTo(Snow.D:GetX(), Snow.D:GetY(), Snow.D:GetZ(), 0)
  66.     Snow.A:MoveTo(Snow.C:GetX(), Snow.C:GetY(), Snow.C:GetZ(), 0)
  67.     Snow.D:MoveTo(Snow.A:GetX(), Snow.A:GetY(), Snow.A:GetZ(), 0)
  68.     if Snow.i < 4 then
  69.         pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
  70.     elseif Snow.i == 4 then
  71.         Snow.current = GetRandomSnowman(pUnit)
  72.         Snow.current:CastSpell(20374) -- mark self
  73.         pUnit:SendChatMessage(42,0,"One of the snowmen is preparing to hit you, get him first!")
  74.         pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
  75.     elseif Snow.i == 5 then
  76.         pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
  77.     elseif Snow.i == 6 then
  78.         Snow.current:RemoveAura(20374) -- reset arrow marker
  79.         if WhoGotHitFirst(pUnit) then
  80.             pUnit:SendChatMessage(12,0,"Well done.")
  81.             -- player got the hit
  82.         else
  83.             Snow.hit = false -- reset for next event
  84.         end
  85.         Snow.current = nil
  86.     end
  87.     Snow.i = Snow.i + 1
  88. end
  89.  
  90. function GetRandomSnowman(pUnit)
  91.     local choice = math.random(1,4)
  92.     if choice == 1 then
  93.         return Snow.A
  94.     elseif choice == 2 then
  95.         return Snow.B
  96.     elseif choice == 3 then
  97.         return Snow.C
  98.     elseif choice == 4 then
  99.         return Snow.D
  100.     end
  101. end
  102.  
  103. function WhoGotHitFirst(pUnit)
  104.     if Snow.hit then
  105.         return true
  106.     else
  107.         pUnit:SendChatMessage(42,0,"You have lost the game!")
  108.         Snow.A:Despawn(1000, 10000)
  109.         Snow.B:Despawn(1000, 10000)
  110.         Snow.C:Despawn(1000, 10000)
  111.         Snow.D:Despawn(1000, 10000)
  112.         RegisterTimedEvent("ResetSnowmenGuys", 12500, 1)
  113.         return false
  114.     end
  115. end
  116.  
  117. function ResetSnowmenGuys()
  118.     Snow.A:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0) -- random time so that functions are called seperately
  119.     Snow.B:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0)
  120.     Snow.C:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0)
  121.     Snow.D:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0)
  122.     Snow.A = nil
  123.     Snow.B = nil
  124.     Snow.C = nil
  125.     Snow.D = nil
  126. end
  127.  
  128. RegisterUnitEvent(13636, 18, "SnowManStrangeOnSpawn")
  129.  
  130. function GetSnowballCast(event, plr, spellid)
  131.     if spellid == 21343 then -- snowball thrown
  132.         if Snow.i > 0 then -- event is in progress
  133.             if plr:GetSelection() ~= nil then
  134.                 if plr:GetSelection():GetGUID() == Snow.current:GetGUID() then
  135.                     Snow.hit = true
  136.                 end
  137.             end
  138.         end
  139.     end
  140. end
  141.  
  142. RegisterServerHook(10, "GetSnowballCast")
Advertisement
Add Comment
Please, Sign In to add comment