Advertisement
Guest User

Laurea

a guest
Oct 13th, 2010
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.16 KB | None | 0 0
  1. --Made by Laurea
  2.  
  3. local MaxScore = 1000 --The score you need to win
  4. local PerUpdate = 1 --How many points each team gets per flag and score update
  5. local UpdateTimer = 5 --How often the score is updated in seconds (1-3600)
  6. local Flag = 99000 --Entry id of the flag (if it doesnt exist the script automaticly creates it)
  7. local WorldDB = "world" --Name of your world database
  8. local StartMsg = "start bg" --Chat message you start the event with
  9.  
  10. --Do not edit anything beyond this point.
  11.  
  12. local Flags = {}
  13. local AllianceScore = 0
  14. local HordeScore = 0
  15. local Started = false
  16.  
  17. function ScoreCounter_FlagTaken(go, event, player)
  18.     if Started == true then
  19.         if player:IsInCombat() then
  20.             player:SendBroadcastMessage("You cannot take a flag while in combat!")
  21.         else
  22.             if Flags[go:GetSpawnId()] == nil then
  23.                 Flags[go:GetSpawnId()] = 2
  24.             end
  25.             local team = player:GetTeam()
  26.             local owner = Flags[go:GetSpawnId()]
  27.             if team ~= owner then
  28.                 local tmp
  29.                 if team == 0 then
  30.                     tmp = "Alliance"
  31.                 else
  32.                     tmp = "Horde"
  33.                 end
  34.                 SendWorldMessage(player:GetName().." has captured a flag for the "..tmp.."!", 1)
  35.                 Flags[go:GetSpawnId()] = team
  36.             else
  37.                 player:SendBroadcastMessage("Your team already owns this flag.")
  38.             end
  39.         end
  40.     end
  41. end
  42.  
  43. function ScoreCounter_Create()
  44.     if Started == true then
  45.         ScoreCounter_Destroy()
  46.     end
  47.     local p = LuaPacket:CreatePacket(706, 18)
  48.     p:WriteULong(1)
  49.     p:WriteULong(1377)
  50.     p:WriteULong(0)
  51.     p:WriteUShort(1)
  52.     p:WriteULong(0)
  53.     p:WriteULong(1)
  54.     SendPacketToWorld(p)
  55.     p = LuaPacket:CreatePacket(707, 8)
  56.     p:WriteULong(2317)
  57.     p:WriteULong(MaxScore)
  58.     SendPacketToWorld(p)
  59.     p = LuaPacket:CreatePacket(707, 8)
  60.     p:WriteULong(2313)
  61.     p:WriteULong(AllianceScore)
  62.     SendPacketToWorld(p)
  63.     p = LuaPacket:CreatePacket(707, 8)
  64.     p:WriteULong(2314)
  65.     p:WriteULong(HordeScore)
  66.     SendPacketToWorld(p)
  67.     Started = true
  68.     SendWorldMessage("World BG event has started.", 1)
  69. end
  70. function ScoreCounter_OnLogin(event, player)
  71.     if Started == true then
  72.         RegisterTimedEvent("ScoreCounter_CreateForPlayer", 100, 1, player)
  73.     end
  74. end
  75. function ScoreCounter_CreateForPlayer(player)
  76.     local p = LuaPacket:CreatePacket(706, 18)
  77.     p:WriteULong(1)
  78.     p:WriteULong(1377)
  79.     p:WriteULong(0)
  80.     p:WriteUShort(1)
  81.     p:WriteULong(0)
  82.     p:WriteULong(1)
  83.     player:SendPacketToPlayer(p)
  84.     p = LuaPacket:CreatePacket(707, 8)
  85.     p:WriteULong(2317)
  86.     p:WriteULong(MaxScore)
  87.     player:SendPacketToPlayer(p)
  88.     p = LuaPacket:CreatePacket(707, 8)
  89.     p:WriteULong(2313)
  90.     p:WriteULong(AllianceScore)
  91.     player:SendPacketToPlayer(p)
  92.     p = LuaPacket:CreatePacket(707, 8)
  93.     p:WriteULong(2314)
  94.     p:WriteULong(HordeScore)
  95.     player:SendPacketToPlayer(p)
  96. end
  97.  
  98. function ScoreCounter_Update()
  99.     if Started == true then
  100.         local Alliance = AllianceScore
  101.         local Horde = HordeScore
  102.         for k, v in pairs (Flags) do
  103.             if v == 0 then
  104.                 Alliance = Alliance + PerUpdate
  105.             elseif v == 1 then
  106.                 Horde = Horde + PerUpdate
  107.             end
  108.         end
  109.         if Alliance == AllianceScore and Horde == HordeScore then
  110.             return
  111.         else
  112.             if Alliance >= MaxScore and Horde >= MaxScore then
  113.                 ScoreCounter_Destroy()
  114.                 SendWorldMessage("No side won the world BG event.", 1)
  115.                 Started = false
  116.             elseif Alliance >= MaxScore then
  117.                 ScoreCounter_Destroy()
  118.                 SendWorldMessage("The Alliance has won the world BG event.", 1)
  119.                 Started = false
  120.             elseif Horde >= MaxScore then
  121.                 ScoreCounter_Destroy()
  122.                 SendWorldMessage("The Horde has won the world BG event.", 1)
  123.                 Started = false
  124.             else
  125.                 AllianceScore = Alliance
  126.                 HordeScore = Horde
  127.                 local p = LuaPacket:CreatePacket(707, 8)
  128.                 p:WriteULong(2313)
  129.                 p:WriteULong(Alliance)
  130.                 SendPacketToWorld(p)
  131.                 p = LuaPacket:CreatePacket(707, 8)
  132.                 p:WriteULong(2314)
  133.                 p:WriteULong(Horde)
  134.                 SendPacketToWorld(p)
  135.             end
  136.         end
  137.     end
  138. end
  139.  
  140. function ScoreCounter_Destroy()
  141.     AllianceScore = 0
  142.     HordeScore = 0
  143.     for k, v in pairs (Flags) do
  144.         Flags[k] = 2
  145.     end
  146.     local p = LuaPacket:CreatePacket(707, 8)
  147.     p:WriteULong(2317)
  148.     p:WriteULong(0)
  149.     SendPacketToWorld(p)
  150.     p = LuaPacket:CreatePacket(707, 8)
  151.     p:WriteULong(2313)
  152.     p:WriteULong(0)
  153.     SendPacketToWorld(p)
  154.     p = LuaPacket:CreatePacket(707, 8)
  155.     p:WriteULong(2314)
  156.     p:WriteULong(0)
  157.     SendPacketToWorld(p)
  158.     p = LuaPacket:CreatePacket(706, 18)
  159.     p:WriteULong(0)
  160.     p:WriteULong(0)
  161.     SendPacketToWorld(p)
  162.     Started = false
  163. end
  164.  
  165. local RegisterCheck = true
  166.  
  167. assert(type(Flag) == "number", "Value of Flag is invalid. If you want the score counter to work please use a valid value next time.")
  168. if RegisterCheck == true and WorldDBQuery("SELECT `entry` FROM `"..WorldDB.."`.`gameobject_names` WHERE `entry`="..Flag) == nil then
  169.     WorldDBQuery("INSERT INTO `gameobject_names` (`entry`, `Type`, `DisplayID`, `Name`, `Category`, `CastBarText`, `UnkStr`, `spellfocus`, `sound1`, `sound2`, `sound3`, `sound4`, `sound5`, `sound6`, `sound7`, `sound8`, `sound9`, `unknown1`, `unknown2`, `unknown3`, `unknown4`, `unknown5`, `unknown6`, `unknown7`, `unknown8`, `unknown9`, `unknown10`, `unknown11`, `unknown12`, `unknown13`, `unknown14`, `Size`, `QuestItem1`, `QuestItem2`, `QuestItem3`, `QuestItem4`, `QuestItem5`, `QuestItem6`) VALUES ("..Flag..", 10, 6663, 'Flag', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0);")
  170.     print ("A gameobject with entry "..Flag.." does not exist. Creating one now.")
  171.     RegisterCheck = false
  172. elseif RegisterCheck == true and WorldDBQuery("SELECT `Name` FROM `"..WorldDB.."`.`gameobject_names` WHERE `entry`="..Flag):GetColumn(0):GetString() ~= "Flag" then
  173.     print ("Gameobject with entry "..Flag.." does not meet the requirements of the score counter. If you want the score counter to work please change the value of Flag or delete the go from your database.")
  174.     RegisterCheck = false
  175. end
  176. if WorldDB == nil then
  177.     WorldDB = "world"
  178.     print ("WorldDB was nil. Setting it back to \"world\", but its not sure its correct.")
  179. end
  180. if type(MaxScore) ~= "number" then
  181.     MaxScore = 1000
  182.     print ("MaxScore was not a number and got set back to 1000.")
  183. end
  184. if type(PerUpdate) ~= "number" then
  185.     PerUpdate = 1
  186.     print ("PerUpdate was not a number and got set back to 1.")
  187. end
  188. if type(UpdateTimer) ~= "number" then
  189.     UpdateTimer = 5
  190.     print ("UpdateTimer was not a number and got set back to 5.")
  191. elseif UpdateTimer < 1 then
  192.     UpdateTimer = 1
  193.     print ("UpdateTimer was less than 1 and got set to 1.")
  194. elseif UpdateTimer > 3600 then
  195.     UpdateTimer = 3600
  196.     print ("UpdateTimer was more than 3600 and got set back to 3600.")
  197. end
  198. if Flags == nil or AllianceScore ~= 0 or HordeScore ~= 0 or Started ~= false then
  199.     RegisterCheck = false
  200.     print ("Didnt I tell you not to touch anything beyond that point? Now reset anything you did or the script wont run.")
  201. end
  202.  
  203. function ScoreCounter_Start(event, player, message)
  204.     if message == StartMsg and player:IsGm() then
  205.         if Started == false then
  206.             ScoreCounter_Create()
  207.         else
  208.             player:SendAreaTriggerMessage("World BG event is already on.")
  209.         end
  210.         return 0
  211.     end
  212. end
  213.  
  214. if RegisterCheck == true then
  215.     RegisterGameObjectEvent(Flag, 4, "ScoreCounter_FlagTaken")
  216.     RegisterServerHook(19, "ScoreCounter_OnLogin")
  217.     RegisterTimedEvent("ScoreCounter_Update", UpdateTimer*1000, 0)
  218.     RegisterServerHook(16, "ScoreCounter_Start")
  219. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement