stoneharry

Untitled

Dec 18th, 2011
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.35 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.                 -- Get center point
  38.                 local x3 = Snow.A:GetX() - ((Snow.A:GetX() - Snow.B:GetX()) / 2)
  39.                 local y3 = Snow.A:GetY() - ((Snow.A:GetY() - Snow.B:GetY()) / 2)
  40.                 local plr = pUnit:GetClosestPlayer()
  41.                 if plr ~= nil then
  42.                     plr:SetPosition(x3, y3, pUnit:GetLandHeight(x3, y3), plr:GetO())
  43.                     plr:Root()
  44.                     pUnit:SendChatMessage(42,0,"Hit the snowmen with snowballs before they hit you, when they attack!")
  45.                     if plr:GetItemCount(17202) < 20 then
  46.                         plr:AddItem(17202, 20) -- snowballs
  47.                     end
  48.                 end
  49.                 Snow.i = 0
  50.                 pUnit:RegisterEvent("HandleSnowmanEventRepeat", 2500, 1)
  51.             end
  52.         end
  53.     end
  54. end
  55.  
  56. function PlayerIsNear(pUnit)
  57.     local plr = pUnit:GetClosestPlayer()
  58.     if plr ~= nil then
  59.         if plr:GetDistanceYards(pUnit) < 10 then
  60.             return true
  61.         end
  62.     end
  63.     return false
  64. end
  65.  
  66. function CheckSnowmenAreValid(pUnit)
  67.     if Snow.A ~= nil and Snow.B ~= nil and Snow.C ~= nil and Snow.D ~= nil then
  68.         return true
  69.     else
  70.         error("Four 'Strange Snowman' were not found. The Snow Man Event cannot continue.")
  71.         return false
  72.     end
  73. end
  74.  
  75. function HandleSnowmanEventRepeat(pUnit)
  76.     Snow.C:MoveTo(Snow.B:GetX(), Snow.B:GetY(), Snow.B:GetZ(), 0)
  77.     Snow.B:MoveTo(Snow.D:GetX(), Snow.D:GetY(), Snow.D:GetZ(), 0)
  78.     Snow.A:MoveTo(Snow.C:GetX(), Snow.C:GetY(), Snow.C:GetZ(), 0)
  79.     Snow.D:MoveTo(Snow.A:GetX(), Snow.A:GetY(), Snow.A:GetZ(), 0)
  80.     if Snow.i < 4 then
  81.         pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
  82.     elseif Snow.i == 4 then
  83.         Snow.current = GetRandomSnowman(pUnit)
  84.         Snow.current:CastSpell(20374) -- mark self
  85.         pUnit:SendChatMessage(42,0,"One of the snowmen is preparing to hit you, get him first!")
  86.         pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
  87.     elseif Snow.i == 5 then
  88.         pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
  89.     elseif Snow.i == 6 then
  90.         if WhoGotHitFirst(pUnit) then
  91.             pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
  92.         end
  93.         Snow.hit = false -- reset for next event
  94.         Snow.current = nil
  95.     elseif Snow.i == 7 then
  96.         Snow.current = GetRandomSnowman(pUnit)
  97.         Snow.current:CastSpell(20374) -- mark self
  98.         pUnit:SendChatMessage(42,0,"One of the snowmen is preparing to hit you, get him first!")
  99.         pUnit:RegisterEvent("HandleSnowmanEventRepeat", math.random(1000,6000), 1)
  100.     elseif Snow.i == 8 then
  101.         if WhoGotHitFirst(pUnit) then
  102.             Snow.i = 6
  103.             pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
  104.         end
  105.         Snow.hit = false -- reset for next event
  106.         Snow.current = nil
  107.     end
  108.     Snow.i = Snow.i + 1
  109. end
  110.  
  111. function GetRandomSnowman(pUnit)
  112.     local choice = math.random(1,4)
  113.     if choice == 1 then
  114.         return Snow.A
  115.     elseif choice == 2 then
  116.         return Snow.B
  117.     elseif choice == 3 then
  118.         return Snow.C
  119.     elseif choice == 4 then
  120.         return Snow.D
  121.     end
  122. end
  123.  
  124. function WhoGotHitFirst(pUnit)
  125.     if Snow.hit then
  126.         return true
  127.     else
  128.         if Snow.points == nil then
  129.             Snow.points = 0
  130.         end
  131.         pUnit:SendChatMessage(42,0,"You have lost the game with " ..Snow.points.." points!")
  132.         local plr = Snow.current:GetClosestPlayer()
  133.         if plr ~= nil then
  134.             Snow.current:CastSpellOnTarget(21343, plr) -- snowball
  135.             plr:Unroot()
  136.             if Snow.points > 2 then -- badge of justice rewards
  137.                 plr:AddItem(29434, 1)
  138.                 pUnit:SendChatMessageToPlayer(42,0,"You have been rewarded with 1 \124cffa335ee\124Hitem:29434:0:0:0:0:0:0:0:0\124h[Badge of Justice]\124h\124r!", plr)
  139.             elseif Snow.points > 5 then
  140.                 plr:AddItem(29434, 3)
  141.                 pUnit:SendChatMessageToPlayer(42,0,"You have been rewarded with 3 \124cffa335ee\124Hitem:29434:0:0:0:0:0:0:0:0\124h[Badge of Justice]\124h\124r!", plr)
  142.             elseif Snow.points > 9 then
  143.                 plr:AddItem(29434, 5)
  144.                 pUnit:SendChatMessageToPlayer(42,0,"You have been rewarded with 5 \124cffa335ee\124Hitem:29434:0:0:0:0:0:0:0:0\124h[Badge of Justice]\124h\124r!", plr)
  145.             end
  146.         end
  147.         Snow.current:RemoveAura(20374) -- reset arrow marker
  148.         Snow.A:SetScale(1)
  149.         Snow.B:SetScale(1)
  150.         Snow.C:SetScale(1)
  151.         Snow.D:SetScale(1)
  152.         Snow.A:Despawn(1000, 10000)
  153.         Snow.B:Despawn(1000, 10000)
  154.         Snow.C:Despawn(1000, 10000)
  155.         Snow.D:Despawn(1000, 10000)
  156.         Snow.current = nil
  157.         Snow.points = nil
  158.         RegisterTimedEvent("ResetSnowmenGuys", 12500, 1)
  159.         return false
  160.     end
  161. end
  162.  
  163. function ResetSnowmenGuys()
  164.     Snow.A:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0) -- random time so that functions are called seperately
  165.     Snow.B:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0)
  166.     Snow.C:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0)
  167.     Snow.D:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0)
  168.     Snow.A = nil
  169.     Snow.B = nil
  170.     Snow.C = nil
  171.     Snow.D = nil
  172. end
  173.  
  174. RegisterUnitEvent(13636, 18, "SnowManStrangeOnSpawn")
  175.  
  176. function GetSnowballCast(event, plr, spellid)
  177.     if spellid == 21343 then -- snowball thrown
  178.         if Snow.i > 0 then -- event is in progress
  179.             if Snow.current ~= nil then
  180.                 if plr:GetSelection() ~= nil then
  181.                     if tostring(plr:GetSelection()) == tostring(Snow.current) then
  182.                         if plr:IsInFront(Snow.current) then
  183.                             if not Snow.hit then
  184.                                 if Snow.points == nil then
  185.                                     Snow.points = 1
  186.                                 else
  187.                                     Snow.points = Snow.points + 1
  188.                                 end
  189.                                 Snow.current:RemoveAura(20374) -- reset arrow marker
  190.                                 if math.random(1,2) == 1 then
  191.                                     Snow.current:SendChatMessage(12,0,"No fair!")
  192.                                 else
  193.                                     Snow.current:SendChatMessage(12,0,"That didn't happen!")
  194.                                 end
  195.                             end
  196.                             Snow.hit = true
  197.                         end
  198.                     end
  199.                 end
  200.             end
  201.         end
  202.     end
  203. end
  204.  
  205. RegisterServerHook(10, "GetSnowballCast")
Advertisement
Add Comment
Please, Sign In to add comment