Advertisement
Guest User

Lua 1v1 arena script

a guest
Jan 4th, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. --[[
  2.     Script made by Blyitgen @ AC-Web.org
  3.     These credits must stay in place!
  4. ]]
  5.  
  6. -- Variables
  7. local NPC = 78000  -- NPC entry for gossip
  8.  
  9. local m1,x1,y1,z1 = 1.1, 1.2, 1.3, 1.4 -- Location for Player 1
  10. local m2,x2,y2,z2 = 1.1, 1.2, 1.3, 1.4 -- Location for Player 2
  11.  
  12. local am,ax,ay,az = 1.1, 1.2, 1.3, 1.4 -- Location after arena for alliance
  13. local hm,hx,hy,hz = 1.1, 1.2, 1.3, 1.4 -- Location after arena for horde
  14.  
  15. local reward = 125                     -- Reward (in honor) for the winner
  16.  
  17. local started = false                  -- Status of the arena (false = not started, true = started)
  18.  
  19. local p1 = {}
  20. local p2 = {}
  21.  
  22. local t1,t2 = false, false
  23.  
  24. -- Custom Functions
  25.  
  26. local function endArena()
  27.     local p1t = p1[t1]:getTeam()
  28.     local p2t = p2[t2]:getTeam()
  29.    
  30.     if(p1t == 1) then
  31.         p1[t1]:Teleport(hm,hx,hy,hz)
  32.     else
  33.         p1[t1]:Teleport(am,ax,ay,az)
  34.     end
  35.    
  36.     if(p2t == 1) then
  37.         p2[t2]:Teleport(hm,hx,hy,hz)
  38.     else
  39.         p2[t2]:Teleport(am,ax,ay,az)
  40.     end
  41.    
  42.     table.remove(p1,t1)
  43.     table.remove(p2,t2)
  44.     started = false
  45. end
  46.  
  47. local function checkArena()
  48.     if(started) then
  49.         if(t1 and t2) then
  50.             if(p1[t1]:isDead()) then
  51.                 p2[t2]:SendBroadcastMessage("Congratulations! You won "..reward.." honor!")
  52.                 p1[t1]:SendBroadcastMessage("You can do better than that.")
  53.                 p2[t2]:giveHonor(reward)
  54.                 p1[t1]:ResurrectPlayer()
  55.                 endArena()
  56.             elseif(p2[t2]:isDead()) then
  57.                 p1[t1]:SendBroadcastMessage("Congratulations! You won "..reward.." honor!")
  58.                 p2[t2]:SendBroadcastMessage("You can do better than that.")
  59.                 p1[t1]:giveHonor(reward)
  60.                 p2[t2]:ResurrectPlayer()
  61.                 endArena()
  62.             end
  63.         end
  64.     end
  65. end
  66.  
  67. local function getRandom(array)
  68.     local size = #array
  69.     if(size == 0) then
  70.         return false
  71.     elseif(size > 1) then
  72.         return math.random(1,size)
  73.     elseif(size == 1) then
  74.         return 1
  75.     end
  76. end
  77.  
  78. local function sendPlayers()
  79.     if(started == false) then
  80.         t1 = getRandom(p1)
  81.         t2 = getRandom(p2)
  82.        
  83.         if(t1 and t2) then
  84.             p1[t1]:Teleport(m1,x1,y1,z1,0)
  85.             p2[t2]:Teleport(m2,x2,y2,z2,0)
  86.            
  87.             started = true
  88.         end
  89.     end
  90. end
  91.  
  92. local function addPlayer(player,unit)
  93.     local p1s = #p1
  94.     local p2s = #p2
  95.     if (p1s > p2s)  then
  96.         table.insert(p2, player)
  97.     elseif(p1s < p2s or p1s = p2s) then
  98.         table.insert(p1, player)
  99.     end
  100.     player:SendBroadcastMessage("You are now added to the queue! Good luck!")
  101. end
  102.  
  103. local function Hello(Unit, Event, player)
  104.     Unit:GossipCreateMenu(100, player, 0)
  105.    
  106.     Unit:GossipMenuAddItem(6, "Add me to the queue!", 1)
  107.     Unit:GossipMenuAddItem(7, "Nevermind", 2)
  108.    
  109.     Unit:GossipSendMenu(player)
  110. end
  111.  
  112. local function Select(Unit, Event, player, id, intid, code, pMisc)
  113.     if(intid == 1) then
  114.         addPlayer(player)
  115.     end
  116.     player:GossipComplete()
  117. end
  118.  
  119. -- Registers
  120. RegisterTimedEvent("sendPlayers", 30000, 0)
  121. RegisterTimedEvent("checkArena",   5000, 0)
  122. RegisterUnitGossipEvent(NPC, 1, Hello)
  123. RegisterUnitGossipEvent(NPC, 2, Select)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement