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
- -- Get center point
- local x3 = Snow.A:GetX() - ((Snow.A:GetX() - Snow.B:GetX()) / 2)
- local y3 = Snow.A:GetY() - ((Snow.A:GetY() - Snow.B:GetY()) / 2)
- local plr = pUnit:GetClosestPlayer()
- if plr ~= nil then
- plr:SetPosition(x3, y3, pUnit:GetLandHeight(x3, y3), plr:GetO())
- plr:Root()
- pUnit:SendChatMessage(42,0,"Hit the snowmen with snowballs before they hit you, when they attack!")
- if plr:GetItemCount(17202) < 20 then
- plr:AddItem(17202, 20) -- snowballs
- end
- end
- 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
- if WhoGotHitFirst(pUnit) then
- pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
- end
- Snow.hit = false -- reset for next event
- Snow.current = nil
- elseif Snow.i == 7 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", math.random(1000,6000), 1)
- elseif Snow.i == 8 then
- if WhoGotHitFirst(pUnit) then
- Snow.i = 6
- pUnit:RegisterEvent("HandleSnowmanEventRepeat", 4500, 1)
- end
- Snow.hit = false -- reset for next event
- 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
- if Snow.points == nil then
- Snow.points = 0
- end
- pUnit:SendChatMessage(42,0,"You have lost the game with " ..Snow.points.." points!")
- local plr = Snow.current:GetClosestPlayer()
- if plr ~= nil then
- Snow.current:CastSpellOnTarget(21343, plr) -- snowball
- plr:Unroot()
- if Snow.points > 2 then -- badge of justice rewards
- plr:AddItem(29434, 1)
- 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)
- elseif Snow.points > 5 then
- plr:AddItem(29434, 3)
- 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)
- elseif Snow.points > 9 then
- plr:AddItem(29434, 5)
- 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)
- end
- end
- Snow.current:RemoveAura(20374) -- reset arrow marker
- Snow.A:SetScale(1)
- Snow.B:SetScale(1)
- Snow.C:SetScale(1)
- Snow.D:SetScale(1)
- Snow.A:Despawn(1000, 10000)
- Snow.B:Despawn(1000, 10000)
- Snow.C:Despawn(1000, 10000)
- Snow.D:Despawn(1000, 10000)
- Snow.current = nil
- Snow.points = nil
- 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 Snow.current ~= nil then
- if plr:GetSelection() ~= nil then
- if tostring(plr:GetSelection()) == tostring(Snow.current) then
- if plr:IsInFront(Snow.current) then
- if not Snow.hit then
- if Snow.points == nil then
- Snow.points = 1
- else
- Snow.points = Snow.points + 1
- end
- Snow.current:RemoveAura(20374) -- reset arrow marker
- if math.random(1,2) == 1 then
- Snow.current:SendChatMessage(12,0,"No fair!")
- else
- Snow.current:SendChatMessage(12,0,"That didn't happen!")
- end
- end
- Snow.hit = true
- end
- end
- end
- end
- end
- end
- end
- RegisterServerHook(10, "GetSnowballCast")
Add Comment
Please, Sign In to add comment