kusanagy

lua zone battle world states

Nov 13th, 2019
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.40 KB | None | 0 0
  1. --[[ THIS SCRIPT REQUIRES THE WorldStateExtension! DOWNLOAD IT HERE: http://pastebin.com/VWLXjqcp]]
  2.  
  3. local ZoneBattles = {
  4.     ["BattleZone"] = {"Alterac Mountains", 0, 36}, -- Zone name, Map, ZoneId
  5.     ["Rewards"] = {1000, 20, 20560, 1}, -- Copper, Honor, ItemId, ItemCount
  6.     ["MaxScore"] = 2, -- Max score needed to win
  7.     ["Cooldown"] = 1, -- Cooldown in minutes
  8.     [0] = 0, -- Declare Alliance Score
  9.     [1] = 0; -- Declare Horde Score
  10. };
  11.  
  12. local function TeamAsString(team)
  13.     if (team == 0) then
  14.         return "Alliance";
  15.     else
  16.         return "Horde";
  17.     end
  18. end
  19.  
  20. local function HandleReward(player)
  21.     local MoneyReward = ZoneBattles["Rewards"][1];
  22.     local HonorReward = ZoneBattles["Rewards"][2];
  23.     local ItemReward, ItemRewardCount = ZoneBattles["Rewards"][3], ZoneBattles["Rewards"][4];
  24.  
  25.     for k, _ in pairs(ZoneBattles["BattleContribution"]) do
  26.         if (player:GetGUIDLow() == k) then
  27.             if (MoneyReward > 0) then -- Handle Money Reward
  28.                 player:ModifyMoney(MoneyReward)
  29.             end
  30.             if (HonorReward > 0) then -- Handle Honor Reward
  31.                 player:ModifyHonorPoints(HonorReward)
  32.             end
  33.             if (ItemReward > 0) and (ItemRewardCount > 0) then -- Handle Item/Token Reward
  34.                 player:AddItem(ItemReward, ItemRewardCount)
  35.             end
  36.         end
  37.     end
  38. end
  39.  
  40. function ZoneBattles.ResetBattleCounter()
  41.     -- Reset battle variables
  42.     ZoneBattles["BattleContribution"] = {};
  43.     ZoneBattles[0] = 0;
  44.     ZoneBattles[1] = 0;
  45.     ZoneBattles["BattleInProgress"] = true;
  46.    
  47.     for _, v in pairs(GetPlayersInMap(ZoneBattles["BattleZone"][2])) do
  48.         if (v:GetZoneId() == ZoneBattles["BattleZone"][3]) then
  49.             v:UpdateWorldState(2313, ZoneBattles[0]) -- Reset Alliance score when battle resets
  50.             v:UpdateWorldState(2314, ZoneBattles[1]) -- Reset Horde score when battle resets
  51.             v:SendBroadcastMessage("The Battle of "..ZoneBattles["BattleZone"][1].." has begun!")
  52.         end
  53.     end
  54. end
  55.  
  56. function ZoneBattles.OnEnterArea(event, player, newZone, newArea)
  57.     if (player:GetMapId() == ZoneBattles["BattleZone"][2]) and (player:GetZoneId() == ZoneBattles["BattleZone"][3]) then
  58.         player:InitializeWorldState(1, 1377, 0, 1) -- Initialize world state, score 0/0
  59.         player:UpdateWorldState(2317, ZoneBattles["MaxScore"]) -- Sets correct MaxScore
  60.         player:UpdateWorldState(2313, ZoneBattles[0]) -- Set correct Alliance score
  61.         player:UpdateWorldState(2314, ZoneBattles[1]) -- Set correct Horde score
  62.     end
  63. end
  64.  
  65. function ZoneBattles.OnPvPKill(event, killer, killed)
  66.     if ((killer:GetMapId() and killed:GetMapId()) == ZoneBattles["BattleZone"][2]) and ((killer:GetZoneId() and killed:GetZoneId()) == ZoneBattles["BattleZone"][3]) then
  67.         local Team = killer:GetTeam()
  68.  
  69.         if ZoneBattles[0] < ZoneBattles["MaxScore"] and ZoneBattles[1] < ZoneBattles["MaxScore"] then
  70.             if not ZoneBattles["BattleContribution"][killer:GetGUIDLow()] then
  71.                 ZoneBattles["BattleContribution"][killer:GetGUIDLow()] = true; -- Make sure player has contributed to the battle.
  72.             end
  73.  
  74.             ZoneBattles[Team] = ZoneBattles[Team] + 1;
  75.  
  76.             for _, v in pairs(GetPlayersInMap(ZoneBattles["BattleZone"][2])) do
  77.                 if v:GetZoneId() == ZoneBattles["BattleZone"][3] then
  78.                     v:UpdateWorldState(2313+Team, ZoneBattles[Team])
  79.                 end
  80.             end
  81.         end
  82.        
  83.         if ZoneBattles["BattleInProgress"] == true and ZoneBattles[Team] == ZoneBattles["MaxScore"] then
  84.             ZoneBattles["BattleInProgress"] = false;
  85.  
  86.             for _, v in pairs(GetPlayersInMap(ZoneBattles["BattleZone"][2])) do
  87.                 if v:GetZoneId() == ZoneBattles["BattleZone"][3] then
  88.                     if(v:GetTeam() == Team) then
  89.                         HandleReward(v)
  90.                     end
  91.                     v:SendBroadcastMessage("The "..TeamAsString(Team).." has won the Battle of "..ZoneBattles["BattleZone"][1].."! Next battle begins in "..ZoneBattles["Cooldown"].." minutes!")
  92.                 end
  93.             end
  94.  
  95.             CreateLuaEvent(ZoneBattles.ResetBattleCounter, ZoneBattles["Cooldown"]*60*1000, 1)
  96.         end
  97.     end
  98. end
  99.  
  100. ZoneBattles.ResetBattleCounter()
  101. RegisterPlayerEvent(27, ZoneBattles.OnEnterArea)
  102. RegisterPlayerEvent(6, ZoneBattles.OnPvPKill)
Add Comment
Please, Sign In to add comment