Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- By Stoneharry
- local Snow = {}
- function SnowManStrangeOnSpawn(pUnit, Event)
- pUnit:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0) -- random time so that functions are called seperately
- end
- function HookTheSnowmenIntoOrder(pUnit)
- if Snow.A == nil then
- if PlayerIsNear(pUnit) then
- pUnit:RemoveEvents()
- pUnit:SetScale(2)
- Snow.A = pUnit
- Snow.B = nil
- Snow.C = nil
- Snow.D = nil
- for k,Unit in pairs(pUnit:GetInRangeUnits()) do
- if Unit:GetEntry() == 13636 then
- if Snow.B == nil then
- Unit:SetScale(2)
- Unit:RemoveEvents()
- Snow.B = Unit
- elseif Snow.C == nil then
- Unit:SetScale(2)
- Unit:RemoveEvents()
- Snow.C = Unit
- elseif Snow.D == nil then
- Unit:SetScale(2)
- Unit:RemoveEvents()
- Snow.D = Unit
- end
- end
- end
- if CheckSnowmenAreValid(pUnit) then
- Snow.i = 0
- pUnit:RegisterEvent("HandleSnowmanEventRepeat", 2500, 1)
- end
- end
- end
- end
- function PlayerIsNear(pUnit)
- local plr = pUnit:GetClosestPlayer()
- if plr ~= nil then
- if plr:GetDistanceYards(pUnit) < 10 then
- return true
- end
- end
- return false
- end
- function CheckSnowmenAreValid(pUnit)
- if Snow.A ~= nil and Snow.B ~= nil and Snow.C ~= nil and Snow.D ~= nil then
- return true
- else
- error("Four 'Strange Snowman' were not found. The Snow Man Event cannot continue.")
- return false
- end
- end
- function HandleSnowmanEventRepeat(pUnit)
- Snow.C:MoveTo(Snow.B:GetX(), Snow.B:GetY(), Snow.B:GetZ(), 0)
- Snow.B:MoveTo(Snow.D:GetX(), Snow.D:GetY(), Snow.D:GetZ(), 0)
- Snow.A:MoveTo(Snow.C:GetX(), Snow.C:GetY(), Snow.C:GetZ(), 0)
- Snow.D:MoveTo(Snow.A:GetX(), Snow.A:GetY(), Snow.A:GetZ(), 0)
- if Snow.i < 4 then
- pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
- elseif Snow.i == 4 then
- Snow.current = GetRandomSnowman(pUnit)
- Snow.current:CastSpell(20374) -- mark self
- pUnit:SendChatMessage(42,0,"One of the snowmen is preparing to hit you, get him first!")
- pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
- elseif Snow.i == 5 then
- pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
- elseif Snow.i == 6 then
- Snow.current:RemoveAura(20374) -- reset arrow marker
- if WhoGotHitFirst(pUnit) then
- pUnit:SendChatMessage(12,0,"Well done.")
- -- player got the hit
- else
- Snow.hit = false -- reset for next event
- end
- Snow.current = nil
- end
- Snow.i = Snow.i + 1
- end
- function GetRandomSnowman(pUnit)
- local choice = math.random(1,4)
- if choice == 1 then
- return Snow.A
- elseif choice == 2 then
- return Snow.B
- elseif choice == 3 then
- return Snow.C
- elseif choice == 4 then
- return Snow.D
- end
- end
- function WhoGotHitFirst(pUnit)
- if Snow.hit then
- return true
- else
- pUnit:SendChatMessage(42,0,"You have lost the game!")
- Snow.A:Despawn(1000, 10000)
- Snow.B:Despawn(1000, 10000)
- Snow.C:Despawn(1000, 10000)
- Snow.D:Despawn(1000, 10000)
- RegisterTimedEvent("ResetSnowmenGuys", 12500, 1)
- return false
- end
- end
- function ResetSnowmenGuys()
- Snow.A:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0) -- random time so that functions are called seperately
- Snow.B:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0)
- Snow.C:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0)
- Snow.D:RegisterEvent("HookTheSnowmenIntoOrder", math.random(1000,5000), 0)
- Snow.A = nil
- Snow.B = nil
- Snow.C = nil
- Snow.D = nil
- end
- RegisterUnitEvent(13636, 18, "SnowManStrangeOnSpawn")
- function GetSnowballCast(event, plr, spellid)
- if spellid == 21343 then -- snowball thrown
- if Snow.i > 0 then -- event is in progress
- if plr:GetSelection() ~= nil then
- if plr:GetSelection():GetGUID() == Snow.current:GetGUID() then
- Snow.hit = true
- end
- end
- end
- end
- end
- RegisterServerHook(10, "GetSnowballCast")
Advertisement
Add Comment
Please, Sign In to add comment