stoneharry

Untitled

Jan 19th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.53 KB | None | 0 0
  1.  
  2. local can_start = false
  3.  
  4. local plrA = nil
  5. local plrB = nil
  6.  
  7. local resources_A = 0
  8. local resources_B = 0
  9.  
  10. local ax, ay, az = 16094, 15981, 0
  11. local bx, by, bz = 16060, 16077, 0
  12.  
  13. local TEAM_A_VISUAL = 52619
  14. local TEAM_B_VISUAL = 52670
  15.  
  16. function Event_Game_Minigame_A(pUnit, event, player)
  17.     pUnit:GossipCreateMenu(1, player, 0)
  18.     if can_start then
  19.         pUnit:GossipMenuAddItem(10, "A game is in progress.", 250, 0)
  20.     else
  21.         pUnit:GossipMenuAddItem(10, "Challenge a target player to a game.", 1, 0)
  22.     end
  23.     pUnit:GossipMenuAddItem(10, "Nevermind.", 250, 0)
  24.     pUnit:GossipSendMenu(player)
  25. end
  26.  
  27. function Event_Game_Minigame_B(pUnit, event, player, id, intid, code)
  28.     if intid == 1 then
  29.         local target = player:GetSelection()
  30.         if (target and target:IsPlayer() and target:GetName() ~= player:GetName() and can_start == false) then
  31.             plrA = player;
  32.             plrB = target
  33.             pUnit:SendChatMessage(42,0,"Player "..player:GetName().." has challenged "..plrB:GetName().." to a game!")
  34.             plrA:SendBroadcastMessage("[CU-ADDON] OpenMinigame")
  35.             plrB:SendBroadcastMessage("[CU-ADDON] OpenMinigame")
  36.             can_start = true
  37.         else
  38.             player:SendBroadcastMessage("Error: Target player was not found.")
  39.         end
  40.         player:GossipComplete()
  41.     elseif intid == 250 then
  42.         player:GossipComplete()
  43.     end
  44. end
  45.  
  46. RegisterUnitGossipEvent(400000, 1, "Event_Game_Minigame_A")
  47. RegisterUnitGossipEvent(400000, 2, "Event_Game_Minigame_B")
  48. RegisterUnitGossipEvent(400001, 1, "Event_Game_Minigame_A")
  49. RegisterUnitGossipEvent(400001, 2, "Event_Game_Minigame_B")
  50.  
  51. -- Update score
  52.  
  53. function UpdateScoreSpawn(pUnit, Event)
  54.     pUnit:RegisterEvent("Update_Player_Scores_Local", 1000, 0)
  55. end
  56.  
  57. function Update_Player_Scores_Local(pUnit)
  58.     if plrA and plrB then
  59.         resources_A = resources_A + 2
  60.         resources_B = resources_B + 2
  61.         plrA:SendBroadcastMessage("[CU-ADDON] minigame-resources : "..tostring(resources_A))
  62.         plrB:SendBroadcastMessage("[CU-ADDON] minigame-resources : "..tostring(resources_B))
  63.     end
  64. end
  65.  
  66. RegisterUnitEvent(400000, 18, "UpdateScoreSpawn")
  67.  
  68. -- Reset event
  69.  
  70. function ResetGame_Mini(pUnit, Event)
  71.     if plrA and plrB then
  72.         if pUnit:GetEntry() == 400000 then
  73.             pUnit:SendChatMessage(42,0,plrB:GetName().." has won!")
  74.         else
  75.             pUnit:SendChatMessage(42,0,plrA:GetName().." has won!")
  76.         end
  77.     end
  78.     for _,v in pairs(pUnit:GetInRangeUnits()) do
  79.         local entry = v:GetEntry()
  80.         if entry < 420000 and entry > 350000 then
  81.             if entry == 400000 or entry == 400001 then
  82.                 v:Despawn(5000, 30000)
  83.             else
  84.                 v:Despawn(1,0)
  85.             end
  86.         end
  87.     end
  88.     if plrA then
  89.         plrA:SendBroadcastMessage("[CU-ADDON] CloseMiniGame")
  90.     end
  91.     plrA = nil
  92.     if plrB then
  93.         plrB:SendBroadcastMessage("[CU-ADDON] CloseMiniGame")
  94.     end
  95.     plrB = nil
  96.     can_start = false
  97.     resources_A = 0
  98.     resources_B = 0
  99. end
  100.  
  101. RegisterUnitEvent(400001, 4, "ResetGame_Mini")
  102. RegisterUnitEvent(400000, 4, "ResetGame_Mini")
  103.  
  104. -- chat
  105.  
  106. function Minigame_Chat(event, plr, message, mtype, language)
  107.     if message ~= nil then
  108.         if message == "[CU-ADDON] SpawnWeakGhouls" then
  109.             if plrA and plrB then
  110.                 if plr:GetName() == plrA:GetName() then
  111.                     if resources_A > 4 then
  112.                         resources_A = resources_A - 5
  113.                         plrA:SendBroadcastMessage("[CU-ADDON] minigame-resources : "..tostring(resources_A))
  114.                         plr:SpawnCreature(399999, ax, ay, az, 0, 35, 120000)
  115.                     end
  116.                 elseif plr:GetName() == plrB:GetName() then
  117.                     if resources_B > 4 then
  118.                         resources_B = resources_B - 5
  119.                         plrB:SendBroadcastMessage("[CU-ADDON] minigame-resources : "..tostring(resources_B))
  120.                         plr:SpawnCreature(400002, bx, by, bz, 0, 35, 120000)
  121.                     end
  122.                 end
  123.             end
  124.         elseif message == "[CU-ADDON] SpawnSpellcaster" then
  125.             if plrA and plrB then
  126.                 if plr:GetName() == plrA:GetName() then
  127.                     if resources_A > 6 then
  128.                         resources_A = resources_A - 7
  129.                         plrB:SendBroadcastMessage("[CU-ADDON] minigame-resources : "..tostring(resources_B))
  130.                         plr:SpawnCreature(399998, ax, ay, az, 0, 35, 120000)
  131.                     end
  132.                 elseif plr:GetName() == plrB:GetName() then
  133.                     if resources_B > 6 then
  134.                         resources_B = resources_B - 7
  135.                         plr:SpawnCreature(400003, bx, by, bz, 0, 35, 120000)
  136.                     end
  137.                 end
  138.             end
  139.         elseif message == "[CU-ADDON] SpawnAbomination" then
  140.             if plrA and plrB then
  141.                 if plr:GetName() == plrA:GetName() then
  142.                     if resources_A > 49 then
  143.                         resources_A = resources_A - 50
  144.                         plrB:SendBroadcastMessage("[CU-ADDON] minigame-resources : "..tostring(resources_B))
  145.                         plr:SpawnCreature(399997, ax, ay, az, 0, 35, 120000)
  146.                     end
  147.                 elseif plr:GetName() == plrB:GetName() then
  148.                     if resources_B > 49 then
  149.                         resources_B = resources_B - 50
  150.                         plr:SpawnCreature(400004, bx, by, bz, 0, 35, 120000)
  151.                     end
  152.                 end
  153.             end
  154.         elseif message == "[CU-ADDON] TurretR" then
  155.             if plrA and plrB then
  156.                 if plr:GetName() == plrA:GetName() then
  157.                     if resources_A > 29 then
  158.                         resources_A = resources_A - 30
  159.                         plrB:SendBroadcastMessage("[CU-ADDON] minigame-resources : "..tostring(resources_B))
  160.                         plr:SpawnCreature(399995, ax+6, ay+6, az, 2.045725, 35, 300000)
  161.                     end
  162.                 elseif plr:GetName() == plrB:GetName() then
  163.                     if resources_B > 29 then
  164.                         resources_B = resources_B - 30
  165.                         plr:SpawnCreature(400005, bx+6, by-4, bz, 4.994109, 35, 300000)
  166.                     end
  167.                 end
  168.             end    
  169.         elseif message == "[CU-ADDON] TurretL" then
  170.             if plrA and plrB then
  171.                 if plr:GetName() == plrA:GetName() then
  172.                     if resources_A > 29 then
  173.                         resources_A = resources_A - 30
  174.                         plrB:SendBroadcastMessage("[CU-ADDON] minigame-resources : "..tostring(resources_B))
  175.                         plr:SpawnCreature(399995, ax-6, ay+6, az, 1.684442, 35, 300000)
  176.                     end
  177.                 elseif plr:GetName() == plrB:GetName() then
  178.                     if resources_B > 29 then
  179.                         resources_B = resources_B - 30
  180.                         plr:SpawnCreature(400005, bx-6, by-4, bz, 5.198315, 35, 300000)
  181.                     end
  182.                 end
  183.             end    
  184.         end
  185.     end
  186. end
  187.  
  188. RegisterServerHook(16, "Minigame_Chat")
  189.  
  190. function MeleeUnit_AI(pUnit, Event)
  191.     if Event == 18 then
  192.         pUnit:RegisterEvent("MeleeUnitAI_Tick", 1000, 0)
  193.         if pUnit:GetMana() > 0 then
  194.             pUnit:RegisterEvent("AI_SPELL_TICK", 4000, 0)
  195.         elseif pUnit:GetEntry() == 399997 or pUnit:GetEntry() == 400004 then
  196.             pUnit:RegisterEvent("Abomination_Cleave", 3000, 0)
  197.         end
  198.     else
  199.         pUnit:RemoveEvents()
  200.     end
  201. end
  202.  
  203. function MeleeUnitAI_Tick(pUnit)
  204.     if pUnit:IsInCombat() and pUnit:GetSelection() == nil then
  205.         return;
  206.     end
  207.     pUnit:SetMovementFlags(1)
  208.     local target = pUnit:GetValue("target")
  209.     if (target == nil or target:IsDead()) then
  210.         target = nil
  211.         local distance = 40
  212.         if pUnit:GetEntry() < 400001 then -- Team A
  213.             pUnit:CastSpell(TEAM_A_VISUAL)
  214.             for _,v in pairs(pUnit:GetInRangeUnits()) do
  215.                 if v:GetEntry() > 400000 and v:IsAlive() and v:IsCreature() then
  216.                     if v:GetDistanceYards(pUnit) < distance then
  217.                         distance = v:GetDistanceYards(pUnit)
  218.                         target = v
  219.                     end
  220.                 end
  221.             end
  222.             if (target == nil) then
  223.                 pUnit:MoveTo(bx, by, bz, 0)
  224.             end
  225.         else -- team B
  226.             pUnit:CastSpell(TEAM_B_VISUAL)
  227.             for _,v in pairs(pUnit:GetInRangeUnits()) do
  228.                 if v:GetEntry() < 400001 and v:IsAlive() and v:IsCreature() then
  229.                     if v:GetDistanceYards(pUnit) < distance then
  230.                         distance = v:GetDistanceYards(pUnit)
  231.                         target = v
  232.                     end
  233.                 end
  234.             end
  235.             if (target == nil) then
  236.                 pUnit:MoveTo(ax, ay, az, 0)
  237.             end
  238.         end
  239.     end
  240.     pUnit:SetValue("target", target)
  241.     if (target) then
  242.         local_attack(pUnit, target)
  243.     end
  244. end
  245.  
  246. function local_attack(pUnit, target)
  247.     pUnit:AttackReaction(target, 1, 0)
  248. end
  249.  
  250. function AI_SPELL_TICK(pUnit)
  251.     local target = pUnit:GetValue("spell_target")
  252.     if (target == nil or target:IsDead()) then
  253.         target = nil
  254.         local distance = 40
  255.         if pUnit:GetEntry() < 400001 then -- Team A
  256.             for _,v in pairs(pUnit:GetInRangeUnits()) do
  257.                 if v:GetEntry() > 400000 and v:IsAlive() and v:IsCreature() then
  258.                     if v:GetDistanceYards(pUnit) < distance then
  259.                         distance = v:GetDistanceYards(pUnit)
  260.                         target = v
  261.                     end
  262.                 end
  263.             end
  264.         else
  265.             for _,v in pairs(pUnit:GetInRangeUnits()) do
  266.                 if v:GetEntry() < 400001 and v:IsAlive() and v:IsCreature() then
  267.                     if v:GetDistanceYards(pUnit) < distance then
  268.                         distance = v:GetDistanceYards(pUnit)
  269.                         target = v
  270.                     end
  271.                 end
  272.             end
  273.         end
  274.     end
  275.     pUnit:SetValue("spell_target", target)
  276.     if target then
  277.         pUnit:CastSpellOnTarget(42319, target)
  278.         local damage = math.random(20,30)
  279.         if damage > target:GetHealth() then
  280.             target:Kill(target)
  281.         else
  282.             target:SetHealth(target:GetHealth()-damage)
  283.         end
  284.     end
  285. end
  286.  
  287. function Abomination_Cleave(pUnit)
  288.     local targets = pUnit:GetValue("cleave_targets")
  289.     local update = false
  290.     if (targets == nil) then
  291.         targets = {}
  292.         update = true
  293.     else
  294.         for i = 3, 1, -1 do
  295.             if (targets[i] == nil or targets[i]:IsDead()) then
  296.                 update = true
  297.                 table.remove(targets, i)
  298.             end
  299.         end
  300.     end
  301.     if (update) then
  302.         if pUnit:GetEntry() < 400001 then -- Team A
  303.             for _,v in pairs(pUnit:GetInRangeUnits()) do
  304.                 if v:GetEntry() > 400000 and v:IsAlive() and v:IsCreature() then
  305.                     if v:GetDistanceYards(pUnit) < 8 then
  306.                         if (#targets < 3 and isSame(v, targets[1]) == false and isSame(v, targets[2]) == false) then
  307.                             table.insert(targets, v)
  308.                             if (#targets == 3) then
  309.                                 break
  310.                             end
  311.                         end
  312.                     end
  313.                 end
  314.             end
  315.         else
  316.             for _,v in pairs(pUnit:GetInRangeUnits()) do
  317.                 if v:GetEntry() < 400001 and v:IsAlive() and v:IsCreature() then
  318.                     if v:GetDistanceYards(pUnit) < 8 then
  319.                         if (#targets < 3) then
  320.                             table.insert(targets, v)
  321.                             if (#targets == 3) then
  322.                                 break
  323.                             end
  324.                         end
  325.                     end
  326.                 end
  327.             end
  328.         end
  329.     end
  330.     if (0 < #targets) then
  331.         pUnit:SetValue("cleave_targets", targets)
  332.         pUnit:CastSpell(58913) -- visual
  333.         for i = 1, #targets do
  334.             local damage = i * 5 + math.random(0, 5)
  335.             local t = targets[i]
  336.             if (t:GetHealth() <= damage) then
  337.                 t:Kill(t)
  338.             else
  339.                 t:SetHealth(t:GetHealth() - damage)
  340.             end
  341.         end
  342.     end
  343. end
  344.  
  345. RegisterUnitEvent(399999, 18, "MeleeUnit_AI")
  346. RegisterUnitEvent(400002, 18, "MeleeUnit_AI")
  347. RegisterUnitEvent(399998, 18, "MeleeUnit_AI")
  348. RegisterUnitEvent(400003, 18, "MeleeUnit_AI")
  349. RegisterUnitEvent(399997, 18, "MeleeUnit_AI")
  350. RegisterUnitEvent(400004, 18, "MeleeUnit_AI")
  351.  
  352. RegisterUnitEvent(399999, 4, "MeleeUnit_AI")
  353. RegisterUnitEvent(400002, 4, "MeleeUnit_AI")
  354. RegisterUnitEvent(399998, 4, "MeleeUnit_AI")
  355. RegisterUnitEvent(400003, 4, "MeleeUnit_AI")
  356. RegisterUnitEvent(399997, 4, "MeleeUnit_AI")
  357. RegisterUnitEvent(400004, 4, "MeleeUnit_AI")
  358.  
  359. function TurretAI(pUnit, Event)
  360.     if Event == 18 then
  361.         pUnit:RegisterEvent("TurretAI_Tick", 2000, 0)
  362.     else
  363.         pUnit:RemoveEvents()
  364.     end
  365. end
  366.  
  367. function TurretAI_Tick(pUnit)
  368.     local target = nil
  369.     local distance = 20
  370.     if pUnit:GetEntry() < 400001 then -- Team A
  371.         for _,v in pairs(pUnit:GetInRangeUnits()) do
  372.             if v:GetEntry() > 400000 and v:IsAlive() and v:IsCreature() then
  373.                 if v:GetDistanceYards(pUnit) < distance then
  374.                     distance = v:GetDistanceYards(pUnit)
  375.                     target = v
  376.                 end
  377.             end
  378.         end
  379.     else
  380.         for _,v in pairs(pUnit:GetInRangeUnits()) do
  381.             if v:GetEntry() < 400001 and v:IsAlive() and v:IsCreature() then
  382.                 if v:GetDistanceYards(pUnit) < distance then
  383.                     target = v
  384.                 end
  385.             end
  386.         end
  387.     end
  388.     if target then
  389.         pUnit:CastSpellOnTarget(49687, target)
  390.         local damage = math.random(30,60)
  391.         if damage > target:GetHealth() then
  392.             target:Kill(target)
  393.         else
  394.             target:SetHealth(target:GetHealth()-damage)
  395.         end
  396.     end
  397. end
  398.  
  399. RegisterUnitEvent(399995, 4, "TurretAI")
  400. RegisterUnitEvent(400005, 4, "TurretAI")
  401. RegisterUnitEvent(399995, 18, "TurretAI")
  402. RegisterUnitEvent(400005, 18, "TurretAI")
Advertisement
Add Comment
Please, Sign In to add comment